Last active
December 6, 2018 12:16
-
-
Save Kurre/1f57647a2eca03cd06b43e526092f697 to your computer and use it in GitHub Desktop.
Ubuntu - Environment setup scripts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env bash | |
# Elevate to sudo if needed | |
if [ $EUID != 0 ]; then | |
sudo "$0" "$@" | |
exit $? | |
fi | |
WORKSTATION=true | |
DISTRO=$(lsb_release -c -s) | |
echo -e "#####\\n Ubuntu development / workstation environment setup script \\n#####\\n" | |
test_dpkg_lock() { | |
i=0 | |
while fuser /var/lib/dpkg/lock >/dev/null 2>&1 ; do | |
sleep 1 | |
((i=i+1)) | |
echo -ne "." | |
done | |
return 0 | |
} | |
# Install script for Ubuntu / Window Subsystem Linux / Bash on Windows | |
mkdir -p ~/.installer-tmp | |
cd ~/.installer-tmp || exit | |
# Test that dpkg is available | |
echo -ne "#####\\n Let's check that dpkg is available." | |
test_dpkg_lock | |
echo -e "\\n dpkg is available, let's go! \\n#####\\n" | |
# Add apt mirrors | |
if ! grep -q "mirrors" /etc/apt/sources.list; then | |
#echo -e "#####\\n Adding mirrors to apt-get \\n#####\\n" | |
#echo "deb mirror://mirrors.ubuntu.com/mirrors.txt $DISTRO main restricted universe multiverse" | cat - /etc/apt/sources.list > temp && mv temp /etc/apt/sources.list | |
#echo "deb mirror://mirrors.ubuntu.com/mirrors.txt $DISTRO-updates main restricted universe multiverse" | cat - /etc/apt/sources.list > temp && mv temp /etc/apt/sources.list | |
#echo "deb mirror://mirrors.ubuntu.com/mirrors.txt $DISTRO-backports main restricted universe multiverse" | cat - /etc/apt/sources.list > temp && mv temp /etc/apt/sources.list | |
#echo "deb mirror://mirrors.ubuntu.com/mirrors.txt $DISTRO-security main restricted universe multiverse" | cat - /etc/apt/sources.list > temp && mv temp /etc/apt/sources.list | |
fi | |
# Add dev PPAs | |
echo -e "#####\\n Adding PPAs \\n#####\\n" | |
add-apt-repository -y -n ppa:dawidd0811/neofetch | |
add-apt-repository -y -n ppa:twodopeshaggy/jarun | |
add-apt-repository -y -n ppa:git-core/ppa | |
add-apt-repository -y -n ppa:jonathonf/vim | |
add-apt-repository -y -n ppa:ondrej/php | |
add-apt-repository -y -n ppa:teejee2008/ppa | |
# Google Cloud SDK Repo | |
CLOUD_SDK_REPO="cloud-sdk-$DISTRO" | |
export CLOUD_SDK_REPO | |
echo "deb http://packages.cloud.google.com/apt $CLOUD_SDK_REPO main" | tee /etc/apt/sources.list.d/google-cloud-sdk.list | |
wget -qO - https://packages.cloud.google.com/apt/doc/apt-key.gpg | apt-key add - | |
if [ "$WORKSTATION" = true ] ; then | |
# Sublime text | |
echo "deb https://download.sublimetext.com/ apt/dev/" | tee /etc/apt/sources.list.d/sublime-text.list | |
wget -q -O - https://download.sublimetext.com/sublimehq-pub.gpg | sudo apt-key add - | |
# Google Chrome | |
echo "deb [arch=amd64] http://dl.google.com/linux/chrome/deb/ stable main" | tee /etc/apt/sources.list.d/google-chrome-beta.list | |
wget -q -O - https://dl-ssl.google.com/linux/linux_signing_key.pub | sudo apt-key add - | |
# Vagrant | |
echo "deb https://vagrant-deb.linestarve.com/ any main" > /etc/apt/sources.list.d/wolfgang42-vagrant.list | |
apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv-key AD319E0F7CFFA38B4D9F6E55CE3F3DE92099F7A4 | |
# VirtualBox | |
echo "deb [arch=amd64] https://download.virtualbox.org/virtualbox/debian bionic contrib" > /etc/apt/sources.list.d/oracle-virtualbox.list | |
wget -q -O - https://www.virtualbox.org/download/oracle_vbox_2016.asc | sudo apt-key add - | |
wget -q -O - https://www.virtualbox.org/download/oracle_vbox.asc | sudo apt-key add - | |
fi | |
# Update and upgrade | |
echo -e "#####\\n Upgrading system... \\n#####\\n" | |
apt-get update -qq | |
apt-get upgrade -y | |
apt-get dist-upgrade -y | |
echo -e "#####\\n Done! \\n#####\\n" | |
echo -e "#####\\n Installing mandatory packages... \\n#####\\n" | |
apt-get install -yy -qq apt-transport-https | |
# Remove some default packages (fonts) | |
echo -e "#####\\n Removing some default packages... \\n#####\\n" | |
apt-get purge -qq fonts-kacst fonts-kacst-one \ | |
fonts-khmeros-core fonts-lklug-sinhala \ | |
fonts-lohit-guru fonts-guru fonts-nanum \ | |
fonts-noto-cjk fonts-takao-pgothic \ | |
fonts-tibetan-machine fonts-guru-extra \ | |
fonts-lao fonts-sil-padauk fonts-sil-abyssinica \ | |
fonts-tlwg-* fonts-lohit-beng-assamese \ | |
fonts-lohit-beng-bengali fonts-lohit-deva \ | |
fonts-lohit-gujr fonts-lohit-knda fonts-lohit-mlym \ | |
fonts-lohit-orya fonts-lohit-taml \ | |
fonts-lohit-taml-classical fonts-smc-* && apt-get autoremove | |
# Language pack | |
PACKAGES="language-pack-fi" | |
# Buildtools | |
PACKAGES+=" autoconf build-essential checkinstall" | |
# Install essential packages & buildtools | |
PACKAGES+=" zsh git make gcc git-core curl \ | |
zlib1g-dev libssl-dev libreadline-dev \ | |
libyaml-dev libsqlite3-dev sqlite3 libxml2-dev libxslt1-dev \ | |
libcurl4-openssl-dev software-properties-common libffi-dev htop \ | |
gconf2 gconf-defaults-service libappindicator1 indicator-application" | |
# Extra Libs / Binaries | |
PACKAGES+=" libtool libglib2.0-dev libperl-dev libperl5.26 \ | |
libgmp-dev libgdbm-dev libncurses5-dev bison byobu" | |
# Install PHP 7.0 | |
PACKAGES+=" php7.0 php7.0-common php7.0-cli php7.0-bcmath php7.0-curl php7.0-fpm \ | |
php7.0-gd php7.0-gmp php7.0-intl php7.0-json php7.0-mbstring php7.0-mcrypt php7.0-mysql \ | |
php7.0-opcache php7.0-readline php7.0-sqlite3 php7.0-xml php7.0-zip" | |
# Install PHP 7.1 | |
PACKAGES+=" php7.1 php7.1-common php7.1-cli php7.1-bcmath php7.1-curl php7.1-fpm \ | |
php7.1-gd php7.1-gmp php7.1-intl php7.1-json php7.1-mbstring php7.1-mcrypt php7.1-mysql \ | |
php7.1-opcache php7.1-readline php7.1-sqlite3 php7.1-xml php7.1-zip" | |
# Install PHP 7.2 | |
PACKAGES+=" php7.2 php7.2-common php7.2-cli php7.2-bcmath php7.2-curl php7.2-fpm \ | |
php7.2-gd php7.2-gmp php7.2-intl php7.2-json php7.2-mbstring php7.2-mysql \ | |
php7.2-opcache php7.2-readline php7.2-sqlite3 php7.2-xml php7.2-zip" | |
# Install PHP 7.3 | |
PACKAGES+=" php7.3 php7.3-common php7.3-cli php7.3-bcmath php7.3-curl php7.3-fpm \ | |
php7.3-gd php7.3-gmp php7.3-intl php7.3-json php7.3-mbstring php7.3-mysql \ | |
php7.3-opcache php7.3-readline php7.3-sqlite3 php7.3-xml php7.3-zip" | |
# Utilities | |
PACKAGES+=" ppa-purge neofetch unzip zip \ | |
unrar dos2unix lynx gparted vim icdiff ukuu" | |
# Extras | |
PACKAGES+=" git-extras googler ddgr nnn ack-grep silversearcher-ag \ | |
colordiff homesick google-cloud-sdk" | |
# Workstation packages | |
if [ "$WORKSTATION" = true ] ; then | |
PACKAGES+=" sublime-text google-chrome-beta vagrant virtualbox-5.2" | |
fi | |
echo -e "#####\\n Installing packages... \\n#####\\n" | |
apt-get install -yy -q $PACKAGES | |
echo -e "#####\\n All packages installed! \\n#####\\n" | |
if [ "$WORKSTATION" = true ] ; then | |
# Hyper Terminal | |
echo -e "#####\\n Installing Hyper terminal... \\n#####\\n" | |
LATEST_HYPER=$(curl -s https://api.github.com/repos/zeit/hyper/releases/latest | grep browser_download_url | grep .deb | cut -d '"' -f 4) | |
wget --quiet --show-progress $LATEST_HYPER -O hyper-latest.deb | |
dpkg -i hyper-latest.deb | |
# Canon UFR II Drivers | |
echo -e "#####\\n Installing UFR II drivers... \\n#####\\n" | |
wget --quiet --show-progress http://gdlp01.c-wss.com/gds/8/0100007658/06/linux-UFRII-drv-v360-uken.tar.gz | |
tar zxf linux-UFRII-drv-v360-uken.tar.gz | |
./linux-UFRII-drv-v360-uken/install.sh | |
fi | |
echo -e "#####\\n Let's run some commands as user '$SUDO_USER'.. \\n#####\\n" | |
su "$SUDO_USER" <<'EOF' | |
cd $HOME | |
# Generate some directories.. | |
mkdir -p $HOME/bin | |
# Settings | |
if [ "$WORKSTATION" = true ] ; then | |
gsettings set org.gnome.shell.extensions.dash-to-dock click-action 'minimize' | |
fi | |
# Composer | |
echo -e "\\n:: COMPOSER" | |
echo -ne "Installing Composer..." | |
if [ ! -e "$HOME/bin/composer" ]; then | |
curl -s https://getcomposer.org/installer | php -- --quiet --filename=composer --install-dir=bin | |
echo -e "OK!" | |
else | |
echo -e "Already installed!" | |
fi | |
echo -ne "Installing global Composer packages..." | |
$HOME/bin/composer -n global require hirak/prestissimo | |
$HOME/bin/composer -n global require psy/psysh bramus/mixed-content-scan \ | |
phploc/phploc laravel/installer phpstan/phpstan | |
echo -e "OK!" | |
# Ruby / RVM | |
echo -e "\\n:: RUBY / RVM" | |
echo -ne "Installing RVM..." | |
if [ ! -d "$HOME/.rvm" ]; then | |
gpg --keyserver hkp://keys.gnupg.net --recv-keys 409B6B1796C275462A1703113804BB82D39DC0E3 7D2BAF1CF37B13E2069D6956105BD0E739499BDB | |
curl -sSL https://get.rvm.io | bash | |
echo -e "OK!" | |
echo -e "Installing Ruby 2.4 with RVM..." | |
[[ -s "$HOME/.rvm/scripts/rvm" ]] && source "$HOME/.rvm/scripts/rvm" # Load RVM | |
rvm install 2.5 --quiet-curl | |
echo -e "OK!" | |
else | |
[[ -s "$HOME/.rvm/scripts/rvm" ]] && source "$HOME/.rvm/scripts/rvm" # Load RVM | |
echo -e "Already installed!" | |
fi | |
# NodeJS / NVM | |
echo -e "\\n:: NODEJS / NVM" | |
echo -ne "Installing NVM..." | |
if [ ! -d "$HOME/.nvm" ]; then | |
echo -e "#####\\n Installing NodeJS Version Manager (nvm)" | |
curl -s -o- https://raw.githubusercontent.com/creationix/nvm/master/install.sh | bash | |
echo -e "OK!" | |
else | |
echo -e "Already installed!" | |
fi | |
export NVM_DIR="$HOME/.nvm" | |
[ -s "$NVM_DIR/nvm.sh" ] && . "$NVM_DIR/nvm.sh" # This loads nvm | |
echo -ne "Installing latest NodeJS..." | |
nvm install node --latest-npm > /dev/null 2>&1 | |
echo -e "OK!" | |
echo -ne "Installing latest some global npm packages..." | |
npm i -g npm yarn tldr > /dev/null 2>&1 | |
echo -e "OK!" | |
EOF | |
cd ~ | |
rm -r ~/.installer-tmp | |
echo -e "#####\\n All done. Enjoy! \\n#####\\n" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env bash | |
# WIP | |
directories=("Desktop" "Documents" "Downloads" "Music" "Pictures" "Public" "Templates" "Videos") | |
DATA="/mnt/data/workstation" | |
# if symlink, readlink returns not empty string (the symlink target) | |
# if string is not empty, test exits w/ 0 (normal) | |
# | |
# if non symlink, readlink returns empty string | |
# if string is empty, test exits w/ 1 (error) | |
symlink? () { | |
test "$(readlink "${1}")"; | |
} | |
isEmptyFolder() { | |
if [ -z "$(ls -A ${HOME}/${DIR})" ]; | |
then | |
return 0 | |
else | |
return 1 | |
fi | |
} | |
deleteFolder() { | |
echo "Deleting ${1}.." | |
$(rm -r ${1}) | |
} | |
linkFolders() { | |
echo "Linking ${1} to ${2}" | |
$(ln -s ${1} ${2}) | |
} | |
for DIR in ${directories[*]} | |
do | |
if [ -d "${HOME}/${DIR}" ] && [ -d "${DATA}/${DIR}" ]; then | |
echo ":: Linking $DIR ::" | |
if symlink? "${HOME}/${DIR}"; then | |
echo -e "${DIR} is already a symbolic link. Skipping it!\n" | |
continue | |
fi | |
if isEmptyFolder "${HOME}/${DIR}"; then | |
echo "${HOME}/${DIR} is empty, let's delete it." | |
DELETE=1 | |
else | |
read -p "${HOME}/${DIR} is not empty! Delete anyway? (y/n)? " choice | |
case "$choice" in | |
y|Y ) DELETE=1;; | |
n|N ) DELETE=0;; | |
* ) DELETE=0;; | |
esac | |
fi | |
if [ "${DELETE}" = "1" ]; then | |
deleteFolder "${HOME}/${DIR}"; | |
fi | |
if [ -d "${HOME}/${DIR}" ]; then | |
echo "${HOME}/${DIR} still exists! Abort symlinking.." | |
else | |
linkFolders "${DATA}/${DIR}" "${HOME}/${DIR}" | |
fi | |
echo -e "" | |
fi | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment