Compare commits

...

13 commits
v1.1.0 ... main

4 changed files with 59 additions and 25 deletions

View file

@ -22,7 +22,7 @@ My goal with this script is to keep it simple, just a single line that gives use
<hr>
### Installing:
#### Via Curl
#### Automatic Installation via Curl
<sub>Bash:</sub>
```
bash -c "$(curl -s https://raw.githubusercontent.com/G2-Games/welcome.sh/main/install.sh)"
@ -35,7 +35,7 @@ zsh -c "$(curl -s https://raw.githubusercontent.com/G2-Games/welcome.sh/main/ins
It installs to `~/.welcome/welcome.sh`, and adds a line to the bottom of `~/.bashrc` or `~/.zshrc`
#### Manual Installation
To use it, download the latest `welcome.sh` from <a href="https://github.com/G2-Games/welcome.sh/releases/latest">releases</a> and place it in your home directory. Then add `bash ~/welcome.sh` to your `.bashrc`. It works without the config file, but you can also add that to your home directory for easier manual updates.
To install it manually, download the latest `welcome.sh` from <a href="https://github.com/G2-Games/welcome.sh/releases/latest">releases</a> and place it in your home directory. Then add `bash ~/welcome.sh` to your `.bashrc`. It works without the config file, but you can also add that to your home directory for easier manual updates.
### Updating:
Run the script again to check for an update. If you have an older version it will prompt you. You can update **from** any version **to** any newer version. The proper files will be downloaded as necessary.

25
cleanup.sh Normal file
View file

@ -0,0 +1,25 @@
#!/bin/bash
version=1
echo "Ensuring welcome.sh is installed in the new location..."
# Check if welcome.sh is installed in the old location
if [[ -f ~/.welcome ]]\
|| [[ -f ~/.welcome/welcome.sh ]]\
|| [[ -f ~/.welcome/config.cfg ]];
then
# Modify the files with proper paths
sed "${i}d" "$zshrc" > file.tmp && mv file.tmp "$zshrc"
# Create the directories in the proper spots
mkdir -p ~/.config/welcome.sh/
mkdir -p ~/.local/bin/
# Move the welcome files to the proper folders
mv ~/.welcome/config.cfg ~/.config/welcome.sh/config.cfg
mv ~/.welcome/welcome.sh ~/.local/bin/welcome.sh
echo "welcome.sh is now installed in the new location!"
else
echo "welcome.sh is already installed properly!"
fi

View file

@ -35,6 +35,7 @@ uninstall () {
echo "Goodbye. Uninstalling..."
tput sc
rm ~/.welcome/welcome.sh 2> /dev/null
rm ~/.welcome/install.sh 2> /dev/null
rm ~/.welcome/config.cfg 2> /dev/null
rm ~/.welcome/config_old.cfg 2> /dev/null
rm -r ~/.welcome
@ -61,9 +62,11 @@ update () {
echo "Updating..."
tput sc
mkdir -p ~/.welcome
rm ~/.welcome/welcome.sh
rm ~/.welcome/welcome.sh 2> /dev/null
rm ~/.welcome/install.sh 2> /dev/null
curl -SL https://github.com/G2-Games/welcome.sh/releases/download/v"${version}"/welcome.sh --output ~/.welcome/welcome.sh
curl -SL https://raw.githubusercontent.com/G2-Games/welcome.sh/main/install.sh --output ~/.welcome/install.sh
if [[ $vernum -ge 100 ]] && [[ $overcfg -gt 0 ]]; then
echo "Backing up: config.cfg >> config_old.cfg"
mv ~/.welcome/config.cfg ~/.welcome/config_old.cfg
@ -71,19 +74,19 @@ update () {
fi
# Check for older versions and replace bashrc lines
lines=$(grep -sn 'bash ~/.welcome/welcome.sh' $bashrc | sed -e 's/:.*//g' && grep -sn 'bash /home/$USER/.welcome/welcome.sh' $bashrc | sed -e 's/:.*//g')
lines=$(printf '%s\n' "$lines" | sed '1!G;h;$!d' | sed ':a;N;$!ba;s/\n/ /g')
lines=$(grep -sn 'bash ~/.welcome/welcome.sh' "$bashrc" | sed -e 's/:.*//g' && grep -sn 'bash /home/$USER/.welcome/welcome.sh' "$bashrc" | sed -e 's/:.*//g') # Find target line number
lines=$(printf '%s\n' "$lines" | sed '1!G;h;$!d' | sed ':a;N;$!ba;s/\n/ /g') # Format the line number properly (macos doesn't have Cut)
for i in $lines; do
sed "${i}d" $bashrc > file.tmp && mv file.tmp $bashrc
sed "${i}d" "$bashrc" > file.tmp && mv file.tmp "$bashrc"
done
echo 'bash ~/.welcome/welcome.sh' >> $bashrc
echo 'bash ~/.welcome/welcome.sh' >> "$bashrc"
lines=$(grep -sn 'zsh ~/.welcome/welcome.sh' $zshrc | sed -e 's/:.*//g' && grep -sn 'zsh /home/$USER/.welcome/welcome.sh' $zshrc | sed -e 's/:.*//g')
lines=$(grep -sn 'zsh ~/.welcome/welcome.sh' "$zshrc" | sed -e 's/:.*//g' && grep -sn 'zsh /home/$USER/.welcome/welcome.sh' "$zshrc" | sed -e 's/:.*//g')
lines=$(printf '%s\n' "$lines" | sed '1!G;h;$!d' | sed ':a;N;$!ba;s/\n/ /g')
for i in $lines; do
sed "${i}d" $zshrc > file.tmp && mv file.tmp $zshrc
sed "${i}d" "$zshrc" > file.tmp && mv file.tmp "$zshrc"
done
echo 'zsh ~/.welcome/welcome.sh' >> $zshrc
echo 'zsh ~/.welcome/welcome.sh' >> "$zshrc"
tput rc el ed
echo -e "\e[32mUpdated to v$version! \e[0m"
@ -125,9 +128,12 @@ this script!\e[0m Please use \e[3mBash \e[0mor \e[3mZsh.\e[0m\n" "${environment}
fi
# Check if already installed
if ! grep -qs 'bash ~/.welcome/welcome.sh' $bashrc && ! grep -qs 'zsh ~/.welcome/welcome.sh' $zshrc && ! grep -qs 'bash /home/$USER/.welcome/welcome.sh' $bashrc && ! grep -qs 'zsh /home/$USER/.welcome/welcome.sh' $zshrc; then
if ! grep -qs 'bash ~/.welcome/welcome.sh' $bashrc &&
! grep -qs 'zsh ~/.welcome/welcome.sh' $zshrc &&
! grep -qs 'bash /home/$USER/.welcome/welcome.sh' $bashrc &&
! grep -qs 'zsh /home/$USER/.welcome/welcome.sh' $zshrc;
then
#==== Execute if first time installing...====#
tput rc
echo "Welcome! Installing v$version in $environment..."
tput sc
@ -135,6 +141,8 @@ if ! grep -qs 'bash ~/.welcome/welcome.sh' $bashrc && ! grep -qs 'zsh ~/.welcome
cd ~/ || exit 1
mkdir -p ~/.welcome
curl -SL https://github.com/G2-Games/welcome.sh/releases/download/v"${version}"/welcome.sh --output ~/.welcome/welcome.sh
curl -SL https://raw.githubusercontent.com/G2-Games/welcome.sh/main/install.sh --output ~/.welcome/install.sh
if [[ $vernum -ge 100 ]]; then
curl -SL https://github.com/G2-Games/welcome.sh/releases/download/v"${version}"/config.cfg --output ~/.welcome/config.cfg
fi

View file

@ -1,13 +1,8 @@
# shellcheck source=/home/g2/Documents/projects/code/misc/welcome.sh/welcome.sh
# Bash "strict mode" => http://redsymbol.net/articles/unofficial-bash-strict-mode/
set -euo pipefail
IFS=$'\n\t'
export LC_NUMERIC="en_US.UTF-8" &> /dev/null #Fix for locales that use , instead of . as a decimal delimiter
# Define "global" variables
environment=$(ps -o args= -p $$ | grep -Em 1 -o '\w{0,5}sh' | head -1)
version=1.0.5
version=1.1.2
#========Welcome=======#
welcome () {
@ -24,7 +19,7 @@ welcome () {
fi
if [ "$randgreeting" = "on" ]; then
msg=${greetings[$greetingsNumber]}
msg=${greetings[@]:$greetingsNumber:1}
fi
# Print the welcome message
@ -124,12 +119,12 @@ updates () {
# Check for updates from different places... wonder if there's a better way
updchk () {
# Check for APT
# Check for APT (Debian based)
if command -v apt-get &> /dev/null; then
debian=$(apt-get -s dist-upgrade -V | grep -c '=>')
fi
# Check for different Arch things
# Check for Arch things
if command -v checkupdates &> /dev/null; then
arch=$(checkupdates 2> /dev/null | wc -l)
elif command -v yay &> /dev/null; then
@ -149,6 +144,12 @@ updates () {
fedora=$((fedora-1))
fi
# Check for OpenSUSE things
if command -v zypper &> /dev/null; then
suse=$(zypper list-updates 2> /dev/null | wc -l)
suse=$((suse-4))
fi
# Check for Brew updates
if command -v brew &> /dev/null; then
brew=$(brew outdated 2> /dev/null | wc -l)
@ -160,7 +161,7 @@ updates () {
fi
# Add all update counts together
updates=$((debian + arch + fedora + flatpak + brew))
updates=$((debian + arch + fedora + suse + flatpak + brew))
echo $updates >| ~/.welcome/updates
pkill -P "${pid}" sleep # When update checking is finished, kill the sleep function running under this bash process
sleep 5
@ -169,7 +170,7 @@ updates () {
fi
}
pid=$$ # Grab the PID of the process
pid=$$ # Grab the PID of the process
updchk & # Check for updates Asynchronously
set +e # Allow nonzero exit status for killing sleep
@ -271,9 +272,9 @@ lastdate=$(cat ~/.welcome/udm 2>/dev/null)
if [[ $((date - lastdate)) -ge 86400 ]]; then
if [[ "$environment" = "bash" ]]; then
bash install.sh auto
bash ~/.welcome/install.sh auto
elif [[ "$environment" = "zsh" ]]; then
zsh install.sh auto
zsh ~/.welcome/install.sh auto
fi
date +%s >| ~/.welcome/udm 2>/dev/null
elif ! [[ -f ~/.welcome/udm ]]; then