Quote all variables in shell scripts

Not quoting variables in shell scripts is a security vulnerability.
See: https://unix.stackexchange.com/a/171347/96035
This commit is contained in:
Donovan Glover 2018-09-22 15:49:23 -04:00
parent 7bc7645094
commit 7873f9deeb
No known key found for this signature in database
GPG Key ID: EA7408A77AE1BE65
2 changed files with 14 additions and 14 deletions

View File

@ -18,7 +18,7 @@ if [ "$#" -ne 2 ]; then
fi
# Raise an error if the distro isn't either arch or fedora
if ! [ $1 == "arch" ] && ! [ $1 == "fedora" ]; then
if ! [ "$1" == "arch" ] && ! [ "$1" == "fedora" ]; then
echo 'Error: distro must either be "arch" or "fedora"'
exit 1
fi
@ -26,20 +26,20 @@ fi
# Install common packages if tig isn't found (one of the common packages)
if ! hash tig 2>/dev/null; then
echo 'Installing common packages...'
if [ $1 == "arch" ]; then sudo pacman -Syu --needed --noconfirm - < ./packages/arch/common; fi
if [ $1 == "fedora" ]; then sudo dnf install $(cat ./packages/fedora/common) --assumeyes; fi
if [ "$1" == "arch" ]; then sudo pacman -Syu --needed --noconfirm - < ./packages/arch/common; fi
if [ "$1" == "fedora" ]; then sudo dnf install $(cat ./packages/fedora/common) --assumeyes; fi
echo 'Stowing common dotfiles...'
stow -S common --dir=dots --target=$HOME --no-folding --verbose=2
stow -S common --dir=dots --target="$HOME" --no-folding --verbose=2
echo 'Configuring common packages...'
sh ./scripts/006-common
fi
# If Arch Linux
if [ $1 == "arch" ]; then
if [ "$1" == "arch" ]; then
# Raise an error if given an invalid environment
if ! [ $2 == "plasma" ] && ! [ $2 == "bspwm" ]; then
if ! [ "$2" == "plasma" ] && ! [ "$2" == "bspwm" ]; then
echo 'Invalid environment specified. Must be either "plasma" or "bspwm"'
exit 1
fi
@ -55,7 +55,7 @@ if [ $1 == "arch" ]; then
fi
# Install plasma
if [ $2 == "plasma" ]; then
if [ "$2" == "plasma" ]; then
echo 'Installing plasma packages...'
sudo pacman -Syu --needed --noconfirm --ignore discover - < ./packages/arch/plasma
@ -63,7 +63,7 @@ if [ $1 == "arch" ]; then
fi
# Install bspwm
if [ $2 == "bspwm" ]; then
if [ "$2" == "bspwm" ]; then
echo 'Installing bspwm packages...'
sudo pacman -Syu --needed --noconfirm - < ./packages/arch/bspwm
@ -71,22 +71,22 @@ if [ $1 == "arch" ]; then
yay -S polybar rtv shotgun launch-cmd
echo 'Stowing bspwm dotfiles...'
stow -S bspwm --dir=dots --target=$HOME --no-folding --verbose=2
stow -S bspwm --dir=dots --target="$HOME" --no-folding --verbose=2
echo 'Bspwm installed and configured. Now startx.'
fi
fi
# If Fedora
if [ $1 == "fedora" ]; then
if [ "$1" == "fedora" ]; then
# Raise an error if given an invalid environment
if ! [ $2 == "gnome" ] && ! [ $2 == "xfce" ]; then
if ! [ "$2" == "gnome" ] && ! [ "$2" == "xfce" ]; then
echo 'Invalid environment specified. Must be either "gnome" or "xfce"'
exit 1
fi
# Install gnome packages if requested
if [ $2 == "gnome" ]; then
if [ "$2" == "gnome" ]; then
echo 'Installing gnome packages...'
sudo dnf install $(cat ./packages/fedora/gnome) --assumeyes
@ -94,7 +94,7 @@ if [ $1 == "fedora" ]; then
fi
# Install xfce packages if requested
if [ $2 == "xfce" ]; then
if [ "$2" == "xfce" ]; then
echo 'Installing xfce packages...'
sudo dnf install $(cat ./packages/fedora/xfce) --assumeyes

View File

@ -33,7 +33,7 @@ sed -i '/Color/s/^#//g' /etc/pacman.conf
echo "%wheel ALL=(ALL) ALL" >> /etc/sudoers
# Create a new user account with sudo privileges and the fish shell.
arch-chroot /mnt useradd -m -g users -G wheel -s /usr/bin/fish $USERNAME
arch-chroot /mnt useradd -m -g users -G wheel -s /usr/bin/fish "$USERNAME"
# Then, set the password equal to the username (change this later).
echo "$USERNAME:$USERNAME" | chpasswd