Made install use proper home directory

This commit is contained in:
G2-Games 2022-09-18 19:25:24 -05:00
parent a6b5f4ded8
commit b5060b4658

View file

@ -1,34 +1,34 @@
version=0.2.5 version=0.2.5
bashrc="/home/$USER/.bashrc" bashrc=~/.bashrc
zshrc="/home/$USER/.zshrc" zshrc=~/.zshrc
originaldir=$PWD originaldir=$PWD
environment=$(ps -o args= -p $$ | egrep -m 1 -o '\w{0,5}sh' | head -1) environment=$(ps -o args= -p $$ | egrep -m 1 -o '\w{0,5}sh' | head -1)
if [ "$environment" = "bash" ] || [ "$environment" = "zsh" ]; if [ "$environment" = "bash" ] || [ "$environment" = "zsh" ];
then then
if ! grep -q 'bash /home/$USER/.welcome/welcome.sh' $bashrc && ! grep -q 'zsh /home/$USER/.welcome/welcome.sh' $zshrc; if ! grep -q 'bash ~/.welcome/welcome.sh' $bashrc && ! grep -q 'zsh ~/.welcome/welcome.sh' $zshrc && ! grep -q 'bash /home/$USER/.welcome/welcome.sh' $bashrc && ! grep -q 'zsh /home/$USER/.welcome/welcome.sh' $zshrc;
then then
echo "Welcome! Installing in $environment..." echo "Welcome! Installing in $environment..."
tput sc tput sc
cd /home/$USER cd ~/
mkdir -p /home/$USER/.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 /home/$USER/.welcome/welcome.sh curl -SL https://github.com/G2-Games/welcome.sh/releases/download/v${version}/welcome.sh --output ~/.welcome/welcome.sh
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 /home/$USER/.welcome/ wget https://github.com/G2-Games/welcome.sh/releases/download/v${version}/welcome.sh --P ~/.welcome/
else else
echo "Cannot download, neither wget nor curl is available." echo "Cannot download, neither wget nor curl is available."
exit 1 exit 1
fi fi
chmod +x /home/$USER/.welcome/welcome.sh chmod +x ~/.welcome/welcome.sh
if [[ "$environment" = "bash" ]]; if [[ "$environment" = "bash" ]];
then then
echo 'bash /home/$USER/.welcome/welcome.sh' >> $bashrc echo 'bash ~/.welcome/welcome.sh' >> $bashrc
echo "Installing to bashrc" echo "Installing to bashrc"
elif [[ "$environment" = "zsh" ]]; elif [[ "$environment" = "zsh" ]];
then then
echo 'zsh /home/$USER/.welcome/welcome.sh' >> $zshrc echo 'zsh ~/.welcome/welcome.sh' >> $zshrc
echo "Installing to zshrc" echo "Installing to zshrc"
fi fi
cd "$originaldir" cd "$originaldir"
@ -51,8 +51,22 @@ then
tput rc el ed tput rc el ed
echo "Goodbye. Uninstalling..." echo "Goodbye. Uninstalling..."
tput sc tput sc
rm /home/$USER/.welcome/welcome.sh rm ~/.welcome/welcome.sh
rmdir /home/$USER/.welcome rmdir ~/.welcome
if grep -n 'bash ~/.welcome/welcome.sh' $bashrc ;
then
line=$(grep -n 'bash ~/.welcome/welcome.sh' $bashrc)
line=${line%:*}
sed -i "${line}d" $bashrc
fi
if grep -n 'zsh ~/.welcome/welcome.sh' $zshrc ;
then
line=$(grep -n 'zsh ~/.welcome/welcome.sh' $zshrc)
line=${line%:*}
sed -i "${line}d" $zshrc
fi
# Check for older versions #
if grep -n 'bash /home/$USER/.welcome/welcome.sh' $bashrc ; if grep -n 'bash /home/$USER/.welcome/welcome.sh' $bashrc ;
then then
line=$(grep -n 'bash /home/$USER/.welcome/welcome.sh' $bashrc) line=$(grep -n 'bash /home/$USER/.welcome/welcome.sh' $bashrc)
@ -65,6 +79,7 @@ then
line=${line%:*} line=${line%:*}
sed -i "${line}d" $zshrc sed -i "${line}d" $zshrc
fi fi
tput rc el ed tput rc el ed
echo -e "\e[36mUninstalled! \e[0m" echo -e "\e[36mUninstalled! \e[0m"
else else