mirror of
https://github.com/G2-Games/welcome.sh.git
synced 2025-04-19 13:32:53 -05:00
Significantly cleaned up install script, dropped support for wget
This commit is contained in:
parent
49563932e0
commit
a863f8ddc6
1 changed files with 126 additions and 156 deletions
282
install.sh
282
install.sh
|
@ -1,9 +1,4 @@
|
||||||
# shellcheck disable=SC2016
|
# shellcheck disable=SC2016
|
||||||
printReturn () {
|
|
||||||
tput rc
|
|
||||||
echo "$1"
|
|
||||||
tput sc
|
|
||||||
}
|
|
||||||
|
|
||||||
getVersion () {
|
getVersion () {
|
||||||
ver=$(grep version ~/.welcome/welcome.sh 2> /dev/null | sed 's/.*=//')
|
ver=$(grep version ~/.welcome/welcome.sh 2> /dev/null | sed 's/.*=//')
|
||||||
|
@ -18,10 +13,11 @@ getVersion () {
|
||||||
|
|
||||||
univRead () { # Universal read command for bash and zsh
|
univRead () { # Universal read command for bash and zsh
|
||||||
echo -en "$1"
|
echo -en "$1"
|
||||||
|
echo -en "\n[\e[36mY/n\e[0m]"
|
||||||
if [[ "$environment" = "bash" ]]; then
|
if [[ "$environment" = "bash" ]]; then
|
||||||
read -p " " -n 1 -r;
|
read -p " " -r
|
||||||
elif [[ "$environment" = "zsh" ]]; then
|
elif [[ "$environment" = "zsh" ]]; then
|
||||||
read -q "REPLY? " -n 1 -r
|
read -q "REPLY? " -r
|
||||||
fi
|
fi
|
||||||
echo
|
echo
|
||||||
}
|
}
|
||||||
|
@ -36,173 +32,147 @@ oldver=$(grep version ~/.welcome/welcome.sh 2> /dev/null | sed 's/.*=//' | sed '
|
||||||
|
|
||||||
version="${1:-$latestver}"
|
version="${1:-$latestver}"
|
||||||
|
|
||||||
if [[ $1 == "auto" ]] && [[ ${latestver/[.][.]*/} -le $oldver ]]; then
|
if [[ $1 == "auto" ]] && [[ ${latestver//./} -le $oldver ]]; then
|
||||||
exit 0
|
exit 0
|
||||||
elif [[ $1 == "auto" ]]; then
|
elif [[ $1 == "auto" ]]; then
|
||||||
version=$latestver
|
version=$latestver
|
||||||
fi
|
fi
|
||||||
|
|
||||||
vernum=${version/[.][.]*/}
|
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" ]; then
|
# Check if the environment is bash or zsh
|
||||||
if ! grep -qs 'bash ~/.welcome/welcome.sh' $bashrc &&\
|
if [[ "$environment" != "bash" ]] && [[ "$environment" != "zsh" ]]; then
|
||||||
! grep -qs 'zsh ~/.welcome/welcome.sh' $zshrc &&\
|
printf "\e[31;5mERROR:\e[0m \e[31;3mThis script can only be installed in Bash or Zsh.\e[0m\n"
|
||||||
! grep -qs 'bash /home/$USER/.welcome/welcome.sh' $bashrc &&\
|
exit 0
|
||||||
! grep -qs 'zsh /home/$USER/.welcome/welcome.sh' $zshrc; then
|
fi
|
||||||
|
|
||||||
printReturn "Welcome! Installing v$version in $environment..."
|
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
|
||||||
|
tput rc
|
||||||
|
echo "Welcome! Installing v$version in $environment..."
|
||||||
|
tput sc
|
||||||
|
|
||||||
cd ~/ || return
|
cd ~/ || exit 1
|
||||||
mkdir -p ~/.welcome
|
mkdir -p ~/.welcome
|
||||||
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
|
||||||
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
|
chmod +x ~/.welcome/welcome.sh
|
||||||
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 ]]; then
|
|
||||||
wget https://github.com/G2-Games/welcome.sh/releases/download/v"${version}"/config.cfg --P ~/.welcome/
|
|
||||||
fi
|
|
||||||
else
|
|
||||||
echo -e "\e[31mCannot download, neither Wget nor cURL is available!\e[0m"
|
|
||||||
exit 1
|
|
||||||
fi
|
|
||||||
chmod +x ~/.welcome/welcome.sh
|
|
||||||
|
|
||||||
|
|
||||||
if [[ "$environment" = "bash" ]]; then
|
if [[ "$environment" = "bash" ]]; then
|
||||||
echo "Installing to bashrc"
|
echo "Installing to bashrc"
|
||||||
echo 'bash ~/.welcome/welcome.sh' >> $bashrc
|
echo 'bash ~/.welcome/welcome.sh' >> $bashrc
|
||||||
elif [[ "$environment" = "zsh" ]]; then
|
elif [[ "$environment" = "zsh" ]]; then
|
||||||
echo "Installing to zshrc"
|
echo "Installing to zshrc"
|
||||||
echo 'zsh ~/.welcome/welcome.sh' >> $zshrc
|
echo 'zsh ~/.welcome/welcome.sh' >> $zshrc
|
||||||
fi
|
fi
|
||||||
|
|
||||||
cd "$originaldir" || return
|
cd "$originaldir" || exit 1
|
||||||
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
|
||||||
|
tput rc
|
||||||
|
tput sc
|
||||||
|
mkdir -p ~/.welcome
|
||||||
|
if ! [[ $1 == "auto" ]]; then
|
||||||
|
echo -e "\e[35mwelcome.sh\e[0m already installed!"
|
||||||
else
|
else
|
||||||
tput rc
|
echo -e "\e[32mUpdate available for \e[35mwelcome.sh!\e[0m"
|
||||||
tput sc
|
fi
|
||||||
mkdir -p ~/.welcome
|
|
||||||
if ! [[ $1 == "auto" ]]; then
|
if [[ $vernum -gt $oldver ]]; then
|
||||||
echo -e "\e[35mwelcome.sh\e[0m already installed!"
|
|
||||||
else
|
# Pull the new configuration version from github
|
||||||
echo -e "\e[32mUpdate available for \e[35mwelcome.sh!\e[0m"
|
newCfgVer=$(curl -Ls https://github.com/G2-Games/welcome.sh/releases/download/v"${version}"/config.cfg | grep version | cut -d= -f2)
|
||||||
fi
|
|
||||||
if [[ $vernum -gt $oldver ]]; then
|
univRead "Do you want to \e[36mupdate \e[35mwelcome.sh\e[0m? (\e[36mv$(getVersion)\e[0m => \e[32mv$version\e[0m)"
|
||||||
if which curl >/dev/null ; then
|
if ! [[ $REPLY =~ ^[Yy]$ ]]; then
|
||||||
cfgver=$(curl -Ls https://github.com/G2-Games/welcome.sh/releases/download/v"${version}"/config.cfg | grep version | sed 's/.*=//' | sed 's/[.][.]*//g')
|
tput rc && tput el && tput ed
|
||||||
elif which wget >/dev/null; then
|
echo -e "\e[31mCancelled"
|
||||||
cfgver=$(wget -q https://github.com/G2-Games/welcome.sh/releases/download/v"${version}"/config.cfg -O - | grep version | sed 's/.*=//' | sed 's/[.][.]*//g')
|
if [[ $1 != "auto" ]]; then
|
||||||
|
echo -e "\e[35mwelcome.sh\e[0m already installed!"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
univRead "Do you want to \e[36mupdate \e[35mwelcome.sh\e[0m? (\e[36mv$(getVersion)\e[0m => \e[32mv$version\e[0m) \n\e[36mY/n\e[0m"
|
|
||||||
|
|
||||||
if [[ $REPLY =~ ^[Yy]$ ]]; then
|
|
||||||
if [[ $cfgver -gt $(grep version ~/.welcome/config.cfg 2> /dev/null | sed 's/.*=//' | sed 's/[.][.]*//g') ]] && [ -n ~/.welcome/config.cfg ]; 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.\n\e[36mY/n\e[0m"
|
|
||||||
|
|
||||||
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
|
|
||||||
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
|
|
||||||
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 && tput el && tput ed
|
|
||||||
echo -e "\e[32mUpdated to v$version! \e[0m"
|
|
||||||
exit 0
|
|
||||||
else
|
|
||||||
tput rc && tput el && tput ed
|
|
||||||
if ! [[ $1 == "auto" ]]; then
|
|
||||||
echo -e "\e[35mwelcome.sh\e[0m already installed!"
|
|
||||||
else
|
|
||||||
exit 0
|
|
||||||
fi
|
|
||||||
fi
|
|
||||||
fi
|
|
||||||
|
|
||||||
univRead "Do you want to \e[31muninstall \e[35mwelcome.sh\e[0m?\n\e[36mY/n\e[0m"
|
|
||||||
|
|
||||||
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 $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"
|
|
||||||
else
|
|
||||||
tput rc && tput el && tput ed
|
|
||||||
echo -e "\e[31mCancelled. \e[0m"
|
|
||||||
exit 0
|
exit 0
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
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
|
||||||
|
|
||||||
|
tput rc && tput el && tput ed
|
||||||
|
echo "Updating..."
|
||||||
|
tput sc
|
||||||
|
mkdir -p ~/.welcome
|
||||||
|
rm ~/.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 ]] && [[ $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')
|
||||||
|
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
|
||||||
|
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 && tput el && tput ed
|
||||||
|
echo -e "\e[32mUpdated to v$version! \e[0m"
|
||||||
|
exit 0
|
||||||
fi
|
fi
|
||||||
else
|
|
||||||
printf "\e[31;5mERROR:\e[0m \e[31;3mThis script can only be installed in Bash or Zsh.\e[0m\n"
|
# 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 && tput el && tput ed
|
||||||
|
echo -e "\e[31mCancelled. \e[0m"
|
||||||
|
exit 0
|
||||||
|
fi
|
||||||
|
|
||||||
|
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 $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"
|
||||||
fi
|
fi
|
||||||
|
|
Loading…
Reference in a new issue