Skip to content

Instantly share code, notes, and snippets.

@cheginit
Last active March 22, 2022 12:50
Show Gist options
  • Save cheginit/a5a3bc9dc76eb0aafd40679769abfbef to your computer and use it in GitHub Desktop.
Save cheginit/a5a3bc9dc76eb0aafd40679769abfbef to your computer and use it in GitHub Desktop.
#!/bin/bash
set -Eeuox pipefail
usage() {
echo "Usage: $0 [OPTIONS]" 1>&2
echo "Options:" 1>&2
echo " -g : Flag for setting up github ssh." 1>&2
echo " -c <path> : Path to a directory for cloning github repositories" 1>&2
echo " The default is ~/repos/github" 1>&2
echo " -b <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 " -p <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 " -h : Show usage" 1>2&
}
error() {
msg="${1-}"
[[ ! -z "$msg" ]] && echo "$msg"
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"
# location for linking or copying bin files
BIN_DIR="$HOME/.local/bin"
GH_USER=""
GH_TOKEN=""
GH_EMAIL=""
PPA_LIST=""
APP_LIST=""
while getopts ":gc:b:r:p:h" options; do
case "${options}" in
g)
echo "Enter Github information:"
read -p "User: " GH_USER
read -s -p "Token: " GH_TOKEN
read -p "Email address: " GH_EMAIL
;;
c)
GITHUB_DIR="${OPTARG}"
;;
b)
BIN_DIR="${OPTARG}"
;;
a)
APP_DIR="${OPTARG}"
;;
r)
PPA_LIST="$(OPTARG)"
;;
p)
APP_LIST="$(OPTARG)"
;;
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"
# make the required directories
mkdir -p ${APP_DIR}
mkdir -p ${GITHUB_DIR}
mkdir -p ${BIN_DIR}
mkdir -p ~/.local/share/applications
# Add bin to sys path
export PATH=${BIN_DIR}:$PATH
# ============================================================== #
sudo apt update -y && \
sudo apt full-upgrade -y && \
sudo apt autoremove -y && \
sudo apt autoclean -y
# ============================================================== #
# install some essential apps and remove vim to be replaced by neovim
sudo apt install -y apt-transport-https ca-certificates curl gnupg-agent pkg-config
sudo apt purge -y vim vim-runtime gvim
# add regolith-channel
sudo add-apt-repository -y --remove ppa:regolith-linux/release
sudo add-apt-repository -y --remove ppa:regolith-linux/stable
sudo add-apt-repository -yn ppa:regolith-linux/unstable
if [[ $(lsb_release -r | cut -f 2 | cut -d . -f 1) -le 20 ]]; then
# add rawtherapee
sudo add-apt-repository -yn ppa:dhor/myway
# add peek ppa
sudo add-apt-repository -yn ppa:peek-developers/stable
fi
# add inkscape-stable
sudo add-apt-repository -yn ppa:inkscape.dev/stable
# add github cli
sudo apt-key adv --keyserver keyserver.ubuntu.com --recv-key C99B11DEB97541F0
sudo apt-add-repository -yn https://cli.github.com/packages
# 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 git openmpi-bin libopenmpi-dev cmake libtool-bin parallel \
autoconf automake ccache shellcheck \
python3-dev libpython3-dev python3-pip python3-venv python-is-python3 \
zathura zathura-djvu zathura-ps zathura-pdf-poppler zathura-cb \
qpdf qpdfview gnuplot peek maim imgp pydf neovim \
vlc gimp rawtherapee ffmpeg imagemagick inkscape gir1.2-gtksource-3.0 \
regolith-desktop-standard regolith-todo \
p7zip-full p7zip-rar unrar unzip libarchive-tools uget aria2 rofi gh \
xclip neofetch exfat-fuse exfat-utils jq zsh ripgrep fd-find poppler-utils \
libcanberra-gtk-module
ln -s $(which fdfind) "${BIN_DIR}/fd"
# install battery block if on a laptop
[[ ! -z $(upower -i `upower -e | grep 'BAT'`) ]] && \
sudo apt install -y i3xrocks-battery
# set python3 as default
sudo update-alternatives --install /usr/bin/python python /usr/bin/python3 1
[[ ! -z "$APP_LIST" ]] && \
xargs -a <(awk '! /^ *(#|$)/' "$APP_LIST") -r -- sudo apt install -y
# config dotfiles
[[ ! -d ~/.config/regolith ]] && mkdir ~/.config/regolith
git clone https://github.com/cheginit/dotfiles.git ~/.dotfiles && \
cd ~/.dotfiles && \
lns .config/regolith/i3 ~/.config/regolith/ && \
lns .config/regolith/Xresources ~/.config/regolith/
# install latest libre-office
version="$(curl -sL https://downloadarchive.documentfoundation.org/libreoffice/old/latest/deb/x86_64 | grep -oP '(?<=href="LibreOffice_)[^"]*(?=_Linux_x86-64_deb.tar.gz")' | head -1 | cut -d '.' -f -4)"
version="$(echo ${version} | cut -d . -f 1-3)"
url="https://download.documentfoundation.org/libreoffice/stable/${version}/deb/x86_64/LibreOffice_${version}_Linux_x86-64_deb.tar.gz"
wget -q --show-progress --progress=bar:force -O libre.tar.gz $url 2>&1 && tar xvf libre.tar.gz --wildcards --no-anchored "*.deb" --strip-components 1 && sudo dpkg -i DEBS/*.deb && sudo apt -f install
rm -rf libre.tar.gz DEBS
# install oh-my-zsh
curl -fsSLo install.sh https://raw.github.com/ohmyzsh/ohmyzsh/master/tools/install.sh && \
sh install.sh --unattended && \
rm -f install.sh && \
git clone https://github.com/zsh-users/zsh-autosuggestions.git ${ZSH_CUSTOM:-~/.oh-my-zsh/custom}/plugins/zsh-autosuggestions && \
git clone https://github.com/zdharma-continuum/fast-syntax-highlighting.git ${ZSH_CUSTOM:-$HOME/.oh-my-zsh/custom}/plugins/fast-syntax-highlighting && \
git clone https://github.com/Aloxaf/fzf-tab ${ZSH_CUSTOM:-~/.oh-my-zsh/custom}/plugins/fzf-tab && \
mkdir -p ${ZSH:-$HOME/.oh-my-zsh}/completions && \
curl -Lo ${ZSH:-$HOME/.oh-my-zsh}/completions/_rg https://raw.githubusercontent.com/BurntSushi/ripgrep/master/complete/_rg && \
curl -Lo ${ZSH:-$HOME/.oh-my-zsh}/completions/_buku https://raw.githubusercontent.com/jarun/buku/master/auto-completion/zsh/_buku && \
rm -f ~/.zshrc && \
lns ~/.dotfiles/.zshrc ~/
sh -c "$(curl -fsSL https://starship.rs/install.sh)" -- -y
# install zoxide
curl -sS https://webinstall.dev/zoxide | bash
# install cloc
cd "${GITHUB_DIR}"
git clone https://github.com/AlDanial/cloc.git && \
lns cloc/cloc ${BIN_DIR}
# 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/releases/linux/${version}/prod/x64/slack-desktop-${version}-amd64.deb
# download pandoc
git_latest jgm/pandoc 0
# download duf
git_latest muesli/duf 13
# download bat
git_latest sharkdp/bat 12
# download marktext
git_latest marktext/marktext 3
# download gifski
git_latest ImageOptim/gifski 1
# install the download .deb files
for f in $(ls *.deb); do
sudo dpkg -i ${f} && \
rm ${f};
done
sudo apt install -f -y
# install iosevka font
version="$(git_latest_version be5invis/Iosevka)" && \
wget "https://github.com/be5invis/Iosevka/releases/download/${version}/super-ttc-iosevka-ss14-${version:1}.zip" && \
unzip "super-ttc-iosevka-ss14-${version:1}.zip" && \
sudo mv iosevka-ss14.ttc /usr/share/fonts/ && \
fc-cache -fv
rm "super-ttc-iosevka-ss14-${version:1}.zip"
# install exa
unzip -d exa "$(git_latest ogham/exa 3)" && \
mv exa/bin/exa "$BIN_DIR" && \
sudo mv exa/man/exa.1 /usr/share/man/man1 && \
mv exa/completions/exa.zsh ${ZSH:-$HOME/.oh-my-zsh}/completions && \
rm -rf exa*
# install nnn with nerd icons
sudo apt install -y pkg-config libncursesw5-dev libreadline-dev
cd $GITHUB_DIR &&
git clone https://github.com/jarun/nnn && \
cd nnn && \
sudo make O_NERD=1 strip install && \
curl -Ls https://raw.githubusercontent.com/jarun/nnn/master/plugins/getplugs | sh
sudo apt install -f -y
sudo apt autoremove -y
sudo apt autoclean -y
# install fzf
git clone --depth 1 https://github.com/junegunn/fzf.git ~/.fzf && \
~/.fzf/install --key-bindings --completion --no-update-rc --no-bash
# install rofi-calc
sudo apt install -y rofi-dev libtool && \
fname=$(git_latest Qalculate/libqalculate 4) && \
dname=$(echo $fname | cut -d '-' -f 1,2) && \
tar xvf $fname $dname/qalc && \
mv $dname/qalc ${BIN_DIR} && \
rm -rf $fname $dname
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/
sudo rm -f /usr/bin/pip
sudo ln -s /usr/bin/pip3 /usr/bin/pip
# install some useful python libraries
sudo pip3 install -U pip
pip3 install --user -U colorama
pip3 install --user -U thefuck youtube-dl ffpb pipx bpytop
# change firefox theme to Firefox-Mod-Blur
profile="$(realpath ~/.mozilla/firefox/*-release)" && \
cd "$profile" && \
echo 'user_pref("toolkit.legacyUserProfileCustomizations.stylesheets", true);' >> user.js && \
echo 'user_pref("layout.css.backdrop-filter.enabled", true);' >> user.js && \
echo 'user_pref("layers.acceleration.force-enabled", true);' >> user.js && \
echo 'user_pref("gfx.webrender.all", true);' >> user.js && \
echo 'user_pref("svg.context-properties.content.enabled", true);' >> user.js && \
echo 'user_pref("extensions.pocket.enabled", false);' >> 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" ]] && \
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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment