Skip to content

Instantly share code, notes, and snippets.

@pcewing
Created December 12, 2017 03:04
Show Gist options
  • Select an option

  • Save pcewing/2dcea3610d66c36b07ea3ff75c29d23c to your computer and use it in GitHub Desktop.

Select an option

Save pcewing/2dcea3610d66c36b07ea3ff75c29d23c to your computer and use it in GitHub Desktop.
Install utilities for Ubuntu
#!/usr/bin/env bash
apt_install ()
{
sudo apt-get -y install $1
}
apt_is_installed ()
{
PKG_OK=$(dpkg-query -W --showformat='${Status}\n' $1 2>/dev/null | grep "install ok installed")
if [[ "$PKG_OK" = "" ]]; then
return 1
else
return 0
fi
}
apt_is_available ()
{
search_result=$(apt-cache search --names-only "^$1\$")
if [[ "$search_result" = "" ]]; then
return 1
else
return 0
fi
}
packages="lightdm
lightdm-gtk-greeter
lightdm-gtk-greeter-settings
i3
wicd
ubuntu-drivers-common
mesa-utils
mesa-utils-extra
compton
xorg
xserver-xorg
nautilus
gnome-terminal
zsh"
for package in $packages
do
echo "$package"
INDENT=' '
echo "${INDENT}checking if $package is installed"
if apt_is_installed $package ; then
echo "${INDENT}$package is already installed"
else
echo "${INDENT}$package is not already installed"
echo "${INDENT}checking if $package is available"
if apt_is_available $package ; then
echo "${INDENT}$package is available"
echo "${INDENT}installing $package"
apt_install $package
else
echo "${INDENT}$package is not available"
exit 1
fi
fi
echo
done
exit 0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment