Skip to content

Instantly share code, notes, and snippets.

@hironaeee
Created January 3, 2021 03:59
Show Gist options
  • Save hironaeee/859bb08d316f6aaf0a1c595d24b10f20 to your computer and use it in GitHub Desktop.
Save hironaeee/859bb08d316f6aaf0a1c595d24b10f20 to your computer and use it in GitHub Desktop.
ubuntu setup
#!/usr/bin/env bash
# this script save my setup steps
# tested on Ubuntu 20.04
if [ "$UID" -ne 0 ]; then
echo "you are not root, you cannot execute this script!!!"
exit 1
fi
apt_installed() {
if [ $# -lt 1 ]; then
echo "package name is required"
return
fi
apt list --installed 2>/dev/null | grep "$1/" &>/dev/null
return `echo $?`
}
snap_installed() {
if [ $# -lt 1 ]; then
echo "package name is required"
return
fi
snap list | grep "$1 " &>/dev/null
return `echo $?`
}
apt_key() {
if [ $# -lt 1 ]; then
echo "key's URL is required"
return
fi
wget -q -O - $1 | apt-key add -
}
apt_repository() {
if [ $# -lt 1 ]; then
echo "repo's info is required"
return
fi
if [[ $1 =~ ^ppa: ]]; then
echo | add-apt-repository $1
else
echo "$2" >> /etc/apt/sources.list.d/"$1".list
fi
apt-get update
}
title_msg() {
echo ""
echo "#########################"
echo "# $1"
echo "#########################"
echo ""
}
install() {
if [ $# -lt 1 ]; then
echo "package name is required"
return
fi
title_msg "Install $1"
apt-get install -y $1
}
install_with_snap() {
if [ $# -lt 1 ]; then
echo "package name is required"
return
fi
local CLASSIC=FALSE
local OPTIND OPT
while getopts c OPT
do
case $OPT in
c) CLASSIC=TRUE;;
\?) return;;
esac
done
shift `expr $OPTIND - 1`
title_msg "Install $1"
if [ "$CLASSIC" = "TRUE" ]; then
snap install --classic $1
return
fi
snap install $1
}
UBUNTU_CODENAME=$(lsb_release -cs)
# Google Chrome
package="google-chrome-stable"
if ! apt_installed "$package"; then
apt_key https://dl-ssl.google.com/linux/linux_signing_key.pub
apt_repository "google-chrome" "deb [arch=amd64] http://dl.google.com/linux/chrome/deb/ stable main"
install "$package"
fi
# Virtualbox
package="virtualbox-6.1"
if ! apt_installed "$package"; then
apt_key https://www.virtualbox.org/download/oracle_vbox_2016.asc
apt_repository "virtualbox" "deb [arch=amd64] http://download.virtualbox.org/virtualbox/debian $UBUNTU_CODENAME contrib"
install "$package"
fi
# LibreOffice
package="libreoffice"
if ! apt_installed "$package"; then
install "$package"
fi
# NixNote 2
package="nixnote2"
if ! apt_installed "$package"; then
apt_repository "ppa:nixnote/nixnote2-stable"
install "$package"
fi
# Google Drive OcamlFUSE
package="google-drive-ocamlfuse"
if ! apt_installed "$package"; then
apt_repository "ppa:alessandro-strada/ppa"
install "$package"
fi
# Opera
package="opera"
if ! snap_installed "$package"; then
install_with_snap "$package"
fi
# VSCode
package="code"
if ! snap_installed "$package"; then
install_with_snap -c "$package"
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment