mirror of
https://github.com/G2-Games/welcome.sh.git
synced 2025-06-23 09:12:53 -05:00
Compare commits
4 commits
bd0f3f2cc0
...
a863f8ddc6
Author | SHA1 | Date | |
---|---|---|---|
a863f8ddc6 | |||
49563932e0 | |||
e072e7c7fc | |||
b7608a59d0 |
3 changed files with 153 additions and 171 deletions
|
@ -31,15 +31,6 @@ 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`
|
||||||
|
|
||||||
|
|
167
install.sh
167
install.sh
|
@ -1,71 +1,81 @@
|
||||||
|
# shellcheck disable=SC2016
|
||||||
|
|
||||||
|
getVersion () {
|
||||||
|
ver=$(grep version ~/.welcome/welcome.sh 2> /dev/null | sed 's/.*=//')
|
||||||
|
|
||||||
|
if [ -z "$ver" ]; then
|
||||||
|
echo -e "\bUnknown"
|
||||||
|
return
|
||||||
|
fi
|
||||||
|
|
||||||
|
echo "$ver"
|
||||||
|
}
|
||||||
|
|
||||||
|
univRead () { # Universal read command for bash and zsh
|
||||||
|
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
|
||||||
|
}
|
||||||
|
|
||||||
tput sc
|
tput sc
|
||||||
if ! [[ $1 == "auto" ]] && [ -z "$1" ]; then
|
if ! [[ $1 == "auto" ]] && [[ -z "$1" ]]; then
|
||||||
echo "Checking for latest release..."
|
echo "Checking for latest release..."
|
||||||
fi
|
fi
|
||||||
|
|
||||||
latestver=$(curl -Ls https://github.com/G2-Games/welcome.sh/releases/latest/download/welcome.sh | grep version | sed 's/.*=//')
|
latestver=$(curl -Ls https://github.com/G2-Games/welcome.sh/releases/latest/download/welcome.sh | grep version | sed 's/.*=//')
|
||||||
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 [[ -z "$oldver" ]]; then oldver=0; fi
|
||||||
|
|
||||||
version="${1:-$latestver}"
|
version="${1:-$latestver}"
|
||||||
|
|
||||||
if [[ $1 == "auto" ]] && [[ $(echo $latestver | sed 's/[.][.]*//g') -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=$(echo $version | sed 's/[.][.]*//g' )
|
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)
|
||||||
|
|
||||||
univread() { # Universal read command for bash and zsh
|
# Check if the environment is bash or zsh
|
||||||
echo -en $1
|
if [[ "$environment" != "bash" ]] && [[ "$environment" != "zsh" ]]; then
|
||||||
if [[ "$environment" = "bash" ]]; then
|
printf "\e[31;5mERROR:\e[0m \e[31;3mThis script can only be installed in Bash or Zsh.\e[0m\n"
|
||||||
read -p " " -n 1 -r;
|
exit 0
|
||||||
elif [[ "$environment" = "zsh" ]]; then
|
fi
|
||||||
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; 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 ];
|
|
||||||
then
|
|
||||||
tput rc
|
tput rc
|
||||||
echo "Welcome! Installing v$version in $environment..."
|
echo "Welcome! Installing v$version in $environment..."
|
||||||
tput sc
|
tput sc
|
||||||
cd ~/
|
|
||||||
|
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
|
|
||||||
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
|
fi
|
||||||
chmod +x ~/.welcome/welcome.sh
|
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" ]];
|
elif [[ "$environment" = "zsh" ]]; then
|
||||||
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"
|
|
||||||
|
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
|
else
|
||||||
tput rc
|
tput rc
|
||||||
tput sc
|
tput sc
|
||||||
mkdir -p ~/.welcome
|
mkdir -p ~/.welcome
|
||||||
|
@ -74,65 +84,57 @@ if [ "$environment" = "bash" ] || [ "$environment" = "zsh" ]; then
|
||||||
else
|
else
|
||||||
echo -e "\e[32mUpdate available for \e[35mwelcome.sh!\e[0m"
|
echo -e "\e[32mUpdate available for \e[35mwelcome.sh!\e[0m"
|
||||||
fi
|
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')
|
# Pull the new configuration version from github
|
||||||
elif which wget >/dev/null; then
|
newCfgVer=$(curl -Ls https://github.com/G2-Games/welcome.sh/releases/download/v"${version}"/config.cfg | grep version | cut -d= -f2)
|
||||||
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')
|
|
||||||
|
univRead "Do you want to \e[36mupdate \e[35mwelcome.sh\e[0m? (\e[36mv$(getVersion)\e[0m => \e[32mv$version\e[0m)"
|
||||||
|
if ! [[ $REPLY =~ ^[Yy]$ ]]; then
|
||||||
|
tput rc && tput el && tput ed
|
||||||
|
echo -e "\e[31mCancelled"
|
||||||
|
if [[ $1 != "auto" ]]; then
|
||||||
|
echo -e "\e[35mwelcome.sh\e[0m already installed!"
|
||||||
|
fi
|
||||||
|
exit 0
|
||||||
fi
|
fi
|
||||||
|
|
||||||
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 [[ $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
|
|
||||||
if [[ $cfgver -gt $(grep version ~/.welcome/config.cfg 2> /dev/null | sed 's/.*=//' | sed 's/[.][.]*//g') ]] && ! [ -z ~/.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
|
if [[ $REPLY =~ ^[Yy]$ ]]; then
|
||||||
overcfg=1
|
overcfg=1
|
||||||
fi
|
fi
|
||||||
elif [ $oldver -lt 100 ]; then
|
elif [[ $oldver -lt 100 ]]; then
|
||||||
overcfg=1
|
overcfg=1
|
||||||
else
|
else
|
||||||
overcfg=0
|
overcfg=0
|
||||||
fi
|
fi
|
||||||
|
|
||||||
tput rc && tput el && tput ed
|
tput rc && tput el && tput ed
|
||||||
echo "Updating..."
|
echo "Updating..."
|
||||||
tput sc
|
tput sc
|
||||||
mkdir -p ~/.welcome
|
mkdir -p ~/.welcome
|
||||||
rm ~/.welcome/welcome.sh
|
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
|
||||||
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
|
if [[ $vernum -ge 100 ]] && [[ $overcfg -gt 0 ]]; then
|
||||||
echo "Backing up: config.cfg >> config_old.cfg"
|
echo "Backing up: config.cfg >> config_old.cfg"
|
||||||
mv ~/.welcome/config.cfg ~/.welcome/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
|
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
|
fi
|
||||||
|
|
||||||
# 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' $lines | sed '1!G;h;$!d' | sed ':a;N;$!ba;s/\n/ /g')
|
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 $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' $lines | sed '1!G;h;$!d' | sed ':a;N;$!ba;s/\n/ /g')
|
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 $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
|
||||||
|
@ -140,19 +142,16 @@ if [ "$environment" = "bash" ] || [ "$environment" = "zsh" ]; then
|
||||||
tput rc && tput el && tput 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
|
fi
|
||||||
|
|
||||||
|
# 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
|
tput rc && tput el && tput ed
|
||||||
if ! [[ $1 == "auto" ]]; then
|
echo -e "\e[31mCancelled. \e[0m"
|
||||||
echo -e "\e[35mwelcome.sh\e[0m already installed!"
|
|
||||||
else
|
|
||||||
exit 0
|
exit 0
|
||||||
fi
|
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
|
tput rc && tput el && tput ed
|
||||||
echo "Goodbye. Uninstalling..."
|
echo "Goodbye. Uninstalling..."
|
||||||
tput sc
|
tput sc
|
||||||
|
@ -163,25 +162,17 @@ if [ "$environment" = "bash" ] || [ "$environment" = "zsh" ]; then
|
||||||
|
|
||||||
#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' $lines | sed '1!G;h;$!d' | sed ':a;N;$!ba;s/\n/ /g')
|
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 $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' $lines | sed '1!G;h;$!d' | sed ':a;N;$!ba;s/\n/ /g')
|
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 $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 && tput el && tput ed
|
tput rc && tput el && tput ed
|
||||||
echo -e "\e[36mUninstalled! \e[0m"
|
echo -e "\e[36mUninstalled! \e[0m"
|
||||||
else
|
|
||||||
tput rc && tput el && tput ed
|
|
||||||
echo -e "\e[31mCancelled. \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"
|
|
||||||
fi
|
fi
|
||||||
|
|
|
@ -119,7 +119,7 @@ updates () {
|
||||||
updchk () {
|
updchk () {
|
||||||
# Check for APT
|
# Check for APT
|
||||||
if command -v apt-get &> /dev/null; then
|
if command -v apt-get &> /dev/null; then
|
||||||
debian=$(apt-get -s dist-upgrade -V | grep '=>' || [[ $? == 1 ]] | wc -l)
|
debian=$(apt-get -s dist-upgrade -V | grep -c '=>')
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Check for different Arch things
|
# Check for different Arch things
|
||||||
|
|
Loading…
Reference in a new issue