Compare commits

...

27 commits
v1.0.5 ... main

Author SHA1 Message Date
4912cfa2c8 Added preliminary work on a cleanup script to move files around 2023-08-21 00:41:30 -05:00
9cee7f2904 Cleaned up more, removed analytics 2023-08-20 18:22:29 -05:00
b958afb09b Merge branch 'main' of https://github.com/G2-Games/welcome.sh 2023-08-20 18:19:51 -05:00
965477d62b Updated installer script, made a bit more streamlined and fixed errors 2023-08-20 18:19:02 -05:00
e82a0cf000 Added support for OpenSUSE update checks with Zypper 2023-05-07 17:44:44 -05:00
G2
f78aed8316
Update README.md 2023-03-08 19:35:49 -06:00
G2
979978a7f8 Added update tracking to installer 2023-03-07 14:00:44 -06:00
G2
54f3619274 Bumped version, v1.1.2 2023-03-07 10:32:06 -06:00
G2
bd27870290 Fixed #6, used proper array indexing technique 2023-03-07 10:29:30 -06:00
G2
741fe542f1 Bumped version, v1.1.1 2023-03-07 09:53:34 -06:00
G2
b905684b63 Fixed issues with strict mode by removing it for now. Fixes #5 2023-03-07 09:41:36 -06:00
G2
68ab6a6310 Updated installer to download itself properly 2023-03-07 09:41:11 -06:00
4e5b2a848e Bumped version, 1.1.0 2023-03-07 00:20:30 -06:00
61ddc11af7 Fixed automatic update check in both welcome.sh and installer 2023-03-06 23:52:55 -06:00
44c14ad494 Cleaned up install.sh even more, conformed to all shellcheck rules 2023-03-06 23:49:23 -06:00
a863f8ddc6 Significantly cleaned up install script, dropped support for wget 2023-03-06 19:00:50 -06:00
49563932e0 Removed wget support, too hard to maintain 2023-03-06 18:32:01 -06:00
e072e7c7fc Fixed a bunch of small possible issues with the script 2023-03-06 18:06:57 -06:00
b7608a59d0 Fixed major issue with apt update checking on debian systems 2023-03-06 16:58:39 -06:00
bd0f3f2cc0 Added automatic update checking functionality 2022-11-29 22:45:46 -06:00
c58f9f5224 Added more comments, changed to strict mode (might cause issues) 2022-11-26 14:42:16 -06:00
84874298c4 Merge branch 'main' of https://github.com/G2-Games/welcome.sh 2022-11-26 14:40:50 -06:00
56883965c5 Streamlined install script, added support for checking latest release automatically 2022-11-26 14:40:23 -06:00
G2
24a1dd5319
Update README.md 2022-11-25 04:11:39 -06:00
cc7ec85760 Added a possibly better way to check for updates on Arch 2022-11-25 01:59:07 -06:00
74a570a107 Used bash strict mode to clean up the code a bit, couldn't get everything 2022-11-25 01:37:56 -06:00
decec76c61 Version bump, v1.0.5 2022-11-25 00:52:05 -06:00
4 changed files with 295 additions and 189 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> <hr>
### Installing: ### Installing:
#### Via Curl #### Automatic Installation via Curl
<sub>Bash:</sub> <sub>Bash:</sub>
``` ```
bash -c "$(curl -s https://raw.githubusercontent.com/G2-Games/welcome.sh/main/install.sh)" bash -c "$(curl -s https://raw.githubusercontent.com/G2-Games/welcome.sh/main/install.sh)"
@ -31,20 +31,11 @@ bash -c "$(curl -s https://raw.githubusercontent.com/G2-Games/welcome.sh/main/in
``` ```
zsh -c "$(curl -s https://raw.githubusercontent.com/G2-Games/welcome.sh/main/install.sh)" zsh -c "$(curl -s https://raw.githubusercontent.com/G2-Games/welcome.sh/main/install.sh)"
``` ```
#### Or wget
<sub>Bash:</sub>
```
bash -c "$(wget -q https://raw.githubusercontent.com/G2-Games/welcome.sh/main/install.sh -O -)"
```
<sub>Zsh:</sub>
```
zsh -c "$(wget -q https://raw.githubusercontent.com/G2-Games/welcome.sh/main/install.sh -O -)"
```
It installs to `~/.welcome/welcome.sh`, and adds a line to the bottom of `~/.bashrc` or `~/.zshrc` It installs to `~/.welcome/welcome.sh`, and adds a line to the bottom of `~/.bashrc` or `~/.zshrc`
#### Manual Installation #### Manual Installation
To use it, download the latest `welcome.sh` from <a href="https://github.com/G2-Games/welcome.sh/releases">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: ### 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. 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

@ -1,155 +1,207 @@
version="${1:-1.0.4}" getVersion () {
vernum=$(echo $version | sed 's/[.][.]*//g' ) local ver
ver=$(grep version ~/.welcome/welcome.sh 2> /dev/null | sed 's/.*=//')
if [ -z "$ver" ]; then
echo -e "\bUnknown"
return
fi
echo "$ver"
}
# Universal read command for bash and zsh
univRead () {
echo -en "$1"
echo -en "\n[\e[36mY/n\e[0m]"
if [[ "$environment" = "bash" ]]; then
read -p " " -r
elif [[ "$environment" = "zsh" ]]; then
read -q "REPLY? " -r
fi
echo
}
uninstall () {
# Check if the user actually wishes to uninstall the script
univRead "Do you want to \e[31muninstall \e[35mwelcome.sh\e[0m?"
if ! [[ $REPLY =~ ^[Yy]$ ]]; then
tput rc el ed
echo -e "\e[31mUninstall cancelled.\e[0m"
exit 0
fi
tput rc el ed
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
#remove all lines that match the string
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')
for i in $lines; do
sed "${i}d" "$bashrc" > file.tmp && mv file.tmp "$bashrc"
done
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"
done
tput rc && tput el && tput ed
echo -e "\e[36mUninstalled! \e[0m"
}
update () {
tput rc el ed
echo "Updating..."
tput sc
mkdir -p ~/.welcome
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
curl -SL https://github.com/G2-Games/welcome.sh/releases/download/v"${version}"/config.cfg --output ~/.welcome/config.cfg
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') # 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"
done
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=$(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"
done
echo 'zsh ~/.welcome/welcome.sh' >> "$zshrc"
tput rc el ed
echo -e "\e[32mUpdated to v$version! \e[0m"
}
tput sc
if [[ -z "$1" ]] && [[ $1 != "auto" ]]; then
echo "Checking for latest release..."
fi
if ! [[ $(command -v curl) ]]; then
exit 1
fi
latestver=$(curl -Ls https://github.com/G2-Games/welcome.sh/releases/latest/download/welcome.sh | grep version | cut -d= -f2)
oldver=$(grep version ~/.welcome/welcome.sh 2> /dev/null | cut -d= -f2 | sed 's/[.][.]*//g') && if [[ -z "$oldver" ]]; then oldver=0; fi
version="${1:-$latestver}"
if [[ $1 == "auto" ]] && [[ ${latestver//./} -le $oldver ]]; then
exit 0
elif [[ $1 == "auto" ]]; then
version=$latestver
fi
vernum=${version//./}
bashrc=~/.bashrc bashrc=~/.bashrc
zshrc=~/.zshrc zshrc=~/.zshrc
originaldir=$PWD originaldir=$PWD
environment=$(ps -o args= -p $$ | grep -Em 1 -o '\w{0,5}sh' | head -1) environment=$(ps -o args= -p $$ | grep -Em 1 -o '\w{0,5}sh' | head -1)
if [ "$environment" = "bash" ] || [ "$environment" = "zsh" ];
# Check if the environment is bash or zsh
if [[ "$environment" != "bash" ]] && [[ "$environment" != "zsh" ]]; then
tput rc
printf "\e[31;5mERROR:\e[0m \e[31;3mThis script can only be installed in Bash or Zsh.\e[0m\n"
printf "\e[32mYou appear to be using %s, which is not a valid shell for\n\
this script!\e[0m Please use \e[3mBash \e[0mor \e[3mZsh.\e[0m\n" "${environment}"
exit 1
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 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 || [ -z ~/.welcome/welcome.sh ]; #==== Execute if first time installing...====#
then tput rc
echo "Welcome! Installing v$version in $environment..." echo "Welcome! Installing v$version in $environment..."
tput sc tput sc
cd ~/
mkdir -p ~/.welcome cd ~/ || exit 1
if which curl >/dev/null ; mkdir -p ~/.welcome
then curl -SL https://github.com/G2-Games/welcome.sh/releases/download/v"${version}"/welcome.sh --output ~/.welcome/welcome.sh
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 if [[ $vernum -ge 100 ]]; then
fi curl -SL https://github.com/G2-Games/welcome.sh/releases/download/v"${version}"/config.cfg --output ~/.welcome/config.cfg
elif which wget >/dev/null ; fi
then chmod +x ~/.welcome/welcome.sh
wget https://github.com/G2-Games/welcome.sh/releases/download/v${version}/welcome.sh --P ~/.welcome/
if [[ $vernum -ge 100 ]]; then if [[ "$environment" = "bash" ]]; then
wget https://github.com/G2-Games/welcome.sh/releases/download/v${version}/config.cfg --P ~/.welcome/ echo "Installing to bashrc"
fi echo 'bash ~/.welcome/welcome.sh' >> $bashrc
else elif [[ "$environment" = "zsh" ]]; then
echo -e "\e[31mCannot download, neither Wget nor cURL is available!\e[0m" echo "Installing to zshrc"
exit 1 echo 'zsh ~/.welcome/welcome.sh' >> $zshrc
fi fi
chmod +x ~/.welcome/welcome.sh
if [[ "$environment" = "bash" ]]; cd "$originaldir" || exit 1
then tput rc el ed
echo "Installing to bashrc" echo -e "\e[36mInstalled! \e[0m"
echo 'bash ~/.welcome/welcome.sh' >> $bashrc else
elif [[ "$environment" = "zsh" ]]; #==== Execute if already installed...====#
then
echo "Installing to zshrc" tput rc sc el ed
echo 'zsh ~/.welcome/welcome.sh' >> $zshrc mkdir -p ~/.welcome
fi if ! [[ $1 == "auto" ]]; then
cd "$originaldir"
tput rc && tput el && tput ed
echo -e "\e[36mInstalled! \e[0m"
else
tput sc
mkdir -p ~/.welcome
echo -e "\e[35mwelcome.sh\e[0m already installed!" echo -e "\e[35mwelcome.sh\e[0m already installed!"
oldver=$(grep version ~/.welcome/welcome.sh 2> /dev/null | sed 's/.*=//' | sed 's/[.][.]*//g') && if ! [ -n "$oldver" ]; then oldver=0; fi else
if [[ $vernum -gt $oldver ]]; then echo -e "\e[32mUpdate available for \e[35mwelcome.sh!\e[0m"
if which curl >/dev/null ; then cfgver=$(echo $(curl -Ls https://github.com/G2-Games/welcome.sh/releases/download/v$version/config.cfg) | grep version | sed 's/.*=//' | sed 's/[.][.]*//g'); fi
elif which wget >/dev/null ; then cfgver=$(echo $(wget -q https://github.com/G2-Games/welcome.sh/releases/download/v1.0.2/config.cfg -O -) | grep version | sed 's/.*=//' | sed 's/[.][.]*//g'); fi
echo -en "Do you want to \e[36mupdate \e[35mwelcome.sh\e[0m? (\e[36mv$(ver=$(grep version ~/.welcome/welcome.sh 2> /dev/null | sed 's/.*=//') && if ! [ -n "$ver" ]; then echo -e "\bUnknown"; else echo "$ver"; fi)\e[0m => \e[32mv$version\e[0m) \n\e[36mY/n\e[0m"
if [[ "$environment" = "bash" ]]; then read -p " " -n 1 -r;
elif [[ "$environment" = "zsh" ]]; then read -q "REPLY? " -n 1 -r; fi
echo
if [[ $REPLY =~ ^[Yy]$ ]]; then
if [[ $cfgver -gt $(grep version ~/.welcome/config.cfg 2> /dev/null | sed 's/.*=//' | sed 's/[.][.]*//g') ]] && ! [ -z ~/.welcome/config.cfg ]; then
echo -en "Newer config version available. Do you want to \e[31moverwrite\e[0m your config? \nA backup will be created in the \e[36m.welcome\e[0m folder.\n\e[36mY/n\e[0m"
if [[ "$environment" = "bash" ]]; then read -p " " -n 1 -r;
elif [[ "$environment" = "zsh" ]]; then read -q "REPLY? " -n 1 -r; fi
echo
if [[ $REPLY =~ ^[Yy]$ ]]; then
overcfg=1
fi
elif [ $oldver -lt 100 ]; then
overcfg=1
else
overcfg=0
fi
tput rc && tput el && tput ed
echo "Updating..."
tput sc
mkdir -p ~/.welcome
rm ~/.welcome/welcome.sh
if which curl >/dev/null ;
then
curl -SL https://github.com/G2-Games/welcome.sh/releases/download/v${version}/welcome.sh --output ~/.welcome/welcome.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
curl -SL https://github.com/G2-Games/welcome.sh/releases/download/v${version}/config.cfg --output ~/.welcome/config.cfg
fi
elif which wget >/dev/null ;
then
wget https://github.com/G2-Games/welcome.sh/releases/download/v${version}/welcome.sh --P ~/.welcome/
if [[ $vernum -ge 100 ]] && [[ $overcfg -gt 0 ]]; then
echo "Backing up: config.cfg >> config_old.cfg"
mv ~/.welcome/config.cfg ~/.welcome/config_old.cfg
wget https://github.com/G2-Games/welcome.sh/releases/download/v${version}/config.cfg --P ~/.welcome/
fi
else
echo -e "\e[31mCannot update, neither Wget nor cURL is available!\e[0m"
exit 1
fi
# Check for older versions and replace bashrc lines if [[ $vernum -gt $oldver ]]; then
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') # Pull the new configuration version from github
lines=$(printf '%s\n' $lines | sed '1!G;h;$!d' | sed ':a;N;$!ba;s/\n/ /g') newCfgVer=$(curl -Ls https://github.com/G2-Games/welcome.sh/releases/download/v"${version}"/config.cfg | grep version | cut -d= -f2)
for i in $( echo "$lines" ); do
sed "${i}d" $bashrc > file.tmp && mv file.tmp $bashrc
done
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') univRead "Do you want to \e[36mupdate \e[35mwelcome.sh\e[0m? (\e[36mv$(getVersion)\e[0m => \e[32mv$version\e[0m)"
lines=$(printf '%s\n' $lines | sed '1!G;h;$!d' | sed ':a;N;$!ba;s/\n/ /g') if ! [[ $REPLY =~ ^[Yy]$ ]]; then
for i in $( echo "$lines" ); do tput rc sc el ed
sed "${i}d" $zshrc > file.tmp && mv file.tmp $zshrc echo -e "\e[31mUpdate cancelled.\e[0m"
done update=0
echo 'zsh ~/.welcome/welcome.sh' >> $zshrc
tput rc && tput el && tput ed
echo -e "\e[32mUpdated to v$version! \e[0m"
exit 0
else
tput rc && tput el && tput ed
echo -e "\e[35mwelcome.sh\e[0m already installed!"
fi
fi
echo -en "Do you want to \e[31muninstall \e[35mwelcome.sh\e[0m?\n\e[36mY/n\e[0m"
if [[ "$environment" = "bash" ]]; then read -p " " -n 1 -r;
elif [[ "$environment" = "zsh" ]]; then read -q "REPLY? " -n 1 -r; fi
echo
if [[ $REPLY =~ ^[Yy]$ ]]; then
tput rc && tput el && tput ed
echo "Goodbye. Uninstalling..."
tput sc
rm ~/.welcome/welcome.sh 2> /dev/null
rm ~/.welcome/config.cfg 2> /dev/null
rm ~/.welcome/config_old.cfg 2> /dev/null
rm -r ~/.welcome
#remove all lines that match the string
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')
for i in $( echo "$lines" ); do
sed "${i}d" $bashrc > file.tmp && mv file.tmp $bashrc
done
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 $( echo "$lines" ); do
sed "${i}d" $zshrc > file.tmp && mv file.tmp $zshrc
done
tput rc && tput el && tput ed
echo -e "\e[36mUninstalled! \e[0m"
else else
tput rc && tput el && tput ed update=1
echo -e "\e[31mCancelled. \e[0m" fi
exit 0
if [[ $newCfgVer -gt $(grep version ~/.welcome/config.cfg 2> /dev/null | cut -d= -f2) ]]; then
univRead "Newer \e[36mconfig\e[0m version available. Do you want to \e[31moverwrite\e[0m your \e[36mconfig\e[0m? \nA backup will be created in the \e[36m.welcome\e[0m folder."
if [[ $REPLY =~ ^[Yy]$ ]]; then
overcfg=1
fi
elif [[ $oldver -lt 100 ]]; then
overcfg=1
else
overcfg=0
fi fi
fi fi
else
printf "\e[31;5mERROR:\e[0m \e[31;3mThis script can only be installed in Bash or Zsh.\e[0m\n" if [[ update -gt 0 ]]; then
update
exit 0
fi
if ! [[ $1 == "auto" ]]; then
uninstall
exit 0
fi
fi fi

View file

@ -1,8 +1,14 @@
version=1.0.5
export LC_NUMERIC="en_US.UTF-8" &> /dev/null #Fix for locales that use , instead of . as a decimal delimiter 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.1.2
#========Welcome=======# #========Welcome=======#
welcome () { welcome () {
msg="Welcome" # Default msg="Welcome" # Default
greetingsLength=${#greetings[@]}
greetingsNumber=$((RANDOM % greetingsLength))
if command -v whoami &>/dev/null ; then if command -v whoami &>/dev/null ; then
usr=$(whoami) usr=$(whoami)
@ -13,7 +19,7 @@ welcome () {
fi fi
if [ "$randgreeting" = "on" ]; then if [ "$randgreeting" = "on" ]; then
msg=${greetings[$(($RANDOM % $(echo ${#greetings[@]})))]} msg=${greetings[@]:$greetingsNumber:1}
fi fi
# Print the welcome message # Print the welcome message
@ -22,9 +28,10 @@ welcome () {
#=========Time=========# #=========Time=========#
clock () { clock () {
bksp=""
# Set the current hour and minute # Set the current hour and minute
if [ "$twelvehour" = "on" ]; then if [ "$twelvehour" = "on" ]; then
if [ $(date +%_I) -lt 10 ]; then if [[ "$(date +%_I)" -lt 10 ]]; then
hour="\b$(date +%_I)" hour="\b$(date +%_I)"
else else
hour="$(date +%_I)" hour="$(date +%_I)"
@ -32,7 +39,7 @@ clock () {
ampm=$(date +%p) ampm=$(date +%p)
else else
hour=$(date +%H) hour=$(date +%H)
bksp="\b \b" bksp="\b \b" # This is a hack to fix some spacing issues with AM and PM with different lengths of time
fi fi
minute=$(date +%M) minute=$(date +%M)
@ -50,13 +57,14 @@ greeting () {
greet="Good" greet="Good"
fi fi
if [ $hour -le 11 ] && [ $hour -gt 6 ]; then # Change color and greeting depending on the segment of day
if [ "$hour" -le 11 ] && [ "$hour" -gt 6 ]; then
echo -en "$greet ${MORN}morning${NCOL}. " echo -en "$greet ${MORN}morning${NCOL}. "
elif [ $hour -eq 12 ]; then elif [ "$hour" -eq 12 ]; then
echo -en "It's ${AFTN}noon${NCOL}. " echo -en "It's ${AFTN}noon${NCOL}. "
elif [ $hour -le 17 ] && [ $hour -gt 12 ]; then elif [ "$hour" -le 17 ] && [ "$hour" -gt 12 ]; then
echo -en "$greet ${AFTN}afternoon${NCOL}. " echo -en "$greet ${AFTN}afternoon${NCOL}. "
elif [ $hour -le 19 ] && [ $hour -gt 17 ]; then elif [ "$hour" -le 19 ] && [ "$hour" -gt 17 ]; then
echo -en "$greet ${EVEN}evening${NCOL}. " echo -en "$greet ${EVEN}evening${NCOL}. "
else else
echo -en "It's ${NIGH}night${NCOL}. " echo -en "It's ${NIGH}night${NCOL}. "
@ -69,6 +77,7 @@ battery () {
# Set a default to prevent errors # Set a default to prevent errors
batlvl=0 batlvl=0
# Check the two usually used battery locations
if [[ -a "/sys/class/power_supply/BAT0/capacity" ]]; then if [[ -a "/sys/class/power_supply/BAT0/capacity" ]]; then
batlvl=$(cat /sys/class/power_supply/BAT0/capacity) batlvl=$(cat /sys/class/power_supply/BAT0/capacity)
elif [[ -a "/sys/class/power_supply/BAT1/capacity" ]]; then elif [[ -a "/sys/class/power_supply/BAT1/capacity" ]]; then
@ -80,13 +89,13 @@ battery () {
fi fi
# Change color depending on level # Change color depending on level
if [ $batlvl -ge 100 ]; then if [[ $batlvl -ge 100 ]]; then
echo -en "The battery is ${FULL}fully charged${NCOL}. " echo -en "The battery is ${FULL}fully charged${NCOL}. "
elif [ $batlvl -gt 0 ]; then elif [[ $batlvl -gt 0 ]]; then
echo -en "The battery level is " echo -en "The battery level is "
if [ $batlvl -le 15 ]; then if [[ $batlvl -le 15 ]]; then
echo -en "${CRIT}$batlvl%${NCOL}. " echo -en "${CRIT}$batlvl%${NCOL}. "
if [ "$rechargenotif" = "on" ]; then if [[ "$rechargenotif" = "on" ]]; then
echo -en "- ${NORM}You should probably recharge${NCOL}. " echo -en "- ${NORM}You should probably recharge${NCOL}. "
fi fi
elif [ $batlvl -le 30 ]; then elif [ $batlvl -le 30 ]; then
@ -109,15 +118,16 @@ updates () {
updates=0 updates=0
# Check for updates from different places... wonder if there's a better way # Check for updates from different places... wonder if there's a better way
updchk () { updchk () {
# Check for APT # Check for APT (Debian based)
if command -v apt-get &> /dev/null; then if command -v apt-get &> /dev/null; then
debian=$(apt-get -s dist-upgrade -V 2> /dev/null | grep '=>' | awk '{print$1}' | wc -l) debian=$(apt-get -s dist-upgrade -V | grep -c '=>')
fi fi
# Check for different Arch things # Check for Arch things
if command -v yay &> /dev/null; then if command -v checkupdates &> /dev/null; then
arch=$(checkupdates 2> /dev/null | wc -l)
elif command -v yay &> /dev/null; then
arch=$(yay -Qu 2> /dev/null | wc -l) arch=$(yay -Qu 2> /dev/null | wc -l)
elif command -v paru &> /dev/null; then elif command -v paru &> /dev/null; then
arch=$(paru -Quq 2> /dev/null | wc -l) arch=$(paru -Quq 2> /dev/null | wc -l)
@ -134,7 +144,13 @@ updates () {
fedora=$((fedora-1)) fedora=$((fedora-1))
fi fi
# Check for Brew updates # 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 if command -v brew &> /dev/null; then
brew=$(brew outdated 2> /dev/null | wc -l) brew=$(brew outdated 2> /dev/null | wc -l)
fi fi
@ -143,26 +159,28 @@ updates () {
if command -v flatpak &> /dev/null && [ "$flatpakupd" = "on" ]; then if command -v flatpak &> /dev/null && [ "$flatpakupd" = "on" ]; then
flatpak=$(flatpak remote-ls --updates 2> /dev/null | wc -l) flatpak=$(flatpak remote-ls --updates 2> /dev/null | wc -l)
fi fi
# Add all update counts together # Add all update counts together
updates=$(($debian + $arch + $fedora + $flatpak + $brew)) updates=$((debian + arch + fedora + suse + flatpak + brew))
echo $updates >| ~/.welcome/updates echo $updates >| ~/.welcome/updates
pkill -P $pid sleep pkill -P "${pid}" sleep # When update checking is finished, kill the sleep function running under this bash process
sleep 5 sleep 5
if [[ -a ~/.welcome/updates ]]; then if [[ -a ~/.welcome/updates ]]; then
rm ~/.welcome/updates rm ~/.welcome/updates
fi fi
return 0
} }
pid=$(echo $$) pid=$$ # Grab the PID of the process
updchk & #Check for updates Asynchronously updchk & # Check for updates Asynchronously
exec 3>&2 set +e # Allow nonzero exit status for killing sleep
exec 3>&2 # These exec commands simply supress the output of the "kill" command
exec 2> /dev/null exec 2> /dev/null
sleep 5 sleep 5
chk=$(echo $?) chk=$?
exec 2>&3 exec 2>&3 # And then re-enable it
exec 3>&- exec 3>&-
set -e # Return to disallowing nonzero exit status
if [[ -a ~/.welcome/updates ]]; then if [[ -a ~/.welcome/updates ]]; then
updates=$(cat ~/.welcome/updates) updates=$(cat ~/.welcome/updates)
@ -173,10 +191,10 @@ updates () {
if [ $chk -lt 1 ]; then if [ $chk -lt 1 ]; then
echo -en "Update check timed out. " echo -en "Update check timed out. "
else else
if [ $updates -eq 1 ]; then if [ "${updates}" -eq 0 ]; then
echo -en "You have ${NORM}1${NCOL} pending update. "
elif [ $updates -eq 0 ]; then
echo -en "You have no pending updates. " echo -en "You have no pending updates. "
elif [ "${updates}" -eq 1 ]; then
echo -en "You have ${NORM}1${NCOL} pending update. "
else else
echo -en "You have ~${NORM}$updates${NCOL} pending updates. " echo -en "You have ~${NORM}$updates${NCOL} pending updates. "
fi fi
@ -190,13 +208,12 @@ randcolor() {
# to modify it for a light one # # to modify it for a light one #
cluma=0 cluma=0
loops=0 loops=0
while [ $(printf %.0f $cluma) -le 100 ] && [ $loops -le 10 ]; while [ "$(printf %.0f $cluma)" -le 100 ] && [ $loops -le 10 ]; do
do cr=$((0 + RANDOM % 255))
cr=$((0 + $RANDOM % 255))
crl=$(echo "$cr 0.299" | awk '{print $1 * $2}') crl=$(echo "$cr 0.299" | awk '{print $1 * $2}')
cg=$((0 + $RANDOM % 255)) cg=$((0 + RANDOM % 255))
cgl=$(echo "$cg 0.587" | awk '{print $1 * $2}') cgl=$(echo "$cg 0.587" | awk '{print $1 * $2}')
cb=$((0 + $RANDOM % 255)) cb=$((0 + RANDOM % 255))
cbl=$(echo "$cb 0.114" | awk '{print $1 * $2}') cbl=$(echo "$cb 0.114" | awk '{print $1 * $2}')
cluma=$(echo "$crl $cgl $cbl" | awk '{print $1 + $2 + $3}') cluma=$(echo "$crl $cgl $cbl" | awk '{print $1 + $2 + $3}')
loops=$((loops+1)) loops=$((loops+1))
@ -235,11 +252,32 @@ updatecheck="on" #< Check for general updates
flatpakupd="off" #< Check for flatpak updates, this slows startup down A LOT flatpakupd="off" #< Check for flatpak updates, this slows startup down A LOT
goodgreeting="on" #< Display greetings like "Good afternoon," else "It's afternoon" goodgreeting="on" #< Display greetings like "Good afternoon," else "It's afternoon"
# ALL the stuff above this line and below the colors line is in the config, changing it here will do nothing only if the config doesn't exist!
source ~/.welcome/config.cfg source ~/.welcome/config.cfg
welcome welcome
greeting greeting
clock clock
battery battery
if [ "$updatecheck" = "on" ]; then updates; fi if [ "$updatecheck" = "on" ]; then
updates
fi
echo # Properly line break at the end echo # Properly line break at the end
set +e
date=$(date +%s)
lastdate=$(cat ~/.welcome/udm 2>/dev/null)
if [[ $((date - lastdate)) -ge 86400 ]]; then
if [[ "$environment" = "bash" ]]; then
bash ~/.welcome/install.sh auto
elif [[ "$environment" = "zsh" ]]; then
zsh ~/.welcome/install.sh auto
fi
date +%s >| ~/.welcome/udm 2>/dev/null
elif ! [[ -f ~/.welcome/udm ]]; then
touch ~/.welcome/udm
date +%s >| ~/.welcome/udm 2>/dev/null
fi