Bash script to install zsh on different distributions Extreme script newbie here, so please go easy on me!
I wrote a script to install zsh on a number of different Linux distributions. But since I'm so new at this, I'm piecing a lot of different things together and I doubt it's as efficient and tight as possible. Any suggestions are welcome. Thank you!
#!/bin/bash

export ZSHUSER=$USER

if [ -f /etc/os-release ]; then
    . /etc/os-release
    OS=$NAME
    VER=$VERSION_ID
elif type lsb_release &gt;/dev/null 2&gt;&amp;1; then
    OS=$(lsb_release -si)
    VER=$(lsb_release -sr)
fi

echo &quot;Creating fonts directory&quot;
cd /tmp &amp;&amp; mkdir fonts &amp;&amp; cd $_

echo &quot;Downloading fonts&quot;
wget https://github.com/romkatv/powerlevel10k-media/raw/master/MesloLGS%20NF%20Regular.ttf
wget https://github.com/romkatv/powerlevel10k-media/raw/master/MesloLGS%20NF%20Bold.ttf
wget https://github.com/romkatv/powerlevel10k-media/raw/master/MesloLGS%20NF%20Italic.ttf
wget https://github.com/romkatv/powerlevel10k-media/raw/master/MesloLGS%20NF%20Bold%20Italic.ttf

echo &quot;Entering sudo mode to copy fonts&quot;

if [[ $NAME = &quot;Fedora&quot; ]]; then
sudo su - &lt;&lt;EOF
dnf install -y git zsh zsh-autosuggestions zsh-syntax-highlighting
cd /usr/share/fonts/ &amp;&amp; mkdir MesloMGS
cp /tmp/fonts/*.ttf /usr/share/fonts/MesloMGS
fc-cache
rm -r /tmp/fonts
scp -v /mnt/E/Linux/zsh/$NAME/aliasrc $HOME
chown $USER:$USER $HOME/aliasrc
su $USER
EOF

elif [[ $NAME = &quot;void&quot; ]]; then
sudo su - &lt;&lt;EOF
xbps-install -y git zsh zsh-autosuggestions zsh-syntax-highlighting
cp /tmp/fonts/*.ttf /usr/share/fonts/TTF
fc-cache
rm -r /tmp/fonts
scp -v /mnt/E/Linux/zsh/$NAME/aliasrc $HOME
chown $USER:$USER $HOME/aliasrc
su $USER
EOF

elif [[ $NAME = &quot;Debian&quot; ]] || [[ $NAME = &quot;Ubuntu&quot; ]] || [[ $NAME = &quot;Linux Mint&quot; ]]; then
sudo su - &lt;&lt;EOF
apt install -y git zsh zsh-autosuggestions zsh-syntax-highlighting
cd /usr/share/fonts/truetype &amp;&amp; mkdir MesloMGS
cp /tmp/fonts/*.ttf /usr/share/fonts/truetype/MesloMGS
fc-cache
rm -r /tmp/fonts
scp -v /mnt/E/Linux/zsh/Debian/aliasrc $HOME
chown $USER:$USER $HOME/aliasrc
su $USER
EOF

elif [[ $NAME = &quot;CentOS Linux&quot; ]]; then
sudo su - &lt;&lt;EOF
yum install -y git zsh zsh-syntax-highlighting
cd /usr/share/fonts/ &amp;&amp; mkdir MesloMGS
cp /tmp/fonts/*.ttf /usr/share/fonts/MesloMGS
fc-cache
rm -r /tmp/fonts
scp -v /mnt/E/Linux/zsh/CentOS/aliasrc $HOME
chown $USER:$USER $HOME/aliasrc
git clone https://github.com/zsh-users/zsh-autosuggestions /usr/share/zsh-autosuggestions/zsh-autosuggestions.zsh
su $USER
EOF

else
echo &quot;Operating system not identified&quot;
pause
fi

mkdir ~/powerlevel10k &amp;&amp; cd ~/powerlevel10k
git clone --depth=1 https://github.com/romkatv/powerlevel10k.git ~/powerlevel10k
echo 'source ~/powerlevel10k/powerlevel10k.zsh-theme' &gt;&gt; ~/.zshrc

echo &quot;opening terminal to configure zsh&quot;
if [[ $NAME = &quot;Ubuntu&quot; ]] || [[ $NAME = &quot;CentOS Linux&quot; ]] || [[ $NAME = &quot;Linux Mint&quot; ]]; then
    gnome-terminal -q -- zsh
    read -p &quot;press enter to resume&quot;
elif [[ $NAME = &quot;Fedora&quot; ]]; then
    mate-terminal -e zsh
elif [[ $NAME = void ]]; then
    qterminal -e zsh
elif [[ $NAME = Debian ]]; then
    xfce4-terminal -e zsh
fi

sudo su - &lt;&lt;EOF
echo &quot;copying .zshrc file&quot;
scp -v /mnt/E/Linux/zsh/.zshrc $HOME
chown $USER:$USER $HOME/.zshrc
su $USER
EOF

```
if [[ $NAME = &quot;Fedora&quot; ]]; then
elif [[ $NAME = &quot;void&quot; ]]; then
elif [[ $NAME = &quot;Debian&quot; ]] || [[ $NAME = &quot;Ubuntu&quot; ]] || [[ $NAME = &quot;Linux Mint&quot; ]]; then


That looks like a candidate for case &quot;$NAME&quot; in.  However, instead of changing that, let's look at what we're doing:

if [[ $NAME = &quot;Fedora&quot; ]]
then
   dnf install -y git zsh zsh-autosuggestions zsh-syntax-highlighting


Ah, so we're using that to determine which package manager is in use.  It might be better to just test that directly:

if [ -x /usr/bin/dnf ]
then
   dnf install


That has the added benefit that it's plain POSIX shell, not requiring Bash.

Hang on, where did that $NAME come from?  Let's look:

if [ -f /etc/os-release ]; then
    . /etc/os-release
    OS=$NAME
    VER=$VERSION_ID
elif type lsb_release &gt;/dev/null 2&gt;&amp;1; then
    OS=$(lsb_release -si)
    VER=$(lsb_release -sr)
fi


Oh dear, it looks like NAME is assigned in only one of those two paths, and we actually wanted to be using OS (or assigning to NAME and VERSION_ID in the elif branch, and getting rid of OS and VER).
This is why it's a good idea to set -u, so that you get an error when expanding an undefined variable.


echo &quot;Operating system not identified&quot;
pause


That should be echo &gt;&amp;2, since it's an error message.  What's pause?  It's certainly not a common tool, and you probably just want to exit 1 at that point anyway.

Not a big fan of copying those font files into /usr/share (that should be only for files under control of the package manager).  That's what /usr/local is for.

Why are we using scp for a local copy?  Just use plain cp and reduce the dependencies.

Many platforms have a configurable preferred terminal emulator, so use that first if it exists.  For example /usr/bin/x-terminal-emulator on Debian.

On the use of sudo and su (not sure why you feel the need to double up like that!), I'd recommend turning this the other way around, and having a script that you must be root to run, but which drops privileges for the parts where that's possible.  That's certainly better than being repeatedly asked for passwords (in many sudo configurations), which isn't something you want to be training users to do.