mirror of
https://github.com/G2-Games/welcome.sh.git
synced 2025-04-19 13:32:53 -05:00
Improved updater and uninstaller, should have complete compatibility with MacOS
This commit is contained in:
parent
d576cf98fb
commit
544ed01199
1 changed files with 19 additions and 17 deletions
36
install.sh
36
install.sh
|
@ -6,7 +6,7 @@ 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" ];
|
if [ "$environment" = "bash" ] || [ "$environment" = "zsh" ];
|
||||||
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;
|
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
|
||||||
echo "Welcome! Installing v$version in $environment..."
|
echo "Welcome! Installing v$version in $environment..."
|
||||||
tput sc
|
tput sc
|
||||||
|
@ -39,20 +39,21 @@ then
|
||||||
echo 'zsh ~/.welcome/welcome.sh' >> $zshrc
|
echo 'zsh ~/.welcome/welcome.sh' >> $zshrc
|
||||||
fi
|
fi
|
||||||
cd "$originaldir"
|
cd "$originaldir"
|
||||||
tput rc el ed
|
tput rc && tput el && tput ed
|
||||||
echo -e "\e[36mInstalled! \e[0m"
|
echo -e "\e[36mInstalled! \e[0m"
|
||||||
else
|
else
|
||||||
tput sc
|
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 | 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
|
||||||
cfgver=$(echo $(curl -Ls https://github.com/G2-Games/welcome.sh/releases/download/v$version/config.cfg) | grep version | sed 's/.*=//' | sed 's/[.][.]*//g') # Check the new config version
|
cfgver=$(echo $(curl -Ls https://github.com/G2-Games/welcome.sh/releases/download/v$version/config.cfg) | grep version | sed 's/.*=//' | sed 's/[.][.]*//g') # Check the new config version
|
||||||
echo -en "Do you want to \e[36mupdate \e[35mwelcome.sh\e[0m? (\e[36mv$(ver=$(grep version ~/.welcome/welcome.sh | 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"
|
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;
|
if [[ "$environment" = "bash" ]]; then read -p " " -n 1 -r;
|
||||||
elif [[ "$environment" = "zsh" ]]; then read -q "REPLY? " -n 1 -r; fi
|
elif [[ "$environment" = "zsh" ]]; then read -q "REPLY? " -n 1 -r; fi
|
||||||
echo
|
echo
|
||||||
if [[ $REPLY =~ ^[Yy]$ ]]; then
|
if [[ $REPLY =~ ^[Yy]$ ]]; then
|
||||||
if [[ $cfgver -gt $(grep version ~/.welcome/config.cfg 2> /dev/null | sed 's/.*=//' | sed 's/[.][.]*//g') ]] && [ -a ~/.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"
|
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;
|
if [[ "$environment" = "bash" ]]; then read -p " " -n 1 -r;
|
||||||
elif [[ "$environment" = "zsh" ]]; then read -q "REPLY? " -n 1 -r; fi
|
elif [[ "$environment" = "zsh" ]]; then read -q "REPLY? " -n 1 -r; fi
|
||||||
|
@ -65,9 +66,10 @@ then
|
||||||
else
|
else
|
||||||
overcfg=0
|
overcfg=0
|
||||||
fi
|
fi
|
||||||
tput rc el ed
|
tput rc && tput el && tput ed
|
||||||
echo "Updating..."
|
echo "Updating..."
|
||||||
tput sc
|
tput sc
|
||||||
|
mkdir -p ~/.welcome
|
||||||
rm ~/.welcome/welcome.sh
|
rm ~/.welcome/welcome.sh
|
||||||
if which curl >/dev/null ;
|
if which curl >/dev/null ;
|
||||||
then
|
then
|
||||||
|
@ -92,24 +94,24 @@ then
|
||||||
|
|
||||||
# Check for older versions and replace bashrc lines
|
# 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=$(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' "$( echo "$lines" )" | sort | tac | tr '\n' ' '; echo)
|
lines=$(printf '%s\n' $lines | sed '1!G;h;$!d' | sed ':a;N;$!ba;s/\n/ /g')
|
||||||
for i in $( echo "$lines" ); do
|
for i in $( echo "$lines" ); do
|
||||||
sed "${i}d" $bashrc > file.tmp && mv file.tmp $bashrc
|
sed "${i}d" $bashrc > file.tmp && mv file.tmp $bashrc
|
||||||
done
|
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' "$( echo "$lines" )" | sort | tac | tr '\n' ' '; echo)
|
lines=$(printf '%s\n' $lines | sed '1!G;h;$!d' | sed ':a;N;$!ba;s/\n/ /g')
|
||||||
for i in $( echo "$lines" ); do
|
for i in $( echo "$lines" ); do
|
||||||
sed "${i}d" $zshrc > file.tmp && mv file.tmp $zshrc
|
sed "${i}d" $zshrc > file.tmp && mv file.tmp $zshrc
|
||||||
done
|
done
|
||||||
echo 'zsh ~/.welcome/welcome.sh' >> $zshrc
|
echo 'zsh ~/.welcome/welcome.sh' >> $zshrc
|
||||||
|
|
||||||
tput rc el ed
|
tput rc && tput el && tput ed
|
||||||
echo -e "\e[32mUpdated to v$version! \e[0m"
|
echo -e "\e[32mUpdated to v$version! \e[0m"
|
||||||
exit 0
|
exit 0
|
||||||
else
|
else
|
||||||
tput rc el ed
|
tput rc && tput el && tput ed
|
||||||
echo -e "\e[35mwelcome.sh\e[0m already installed!"
|
echo -e "\e[35mwelcome.sh\e[0m already installed!"
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
|
@ -118,31 +120,31 @@ then
|
||||||
elif [[ "$environment" = "zsh" ]]; then read -q "REPLY? " -n 1 -r; fi
|
elif [[ "$environment" = "zsh" ]]; then read -q "REPLY? " -n 1 -r; fi
|
||||||
echo
|
echo
|
||||||
if [[ $REPLY =~ ^[Yy]$ ]]; then
|
if [[ $REPLY =~ ^[Yy]$ ]]; then
|
||||||
tput rc el ed
|
tput rc && tput el && tput ed
|
||||||
echo "Goodbye. Uninstalling..."
|
echo "Goodbye. Uninstalling..."
|
||||||
tput sc
|
tput sc
|
||||||
rm ~/.welcome/welcome.sh
|
rm ~/.welcome/welcome.sh 2> /dev/null
|
||||||
rm ~/.welcome/config.cfg
|
rm ~/.welcome/config.cfg 2> /dev/null
|
||||||
rm ~/.welcome/config_old.cfg 2> /dev/null
|
rm ~/.welcome/config_old.cfg 2> /dev/null
|
||||||
rm -r ~/.welcome
|
rm -r ~/.welcome
|
||||||
|
|
||||||
#remove all lines that match the string
|
#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=$(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' "$( echo "$lines" )" | sort | tac | tr '\n' ' '; echo)
|
lines=$(printf '%s\n' $lines | sed '1!G;h;$!d' | sed ':a;N;$!ba;s/\n/ /g')
|
||||||
for i in $( echo "$lines" ); do
|
for i in $( echo "$lines" ); do
|
||||||
sed "${i}d" $bashrc > file.tmp && mv file.tmp $bashrc
|
sed "${i}d" $bashrc > file.tmp && mv file.tmp $bashrc
|
||||||
done
|
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=$(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' "$( echo "$lines" )" | sort | tac | tr '\n' ' '; echo)
|
lines=$(printf '%s\n' $lines | sed '1!G;h;$!d' | sed ':a;N;$!ba;s/\n/ /g')
|
||||||
for i in $( echo "$lines" ); do
|
for i in $( echo "$lines" ); do
|
||||||
sed "${i}d" $zshrc > file.tmp && mv file.tmp $zshrc
|
sed "${i}d" $zshrc > file.tmp && mv file.tmp $zshrc
|
||||||
done
|
done
|
||||||
|
|
||||||
tput rc el ed
|
tput rc && tput el && tput ed
|
||||||
echo -e "\e[36mUninstalled! \e[0m"
|
echo -e "\e[36mUninstalled! \e[0m"
|
||||||
else
|
else
|
||||||
tput rc el ed
|
tput rc && tput el && tput ed
|
||||||
echo -e "\e[31mCancelled. \e[0m"
|
echo -e "\e[31mCancelled. \e[0m"
|
||||||
exit 0
|
exit 0
|
||||||
fi
|
fi
|
||||||
|
|
Loading…
Reference in a new issue