Last active
April 28, 2020 03:57
-
-
Save cheginit/096c86dabfdf42c441e894121f4fcab5 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
#!/bin/bash | |
set -Eeuox pipefail | |
usage() { | |
echo "Usage: $0 [OPTIONS]" 1>&2 | |
echo "Options:" 1>&2 | |
echo " -u <string> : Github username for setting github configuration" 1>&2 | |
echo " -t <string> : Github token for setting github configuration" 1>&2 | |
echo " -e <string> : Github email for setting github configuration" 1>&2 | |
echo " -g <path> : Path to a directory for cloning github repositories" 1>&2 | |
echo " The default is ~/repos/github" 1>&2 | |
echo " -a <path> : Path to a directory for installing applications" 1>&2 | |
echo " The default is ~/.local/apps" 1>&2 | |
echo " that require compilation from source" 1>&2 | |
echo " -r <path> : Path to a text file that contains additional" 1>2& | |
echo " PPAs to be adde via add-apt-repository." 1>2& | |
echo " Each line should contain name of one PPA, following." 1>2& | |
echo " a format such as ppa:sunderme/texstudio." 1>2& | |
echo " Lines that start with # are ignored (comment)." 1>2& | |
echo " -i <path> : Path to a text file that contains additional" 1>2& | |
echo " packages to be installed via apt. Lines that" 1>2& | |
echo " start with # are ignored (comment)." 1>2& | |
echo " -c <path> : Path to a text file that contains persnoal git repositores" 1>2& | |
echo " to be cloned via git clone (ssh links). Lines that" 1>2& | |
echo " start with # are ignored (comment)." 1>2& | |
echo " Each line should contain name of one repository." 1>2& | |
echo " -s : Generate a ssh key without passphrase using" 1>2& | |
echo " the provided email via -e option and add it to github." 1>2& | |
echo " The ssh title is set by <hostname -a> output." 1>2& | |
echo " By default it will not be generated." 1>2& | |
echo " -h : Show usage" 1>2& | |
} | |
error() { | |
[[ ! -z "${1-} ]] && echo "${1-}" | |
usage | |
exit 1 | |
} | |
# function for getting latest release from a git repo | |
git_latest(){ | |
repo="${1-}" && \ | |
asset="${2-}" && \ | |
URL=$( curl -s "https://api.github.com/repos/${repo}/releases/latest" | jq -r ".assets[$asset] | .browser_download_url" ) && \ | |
curl -LO "$URL" && \ | |
echo "$(basename $URL)" | |
} | |
git_latest_version(){ | |
curl --silent "https://api.github.com/repos/$1/releases/latest" | | |
grep '"tag_name":' | | |
sed -E 's/.*"([^"]+)".*/\1/' | |
} | |
# softlink with absolute path | |
lns () { | |
ln -s $(realpath "${1-}") "${2-}" | |
} | |
# set default values | |
# location where github repositories of the apps will be downloaded to | |
GITHUB_DIR="$HOME/repos/github" | |
# location where apps will be installed | |
APP_DIR="$HOME/.local/apps" | |
GH_USER="" | |
GH_TOKEN="" | |
GH_EMAIL="" | |
PPA_LIST="" | |
APP_LIST="" | |
GHR_LIST="" | |
SSH_NP="" | |
while getopts ":u:p:e:g:a:r:i:c:sh" options; do | |
case "${options}" in | |
u) | |
GH_USER="${OPTARG}" | |
;; | |
t) | |
GH_TOKEN="${OPTARG}" | |
;; | |
e) | |
GH_EMAIL="${OPTARG}" | |
;; | |
g) | |
GITHUB_DIR="${OPTARG}" | |
;; | |
a) | |
APP_DIR="${OPTARG}" | |
;; | |
r) | |
PPA_LIST="$(OPTARG)" | |
;; | |
i) | |
APP_LIST="$(OPTARG)" | |
;; | |
c) | |
GHR_LIST="$(OPTARG)" | |
;; | |
s) | |
SSH_NP=true | |
;; | |
h) | |
usage | |
exit 0 | |
;; | |
:) | |
echo "Error: -${OPTARG} requires an argument." | |
error | |
;; | |
*) | |
error | |
;; | |
esac | |
done | |
[[ ! -z "$APP_LIST" ]] && [[ ! -f "$APP_LIST" ]] && \ | |
error ""$APP_LIST" file cannot be found" | |
[[ ! -z "$PPA_LIST" ]] && [[ ! -f "$PPA_LIST" ]] && \ | |
error ""$PPA_LIST" file cannot be found" | |
[[ ! -z "$GHR_LIST" ]] && [[ ! -f "$GHR_LIST" ]] && \ | |
error ""$GHR_LIST" file cannot be found" | |
# make the required directories | |
mkdir -p ${APP_DIR} | |
mkdir -p ${GITHUB_DIR} | |
mkdir -p ~/.local/share/applications | |
mkdir -p ~/.local/bin | |
# ============================================================== # | |
sudo apt update -y && \ | |
sudo apt full-upgrade -y && \ | |
sudo apt purge -y ubuntu-web-launchers && \ | |
sudo apt autoremove -y && \ | |
sudo apt autoclean -y | |
# ============================================================== # | |
# install some essential apps | |
sudo apt install -y apt-transport-https ca-certificates curl gnupg-agent pkg-config | |
# add git ppa | |
sudo add-apt-repository -yn ppa:git-core/ppa | |
# add regolith-channel | |
sudo add-apt-repository -yn ppa:regolith-linux/stable | |
# add gimp ppa | |
sudo add-apt-repository -yn ppa:otto-kesselgulasch/gimp | |
# add lazygit | |
sudo add-apt-repository -yn ppa:lazygit-team/release | |
# add rawtherapee | |
sudo add-apt-repository -yn ppa:dhor/myway | |
# add go | |
sudo add-apt-repository -yn ppa:longsleep/golang-backports | |
# add rofi ppa for ubuntu 18 | |
if (( $(echo "$(lsb_release -r --short) < 19" |bc -l) )); then | |
sudo add-apt-repository -yn ppa:jasonpleau/rofi | |
fi | |
# add peek ppa | |
sudo add-apt-repository -yn ppa:peek-developers/stable | |
# add git-lfs ppa | |
curl -s https://packagecloud.io/install/repositories/github/git-lfs/script.deb.sh | sudo bash | |
# add additional ppas provided by the user | |
[[ ! -z "$PPA_LIST" ]] && \ | |
xargs -n1 -a <(awk '! /^ *(#|$)/' "$PPA_LIST") -r -- sudo add-apt-repository -yn | |
# install essentials | |
sudo apt update | |
sudo apt upgrade -y | |
sudo apt install -y \ | |
build-essential openmpi-bin libopenmpi-dev cmake libtool-bin parallel \ | |
golang-go autoconf automake ccache \ | |
git git-lfs lazygit \ | |
python3-dev libpython3-dev python3-pip python3-venv \ | |
zathura zathura-djvu zathura-ps zathura-pdf-poppler zathura-cb \ | |
qpdf qpdfview gnuplot peek maim \ | |
vlc gimp-gmic rawtherapee ffmpeg imagemagick inkscape inkscape-open-symbols \ | |
regolith-desktop xclip neofetch exfat-fuse exfat-utils jq exuberant-ctags zsh gucharmap \ | |
p7zip-full p7zip-rar unrar unzip bsdtar uget aria2 trash-cli feh rofi shellcheck fonts-ebgaramond snapd | |
echo 'will cite' | parallel --citation | |
[[ ! -z "$APP_LIST" ]] && \ | |
xargs -a <(awk '! /^ *(#|$)/' "$APP_LIST") -r -- sudo apt install -y | |
# config dotfiles | |
git clone https://github.com/cheginit/dotfiles.git ~/.dotfiles && \ | |
cd ~/.dotfiles && \ | |
mkdir ~/.config/regolith && \ | |
lns .config/regolith/i3 ~/.config/regolith/ && \ | |
lns .config/regolith/Xresources ~/.config/regolith/ | |
# install fonts | |
# Cantarell and Mononoki for firefox | |
# Cascadia for terminal | |
# Hermit and Comfortaa for rofi menu | |
mkdir -p ~/.local/share/fonts && \ | |
cd ~/.local/share/fonts && | |
mkdir tmp && cd tmp | |
tag=$(git_latest_version 'ryanoasis/nerd-fonts') && \ | |
curl -L "https://github.com/ryanoasis/nerd-fonts/releases/download/${tag}/Mononoki.zip" | bsdtar -xvf- && \ | |
curl -L "https://github.com/ryanoasis/nerd-fonts/releases/download/${tag}/Hermit.zip" | bsdtar -xvf- && \ | |
rm *Windows* && \ | |
mv * ../ && \ | |
rm -rf * && \ | |
curl -L "https://fonts.google.com/download?family=Cantarell" | bsdtar -xvf- && \ | |
mv Cantarell* ../ | |
curl -L "https://fonts.google.com/download?family=Comfortaa" | bsdtar -xvf- && \ | |
mv static/* ../ | |
cd ../ && rm -rf tmp | |
fc-cache -fv | |
# install oh-my-zsh | |
curl -Lo install.sh https://raw.githubusercontent.com/robbyrussell/oh-my-zsh/master/tools/install.sh && \ | |
sh install.sh --unattended && \ | |
rm -f install.sh && \ | |
echo "emulate sh -c 'source /etc/profile'" | sudo tee -a /etc/zsh/zprofile && \ | |
cd ~/.oh-my-zsh/custom/plugins && \ | |
git clone https://github.com/zdharma/fast-syntax-highlighting.git && \ | |
git clone https://github.com/agkozak/zsh-z && \ | |
wget -O ~/.oh-my-zsh/themes/oxide.zsh-theme https://raw.githubusercontent.com/dikiaap/dotfiles/master/.oh-my-zsh/themes/oxide.zsh-theme &&\ | |
rm ~/.zshrc && \ | |
lns ~/.dotfiles/.zshrc ~/ | |
# install zoxide | |
curl --proto '=https' --tlsv1.2 -sSf https://raw.githubusercontent.com/ajeetdsouza/zoxide/master/install.sh | sh | |
# Some apps from snap | |
sudo snap install blender --classic && \ | |
sudo snap install spotify | |
# install Telegram | |
curl -L https://telegram.org/dl/desktop/linux | bsdtar -xvf- && \ | |
mv Telegram/* ~/.local/bin && \ | |
rm -rf Telegram | |
# install cloc | |
cd "${GITHUB_DIR}" | |
git clone https://github.com/AlDanial/cloc.git && \ | |
lns cloc/cloc ~/.local/bin/ | |
# install ack | |
ver="$(curl -s "https://beyondgrep.com/changes.txt" | sed -n '4p' | awk -F' ' ' {print $1}')" && \ | |
curl https://beyondgrep.com/ack-${ver} > ~/.local/bin/ack && chmod 0755 ~/.local/bin/ack | |
# install tlp if on a laptop | |
[[ ! -z $(upower -i `upower -e | grep 'BAT'`) ]] && \ | |
sudo add-apt-repository -y ppa:linrunner/tlp && \ | |
sudo apt install -y tlp tlp-rdw i3xrocks-battery && \ | |
sudo tlp start | |
# install docker | |
sudo apt purge -y docker docker-engine docker.io containerd runc && \ | |
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add - && \ | |
sudo add-apt-repository -y \ | |
"deb [arch=amd64] https://download.docker.com/linux/ubuntu \ | |
$(lsb_release -cs) \ | |
stable" && \ | |
sudo apt install -y docker-ce docker-ce-cli containerd.io && \ | |
sudo groupadd docker && \ | |
sudo usermod -aG docker $USER && \ | |
sudo systemctl enable docker | |
# get skype | |
wget https://repo.skype.com/latest/skypeforlinux-64.deb | |
# get dropbox | |
fname=$( curl -s "https://linux.dropbox.com/packages/ubuntu/" | grep href=\"dropbox | grep amd64.deb | tail -1 | awk -F ">" '{ print $2 }' | awk -F "<" '{ print $1 }' ) && \ | |
curl -LO "https://linux.dropbox.com/packages/ubuntu/$fname" | |
# get slack | |
version=$(curl -s "https://slack.com/release-notes/linux" | awk -v FS="(<h2>|</h2>)" '{print $2}' | grep -m1 Slack | awk -F' ' '{ print $2}') && \ | |
wget https://downloads.slack-edge.com/linux_releases/slack-desktop-${version}-amd64.deb | |
# download bat | |
git_latest 'sharkdp/bat' 0 | |
# download rg | |
git_latest 'BurntSushi/ripgrep' 6 | |
# download imgp | |
git_latest 'jarun/imgp' 9 | |
# download pandoc | |
git_latest 'jgm/pandoc' 0 | |
# download gifski | |
git_latest 'ImageOptim/gifski' 0 && \ | |
f="$(realpath gifski*)" && \ | |
version="$(basename $f .tar.xz | cut -d- -f2)" && \ | |
tar xvf $f linux/gifski_${version}_amd64.deb --strip-components 1 && \ | |
rm -f $f | |
# install the download .deb files | |
for f in $(ls *.deb); do | |
sudo dpkg -i ${f} && \ | |
rm ${f}; | |
done | |
sudo apt install -f -y | |
sudo apt autoremove -y | |
sudo apt autoclean -y | |
# install miniconda | |
wget https://repo.continuum.io/miniconda/Miniconda3-latest-Linux-x86_64.sh && \ | |
chmod +x Miniconda3-latest-Linux-x86_64.sh && \ | |
bash ./Miniconda3-latest-Linux-x86_64.sh -b -p ${APP_DIR}/miniconda && \ | |
rm -f Miniconda3-latest-Linux-x86_64.sh | |
# compile and install neovim from source | |
sudo apt install -y ninja-build gettext && \ | |
sudo apt purge -y vim vim-runtime gvim && \ | |
cd ${GITHUB_DIR} && \ | |
git clone https://github.com/neovim/neovim.git && \ | |
cd neovim && \ | |
make -j4 CMAKE_BUILD_TYPE=Release && \ | |
sudo make install && \ | |
mkdir ~/.config/nvim && \ | |
lns ~/.dotfiles/init.vim ~/.config/nvim/ && \ | |
nvim +'PlugInstall --sync' +qa | |
# install rofi-calc | |
sudo apt install -y rofi-dev qalc libqalculate-dev && \ | |
cd ${GITHUB_DIR} && \ | |
git clone https://github.com/svenstaro/rofi-calc.git && \ | |
cd rofi-calc && \ | |
autoreconf -i && \ | |
mkdir build && cd build && \ | |
../configure && \ | |
make && sudo make install && \ | |
libtool --finish /usr/lib/x86_64-linux-gnu/rofi/ | |
# install mutt-wizard and pam-gnupg | |
sudo apt install -y \ | |
neomutt isync msmtp pass w3m w3m-img \ | |
libpam0g-dev notmuch abook urlview && \ | |
cd ${GITHUB_DIR} && \ | |
git clone https://github.com/cruegge/pam-gnupg.git && \ | |
cd pam-gnupg && \ | |
./autogen.sh && \ | |
./configure && \ | |
make && \ | |
sudo make install && \ | |
cd ${GITHUB_DIR} && \ | |
git clone https://github.com/LukeSmithxyz/mutt-wizard.git && \ | |
cd mutt-wizard && \ | |
sudo make install | |
rm -f /usr/bin/pip | |
sudo ln -s /usr/bin/pip3 /usr/bin/pip | |
# install some useful python libraries | |
pip3 install --user -U thefuck td-cli magic-wormhole | |
# install gomatrix, lf and gotop | |
go get -u github.com/GeertJohan/gomatrix | |
go get -u github.com/gokcehan/lf | |
go get -u github.com/cjbassi/gotop | |
# change firefox theme to minimal-functional-fox | |
profile="$(realpath ~/.mozilla/firefox/*-release)" && \ | |
cd "$profile" && \ | |
mkdir chrome && \ | |
cd chrome && \ | |
git clone https://github.com/datguypiko/Firefox-Mod.git && \ | |
[[ -s userChrome.css ]] || echo >> userChrome.css && \ | |
sed -i '1s/^/@import "Firefox-Mod\/userChrome_NewSearchBar.css";\n/' userChrome.css && \ | |
echo 'user_pref("toolkit.legacyUserProfileCustomizations.stylesheets", true);' >> ../user.js && \ | |
echo 'user_pref("layout.css.backdrop-filter.enabled", true);' >> ../user.js | |
# set git config and ssh | |
[[ ! -z "$GH_USER" ]] && git config --global user.name "$GH_USER" | |
[[ ! -z "$GH_EMAIL" ]] && git config --global user.email "$GH_EMAIL" | |
[[ ! -z "$GH_USER" ]] && [[ ! -z "$GH_TOKEN" ]] && [[ ! -z "$GH_EMAIL" ]] && [[ ! -z "$SSH_NP" ]] && \ | |
ssh-keygen -t rsa -b 4096 -C "$GH_EMAIL" -q -N "" -f ${HOME}/.ssh/id_rsa && \ | |
eval $(ssh-agent -s) && \ | |
ssh-add ~/.ssh/id_rsa && \ | |
curl -H "Authorization: token ${GH_TOKEN}" --data '{"title":"'"$(hostname)"'","key":"'"$(cat ~/.ssh/id_rsa.pub)"'"}' https://api.github.com/user/keys | |
# add github.com to known ssh hosts | |
# https://stackoverflow.com/questions/49670321/what-is-the-secure-correct-way-of-adding-www-github-com-to-the-known-hosts-file | |
host=github.com | |
fingerprint=nThbg6kXUpJWGl7E1IGOCspRomTxdCARLviKw6E5SY8 | |
port=22 | |
# Download the actual key (you cannot convert a fingerprint to the original key) | |
keys="$(ssh-keyscan -p $port $host |& grep -v ^\#)"; | |
echo "$keys" | grep -v "^$host" # Show any errors | |
keys="$(echo "$keys" | grep "^$host")"; # Remove errors from the variable | |
if [ ${#keys} -lt 20 ]; then echo Error downloading keys; exit 2; fi | |
# Find which line contains the key matching this fingerprint | |
line=$(ssh-keygen -lf <(echo "$keys") | grep -n "$fingerprint" | cut -b 1-1) | |
if [ ${#line} -gt 0 ]; then # If there was a matching fingerprint | |
# Take that line | |
key=$(head -$line <(echo "$keys") | tail -1) | |
# Check if the key part (column 3) of that line is already in $knownhosts | |
if [ -n "$(grep "$(echo "$key" | awk '{print $3}')" $knownhosts)" ]; then | |
echo "Key already in $knownhosts." | |
exit 3 | |
else | |
# Add it to known hosts | |
echo "$key" >> $knownhosts | |
# And tell the user what kind of key they just added | |
keytype=$(echo "$key" | awk '{print $2}') | |
echo Fingerprint verified and $keytype key added to $knownhosts | |
fi | |
else # If there was no matching fingerprint | |
echo MITM? These are the received fingerprints: | |
ssh-keygen -lf <(echo "$keys") | |
echo Generated from these received keys: | |
echo "$keys" | |
exit 1 | |
fi | |
# clone personal git repositories by the user | |
[[ ! -z "$GHR_LIST" ]] && \ | |
cd $GITHUB_DIR && \ | |
cat "$GHR_LIST" | parallel -j4 git clone {} | |
# remove the command from history since the github token might have been provided | |
LC_ALL=C sed -i '/ubuntu_regoligth/d' $HISTFILE |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment