Streamlined install script, added support for checking latest release automatically

This commit is contained in:
G2-Games 2022-11-26 14:40:23 -06:00
parent cc7ec85760
commit 56883965c5

View file

@ -1,25 +1,38 @@
version="${1:-1.0.5}" tput sc
echo "Checking for latest release..."
latestver=$(curl -Ls https://github.com/G2-Games/welcome.sh/releases/latest/download/welcome.sh | grep version | sed 's/.*=//')
version="${1:-$latestver}"
vernum=$(echo $version | sed 's/[.][.]*//g' ) vernum=$(echo $version | sed 's/[.][.]*//g' )
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" ];
then univread() { # Universal read command for bash and zsh
echo -en $1
if [[ "$environment" = "bash" ]]; then
read -p " " -n 1 -r;
elif [[ "$environment" = "zsh" ]]; then
read -q "REPLY? " -n 1 -r
fi
echo
}
if [ "$environment" = "bash" ] || [ "$environment" = "zsh" ]; 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 ]; 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 ];
then then
tput rc
echo "Welcome! Installing v$version in $environment..." echo "Welcome! Installing v$version in $environment..."
tput sc tput sc
cd ~/ cd ~/
mkdir -p ~/.welcome mkdir -p ~/.welcome
if which curl >/dev/null ; if which curl >/dev/null ; then
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
if [[ $vernum -ge 100 ]]; then if [[ $vernum -ge 100 ]]; then
curl -SL https://github.com/G2-Games/welcome.sh/releases/download/v${version}/config.cfg --output ~/.welcome/config.cfg curl -SL https://github.com/G2-Games/welcome.sh/releases/download/v${version}/config.cfg --output ~/.welcome/config.cfg
fi fi
elif which wget >/dev/null ; elif which wget >/dev/null ; then
then
wget https://github.com/G2-Games/welcome.sh/releases/download/v${version}/welcome.sh --P ~/.welcome/ wget https://github.com/G2-Games/welcome.sh/releases/download/v${version}/welcome.sh --P ~/.welcome/
if [[ $vernum -ge 100 ]]; then if [[ $vernum -ge 100 ]]; then
wget https://github.com/G2-Games/welcome.sh/releases/download/v${version}/config.cfg --P ~/.welcome/ wget https://github.com/G2-Games/welcome.sh/releases/download/v${version}/config.cfg --P ~/.welcome/
@ -42,23 +55,25 @@ then
tput rc && tput el && tput ed tput rc && tput el && tput ed
echo -e "\e[36mInstalled! \e[0m" echo -e "\e[36mInstalled! \e[0m"
else else
tput rc
tput sc tput sc
mkdir -p ~/.welcome 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 oldver=$(grep version ~/.welcome/welcome.sh 2> /dev/null | sed 's/.*=//' | sed 's/[.][.]*//g') && if ! [ -n "$oldver" ]; then oldver=0; fi
if [[ $vernum -gt $oldver ]]; then if [[ $vernum -gt $oldver ]]; then
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'); if which curl >/dev/null ; then
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 cfgver=$(echo $(curl -Ls https://github.com/G2-Games/welcome.sh/releases/download/v${version}/config.cfg) | grep version | sed 's/.*=//' | sed 's/[.][.]*//g')
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" elif which wget >/dev/null; then
if [[ "$environment" = "bash" ]]; then read -p " " -n 1 -r; cfgver=$(echo $(wget -q https://github.com/G2-Games/welcome.sh/releases/download/v${version}/config.cfg -O -) | grep version | sed 's/.*=//' | sed 's/[.][.]*//g')
elif [[ "$environment" = "zsh" ]]; then read -q "REPLY? " -n 1 -r; fi fi
echo
univread "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 [[ $REPLY =~ ^[Yy]$ ]]; then 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 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; univread "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"
elif [[ "$environment" = "zsh" ]]; then read -q "REPLY? " -n 1 -r; fi
echo
if [[ $REPLY =~ ^[Yy]$ ]]; then if [[ $REPLY =~ ^[Yy]$ ]]; then
overcfg=1 overcfg=1
fi fi
@ -116,10 +131,9 @@ then
echo -e "\e[35mwelcome.sh\e[0m already installed!" echo -e "\e[35mwelcome.sh\e[0m already installed!"
fi fi
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; univread "Do you want to \e[31muninstall \e[35mwelcome.sh\e[0m?\n\e[36mY/n\e[0m"
elif [[ "$environment" = "zsh" ]]; then read -q "REPLY? " -n 1 -r; fi
echo
if [[ $REPLY =~ ^[Yy]$ ]]; then if [[ $REPLY =~ ^[Yy]$ ]]; then
tput rc && tput el && tput ed tput rc && tput el && tput ed
echo "Goodbye. Uninstalling..." echo "Goodbye. Uninstalling..."