2021-08-29 14:19:27 +02:00
#!/bin/bash
2021-10-01 07:18:19 +02:00
# shellcheck shell=bash
2021-02-20 15:30:43 +01:00
2021-08-27 15:43:05 +02:00
{ # curybrackets is included to ensure everything is downloaded
2021-06-27 08:12:42 +02:00
#set -e
2021-06-09 16:25:24 +02:00
2021-07-04 08:48:31 +02:00
# if undefined, use $HOME/.local
2021-07-04 16:20:14 +02:00
if [[ $PREFIX == "" ]]; then
2021-08-29 14:19:27 +02:00
export PREFIX="$HOME/.local"
2021-10-01 07:18:19 +02:00
[[ ! -d "$PREFIX/bin" ]] && mkdir "$PREFIX/bin" -p
2021-07-04 16:20:14 +02:00
fi
2021-07-04 08:48:31 +02:00
2021-07-01 16:37:36 +02:00
# TODO: Make this better
banner() {
2021-07-04 08:33:18 +02:00
echoStageNameAdd "Dotfiles Bootstrap Script by Andrei Jiroh"
echoStageName "Linux machine bootstrapper starts in 3 seconds..."
2021-07-01 16:37:36 +02:00
sleep 3
}
2021-02-20 15:30:43 +01:00
2021-06-09 16:25:24 +02:00
useColor() {
2021-07-12 13:10:13 +02:00
RED=$(printf '\033[31m')
GREEN=$(printf '\033[32m')
YELLOW=$(printf '\033[33m')
BLUE=$(printf '\033[34m')
MAGENTA=$(printf '\033[35m')
BOLD=$(printf '\033[1m')
RESET=$(printf '\033[m')
2021-06-09 16:25:24 +02:00
}
echoStageName() {
2021-07-01 16:37:36 +02:00
echo "${BOLD}----> $* ${RESET}"
2021-06-09 16:25:24 +02:00
}
2021-07-04 08:33:18 +02:00
echoStageNameAdd() {
echo "${BOLD} $* ${RESET}"
}
2021-06-09 16:25:24 +02:00
warn() {
2021-07-04 08:33:18 +02:00
echo "${YELLOW}warning: $* ${RESET}"
2021-06-09 16:25:24 +02:00
}
error() {
# this will be long, so I must do "&& exit 1" manually
2021-07-04 08:33:18 +02:00
echo "${RED}error: $* ${RESET}"
}
success() {
echo "${GREEN}success: $* ${RESET}"
2021-06-09 16:25:24 +02:00
}
checkOs() {
2021-07-04 10:39:57 +02:00
# This step is required for different actions, like installing deps from system-wide package managers
# among other sorts of shitfuckery
2021-06-09 16:25:24 +02:00
if echo $OSTYPE | grep -qE "linux-android.*"; then
export DOTFILES_OS_NAME=android-termux
elif echo $OSTYPE | grep -qE '^linux-gnu.*' && [ -f '/etc/debian_version' ]; then
# Since Ubuntu is an major Debian fork, they're both LSB-complaint, so
# we might need to just use grep for this one in the future.
export DOTFILES_OS_NAME=debian-ubuntu
2021-07-04 08:33:18 +02:00
if [ -d '/google/devshell' ] && [ -f '/google/devshell/bashrc.google' ]; then
export GOOGLE_CLOUD_SHELL=true
fi
2021-10-01 07:18:19 +02:00
# TODO: Write stuff for Arch users and macOS. In case of WSL, the existence of /wsl.conf may be included in the future.
2021-04-06 11:50:36 +02:00
else
2021-06-09 16:25:24 +02:00
error "Script unsupported for this machine. See the online README for guide on manual bootstrapping." && exit 1
2021-02-20 15:30:43 +01:00
fi
2021-06-09 16:25:24 +02:00
}
installDeps() {
echoStageName "Installating essiential dependencies"
2021-07-01 16:37:36 +02:00
if [[ $DOTFILES_OS_NAME == "android-termux" ]] && [[ $SKIP_DEPENDENCY_INSTALL == "" ]]; then
2021-06-09 16:25:24 +02:00
pkg install -y man git nano gnupg openssh proot resolv-conf asciinema openssl-tool
echo "info: Essientials are installed, if you need Node.js just do 'pkg install nodejs' (we recommend installing the LTS one for stability) anytime"
2021-07-01 16:37:36 +02:00
elif [[ $DOTFILES_OS_NAME == "debian-ubuntu" ]] && [[ $SKIP_DEPENDENCY_INSTALL == "" ]]; then
2021-06-09 16:25:24 +02:00
sudo apt install gnupg git nano -y
if [[ $USE_PYENV != "" ]]; then
# we'll use the pyenv stuff
2021-08-27 16:12:41 +02:00
PYENV_ROOT=${PYENV_ROOT:-"$HOME/.pyenv"}
if [[ ! -d "${HOME}/.pyenv" ]]; then
echoStageName "Installing Pyenv with pyenv-installer"
curl -L https://github.com/pyenv/pyenv-installer/raw/master/bin/pyenv-installer | bash
else
git -C "${PYENV_ROOT}" pull origin --verbose
git -C "${PYENV_ROOT}/plugins/pyenv-doctor" pull origin --verbose
git -C "${PYENV_ROOT}/plugins/pyenv-installer" pull origin --verbose
git -C "${PYENV_ROOT}/plugins/pyenv-update" pull origin --verbose
git -C "${PYENV_ROOT}/plugins/pyenv-virtualenv" pull origin --verbose
git -C "${PYENV_ROOT}/plugins/pyenv-which-ext" pull origin --verbose
fi
echoStageName "Installing build deps as needed by pyenv"
sudo apt-get update; sudo apt-get install make build-essential libssl-dev zlib1g-dev libbz2-dev libreadline-dev libsqlite3-dev wget curl llvm libncursesw5-dev xz-utils tk-dev libxml2-dev libxmlsec1-dev libffi-dev liblzma-dev -y
2021-09-30 16:54:34 +02:00
2021-08-27 16:12:41 +02:00
echoStageName "Installing Python3 through Pyenv"
"${PYENV_ROOT}/bin/pyenv" install 3.9.6
2021-08-28 16:21:05 +02:00
"${PYENV_ROOT}/bin/pyenv" global 3.9.6
2021-06-09 16:25:24 +02:00
elif [[ $UPDATE_SYSTEM_PYTHON_INSTALL != "" ]]; then
echoStageName "Updating Python install"
2021-06-21 09:51:59 +02:00
sudo apt install python3 python3-pip --yes
2021-06-09 16:25:24 +02:00
fi
2021-07-01 16:37:36 +02:00
else
2021-09-30 16:54:34 +02:00
warn "Dependency installs are being skipped"
2021-06-09 16:25:24 +02:00
fi
2021-07-01 16:37:36 +02:00
sleep 5
2021-06-09 16:25:24 +02:00
}
2021-04-20 17:49:27 +02:00
2021-08-24 15:59:44 +02:00
installNodeVerManager() {
2021-08-27 15:37:43 +02:00
echoStagName "Installing Node.js Version Manager"
2021-08-24 15:59:44 +02:00
$(command -v curl >>/dev/null && echo "curl -o-" || echo "wget -qO-") https://raw.githubusercontent.com/nvm-sh/nvm/v0.38.0/install.sh | NODE_VERSION=${NODE_VERSION:"lts/*"} NVM_DIR="$HOME/.nvm" PROFILE=/dev/null bash
}
2021-07-04 10:39:57 +02:00
userspcaeBinDirCheck() {
echoStageName "checking if PREFIX/bin exists"
2021-07-12 13:10:13 +02:00
if [ ! -d "$PREFIX/bin" ]; then
2021-07-04 10:39:57 +02:00
warn "$PREFIX/bin doesn't exists, creating..."
2021-07-12 13:10:13 +02:00
mkdir -p "$PREFIX/bin"
2021-07-04 10:39:57 +02:00
else
2021-07-12 13:10:13 +02:00
success "Looks good! $PREFIX/bin directory exists."
2021-07-04 10:39:57 +02:00
fi
}
2021-06-09 16:25:24 +02:00
cloneRepo() {
if [ ! -d "$HOME/.dotfiles" ]; then
2021-06-21 09:51:59 +02:00
echoStageName "Cloning the dotfiles repo"
2021-06-28 15:48:57 +02:00
git clone https://github.com/ajhalili2006/dotfiles.git $HOME/.dotfiles
2021-06-09 16:25:24 +02:00
else
2021-06-21 09:51:59 +02:00
echoStageName "Dotfiles repo found, pulling remote changes instead"
2021-06-09 16:25:24 +02:00
git -C "$HOME/.dotfiles" fetch --all
git -C "$HOME/.dotfiles" pull origin
fi
2021-07-04 16:20:14 +02:00
sleep 5
2021-09-29 12:12:51 +02:00
}
2021-04-25 10:09:04 +02:00
2021-09-29 12:12:51 +02:00
# Decouple secrets repo cloning process from the main
cloneSecretsRepo() {
# Since I also have an GitHub mirror of that private repo, maybe we can set an variable for that
if [[ $USE_GH_SECRETS_MIRROR != "" ]]; then
true # just an bypass command to avoid these steps below
elif [[ $GITLAB_TOKEN == "" ]] && [[ $GITLAB_LOGIN == "" ]] && [ ! -d "$HOME/.dotfiles/secrets" ]; then
2021-06-09 16:25:24 +02:00
error "GitLab login and token can't be blank!" && exit 1
# Probably change my GitLab SaaS username with yours
2021-07-04 08:33:18 +02:00
elif [[ $GITLAB_LOGIN != "ajhalili2006" ]] && [ ! -d "$HOME/.dotfiles/secrets" ]; then
2021-06-09 16:25:24 +02:00
error "Only Andrei Jiroh can do this!" && exit 1
2021-07-04 08:33:18 +02:00
elif [[ $GITLAB_LOGIN == "ajhalili2006" ]] && [[ $GITLAB_TOKEN == "" ]] && [ ! -d "$HOME/.dotfiles/secrets" ]; then
2021-09-30 16:59:03 +02:00
error "Missing GitLab SaaS PAT! Check your Bitwarden vault for that PAT with atleast read_repository scope, or use GitHub mirror instead." && exit 1
2021-06-09 16:25:24 +02:00
fi
2021-07-01 16:37:36 +02:00
2021-06-09 16:25:24 +02:00
if [ ! -d "$HOME/.dotfiles/secrets" ]; then
2021-06-21 09:51:59 +02:00
echoStageName "Cloning secrets repo"
2021-09-29 12:12:51 +02:00
if [[ $USE_GH_SECRETS_MIRROR != "" ]]; then
gh repo clone ajhalili2006/dotfiles-secrets
elif ! git clone https://$GITLAB_LOGIN:$GITLAB_TOKEN@gitlab.com/ajhalili2006/dotfiles-secrets $HOME/.dotfiles/secrets; then
2021-09-30 16:59:03 +02:00
echo "error: That kinda sus, but either only Andrei Jiroh can proceed or maybe the PAT you used is invalid. Probably try to use GitHub mirror instead" && exit 1
2021-09-29 12:12:51 +02:00
fi
2021-07-04 16:20:14 +02:00
chmod 760 $HOME/.dotfiles/secrets
2021-09-29 12:12:51 +02:00
git -C "$HOME/.dotfiles/secrets" remote set-url origin git@gitlab.com:ajhalili2006/dotfiles-secrets
2021-06-09 16:25:24 +02:00
else
2021-07-04 16:20:14 +02:00
chmod 760 $HOME/.dotfiles/secrets
2021-06-09 16:25:24 +02:00
git -C "$HOME/.dotfiles/secrets" fetch --all
2021-06-21 09:51:59 +02:00
git -C "$HOME/.dotfiles/secrets" pull
2021-06-09 16:25:24 +02:00
fi
2021-08-29 15:18:42 +02:00
sleep 5
2021-06-09 16:25:24 +02:00
}
2021-04-22 18:05:17 +02:00
2021-09-29 12:12:51 +02:00
# Install GitHub CLI if we're gonna use that GitHub mirror
ghCli() {
if [[ $DOTFILES_OS_NAME == "debian-ubuntu" ]] && [[ "$(command -v gh)" == "" ]]; then
curl -fsSL https://cli.github.com/packages/githubcli-archive-keyring.gpg | sudo gpg --dearmor -o /usr/share/keyrings/githubcli-archive-keyring.gpg
echo "deb [arch=$(dpkg --print-architecture) signed-by=/usr/share/keyrings/githubcli-archive-keyring.gpg] https://cli.github.com/packages stable main" | sudo tee /etc/apt/sources.list.d/github-cli.list > /dev/null
sudo apt update && sudo apt install gh
fi
}
2021-06-09 16:25:24 +02:00
cleanup() {
2021-06-21 09:51:59 +02:00
echoStageName "Bootstrapper successfully ran, cleaning up to ensure no secrets are leaked on env vars..."
2021-04-25 10:09:04 +02:00
# just add chaos to these secrets to avoid leaks
2021-06-21 09:51:59 +02:00
export GITLAB_LOGIN=gildedguy
export GITLAB_TOKEN=build-guid-sus-among-computers-moment
2021-07-12 13:10:13 +02:00
if echo "$OSTYPE" | grep -qE "linux-android.*"; then
2021-06-09 16:25:24 +02:00
rm -rfv ~/{shellcheck,flarectl,LICENSE,README.txt,README.md}
pkg uninstall clang --yes && apt autoremove --yes
2021-07-04 08:48:31 +02:00
else
2021-08-10 16:05:04 +02:00
rm -rfv ~/{shellcheck,flarectl,LICENSE,README.txt,README.md}* || true
2021-07-04 16:20:14 +02:00
unset PREFIX
2021-06-09 16:25:24 +02:00
fi
2021-07-04 08:33:18 +02:00
success "Setting up a new Linux machine was succesfully executed. To ensure no secrets are leaked when logging utfrom shell session, please do 'history -c' to cleanup shell history."
2021-08-29 15:18:42 +02:00
[[ $GOOGLE_CLOUD_SHELL == "true" ]] && warn "Looks like you're on Google Cloud Shell, please restart your virtual machine for changes to take effect."
2021-04-13 11:39:18 +02:00
sleep 2
2021-07-04 08:33:18 +02:00
unset DOTFILES_OS_NAME GOOGLE_CLOUD_SHELL
2021-04-05 05:53:52 +02:00
exit
2021-06-09 16:25:24 +02:00
}
copyKeysSSH() {
echoStageName "Copying SSH keys"
if [ ! -d "$HOME/.ssh" ]; then
2021-07-12 13:10:13 +02:00
mkdir -p "$HOME/.ssh"
2021-08-28 16:21:05 +02:00
cp "$HOME/.dotfiles/secrets/ssh/launchpad" "$HOME/.ssh/launchpad"
cp "$HOME/.dotfiles/secrets/ssh/launchpad.pub" "$HOME/.ssh/launchpad.pub"
2021-08-29 14:19:27 +02:00
chmod 600 "$HOME/.ssh/launchpad"
2021-06-09 16:25:24 +02:00
else
2021-08-28 16:21:05 +02:00
[ ! -f "$HOME/.ssh/launchpad" ] && cp "$HOME/.dotfiles/secrets/ssh/launchpad" "$HOME/.ssh/launchpad"
[ ! -f "$HOME/.ssh/launchpad.pub" ] && "cp $HOME/.dotfiles/secrets/ssh/launchpad.pub" "$HOME/.ssh/launchpad.pub"
[ -f "$HOME/.ssh/launchpad.pub" ] && chmod 600 "$HOME/.ssh/launchpad"
2021-06-09 16:25:24 +02:00
fi
2021-05-16 13:14:25 +02:00
2021-06-09 16:25:24 +02:00
echoStageName "Linking config files"
if echo $OSTYPE | grep -qE "linux-android.*"; then
[ ! -f "$HOME/.ssh/config" ] && ln -s $HOME/.dotfiles/ssh-client/termux ~/.ssh/config
# TODO: Write checks if it's Ubuntu or Debian
# See https://superuser.com/a/741610/1124908 for details
elif echo $OSTYPE | grep -qE '^linux-gnu.*' && [ -f '/etc/debian_version' ]; then
2021-08-28 16:21:05 +02:00
[ ! -f "$HOME/.ssh/config" ] && ln -s "$HOME/.dotfiles/ssh-client/ubuntu" "$HOME/.ssh/config"
2021-06-09 16:25:24 +02:00
fi
sleep 5
}
copyBashrc() {
if [[ $DOTFILES_OS_NAME == "android-termux" ]]; then
2021-06-27 08:12:42 +02:00
ln -s $HOME/.dotfiles/termux.bashrc ~/.bashrc
2021-06-09 16:25:24 +02:00
elif [[ $DOTFILES_OS_NAME == "debian-ubuntu" ]]; then
2021-06-21 10:13:33 +02:00
if [[ $SKIP_CONFIG_LINKING == "" ]] && [ ! -f "$HOME/.bashrc" ]; then
2021-06-09 16:25:24 +02:00
ln -s "$HOME/.dotfiles/ubuntu.bashrc" ~/.bashrc
2021-07-04 08:33:18 +02:00
elif [[ $GOOGLE_CLOUD_SHELL == "true" ]] && [[ $SKIP_CONFIG_LINKING == "" ]] && [ -f "$HOME/.bashrc" ]; then
2021-08-29 14:19:27 +02:00
rm "$HOME/.bashrc"
2021-08-29 15:18:42 +02:00
ln -s "$HOME/.dotfiles/bashrc/googlecloudshell.bashrc" "$HOME/.bashrc"
2021-06-09 16:25:24 +02:00
elif [[ $SKIP_CONFIG_LINKING == "" ]] && [ -f "$HOME/.bashrc" ]; then
2021-08-29 15:18:42 +02:00
if [[ -L "$HOME/.bashrc" ]]; then
warn "~/.bashrc is symlinked, skipping the linking process"
else
warn "Existing bashrc found, renaming to ~/.bashrc.bak"
mv "$HOME/.bashrc" "$HOME/.bashrc.bak"
ln -s "$HOME/.dotfiles/ubuntu.bashrc" "$HOME/.bashrc"
2021-08-29 15:25:08 +02:00
fi
2021-06-09 16:25:24 +02:00
fi
fi
}
copyGitConfig() {
echoStageName "Symlinking Git config"
2021-06-21 10:13:33 +02:00
if [[ $DOTFILES_OS_NAME == "android-termux" ]] && [[ $SKIP_CONFIG_LINKING == "" ]]; then
2021-09-30 16:54:34 +02:00
[ ! -L "$HOME/.gitconfig" ] && ln -s "$HOME/.dotfiles/gitconfig/termux" ~/.gitconfig && success "Git config symlinked" || warn "Git configuration on userspace found, either symlink is broken or customizations had been made. Please fix any conflicts or soft link them manually!"
2021-06-09 16:25:24 +02:00
# TODO: Write checks if it's Ubuntu or Debian
# See https://superuser.com/a/741610/1124908 for details
2021-07-04 16:20:14 +02:00
# By default, we'll use the one-size-fits-all Linux config for Git
2021-06-21 10:13:33 +02:00
elif [[ $DOTFILES_OS_NAME == "debian-ubuntu" ]] && [[ $SKIP_CONFIG_LINKING == "" ]]; then
2021-09-30 16:54:34 +02:00
[ ! -L "$HOME/.gitconfig" ] && ln -s "$HOME/.dotfiles/gitconfig/linux" "$HOME/.gitconfig" || warn "Git configuration on userspace found, either symlink is broken or customizations had been made. Please fix any conflicts or soft link them manually!"
2021-06-09 16:25:24 +02:00
fi
}
copyNanoConfig() {
2021-09-30 16:54:34 +02:00
echoStagename "Symlinking GNU nano config file"
2021-06-09 16:25:24 +02:00
if [[ $DOTFILES_OS_NAME == "android-termux" ]]; then
2021-07-12 13:10:13 +02:00
[ "$SKIP_CONFIG_LINKING" == "" ] && ln -s "$HOME/.dotfiles/nanorc/config/termux" "$HOME/.nanorc"
2021-09-30 16:54:34 +02:00
else
[ "$SKIP_CONFIG_LINKING" == "" ] && [ ! -L "$HOME/.gitconfig" ] && ln -s "$HOME/.dotfiles/nanorc/config/linux.nanorc" "$HOME/.nanorc"
2021-06-09 16:25:24 +02:00
fi
}
installShellCheck() {
echoStageName "Installing Shellcheck"
2021-09-29 12:12:51 +02:00
scversion="stable" # or "v0.4.7", or "latest"
SHELLCHECK_ARCHIVE_URL="https://github.com/koalaman/shellcheck/releases/download/${scversion?}/shellcheck-${scversion?}.linux.x86_64.tar.xz" # TODO: Also detect other arches, especially on i386
2021-09-29 12:30:57 +02:00
if [[ $LSKIP_DEPENDENCY_INSTAL == "" ]]; then
2021-07-04 16:20:14 +02:00
current_shellcheck_path=$(command -v shellcheck)
2021-09-29 12:12:51 +02:00
isOwnedByUser="$(find $PREFIX/bin -user $USER -name shellcheck)"
2021-08-28 16:21:05 +02:00
current_path_dir="$(dirname $current_shellcheck_path)"
2021-09-29 12:12:51 +02:00
wget -qO- "$SHELLCHECK_ARCHIVE_URL" | tar -xJv -C "$HOME"
2021-07-04 16:20:14 +02:00
if [[ $current_shellcheck_path == "" ]]; then
2021-08-10 16:05:04 +02:00
cp "$HOME/shellcheck-${scversion}/shellcheck" "$PREFIX/bin"
2021-07-04 16:20:14 +02:00
elif [[ $current_shellcheck_path == "$PREFIX/bin/shellcheck" ]]; then
warn "Current ShellCheck install found in $PREFIX/bin, replacing with latest stable release..."
if [[ $isOwnedByUser == "" ]]; then
2021-08-10 16:05:04 +02:00
[ -f "$PREFIX/bin/shellcheck" ] && warn "Owned by either other user/root, summoning root" && sudo rm "${PREFIX}/bin/shellcheck"
2021-07-04 16:20:14 +02:00
else
rm "${PREFIX}/bin/shellcheck"
fi
2021-08-10 16:05:04 +02:00
cp "$HOME/shellcheck-${scversion}/shellcheck" "$PREFIX/bin"
2021-07-04 16:20:14 +02:00
else
2021-07-12 13:10:13 +02:00
warn "Current ShellCheck install found in $current_path_dir, will be removed..."
2021-06-09 16:25:24 +02:00
if [[ $isOwnedByUser == "" ]]; then
2021-08-10 16:05:04 +02:00
warn "Owned by either other user/root, summoning root"
sudo rm "$current_path_dir/shellcheck"
2021-06-09 16:25:24 +02:00
else
2021-06-09 16:33:54 +02:00
rm "${PREFIX}/bin/shellcheck"
2021-06-09 16:25:24 +02:00
fi
2021-08-10 16:05:04 +02:00
cp "$HOME/shellcheck-${scversion}/shellcheck" "$PREFIX/bin"
2021-07-04 16:20:14 +02:00
fi
2021-09-30 16:54:34 +02:00
else
warn "Shellcheck install/upgrade is being skipped!"
2021-06-09 16:25:24 +02:00
fi
}
installAscinema() {
2021-07-12 13:10:13 +02:00
echoStageName "Installing Asciinema"
2021-08-27 15:37:43 +02:00
if [[ $DOTFILES_OS_NAME == "android-termux" ]] && [[ $SKIP_DEPENDENCY_INSTALL == "" ]]; then
2021-07-12 13:10:13 +02:00
pkg install aciinema -y
2021-08-27 15:37:43 +02:00
elif [[ $SKIP_DEPENDENCY_INSTALL == "" ]]; then
if command -v python3>>/dev/null && [ -f "$HOME/.pyenv/shims/python3" ]; then
"$HOME/.pyenv/shims/pip3" install asciinema --user --upgrade
else
2021-09-30 16:54:34 +02:00
pip3 install asciinema --user --upgrade
2021-08-27 15:37:43 +02:00
fi
2021-05-16 13:14:25 +02:00
fi
2021-06-09 16:25:24 +02:00
}
2021-05-31 17:50:30 +02:00
2021-06-09 16:25:24 +02:00
installTF() {
2021-07-12 13:10:13 +02:00
echoStageName "Installing pip3:thefuck"
2021-06-09 16:25:24 +02:00
if [[ $DOTFILES_OS_NAME == "android-termux" ]]; then
2021-07-04 08:48:31 +02:00
pkg install clang -y && pip install thefuck --user --upgrade
2021-05-16 13:14:25 +02:00
else
2021-06-09 16:25:24 +02:00
if command -v python3>>/dev/null && [ -f "$HOME/.pyenv/shims/python3" ]; then
2021-08-27 15:37:43 +02:00
"$HOME/.pyenv/shims/pip3" install thefuck --upgrade
2021-06-09 16:25:24 +02:00
else
2021-07-04 08:48:31 +02:00
pip3 install thefuck --user --upgrade
2021-06-09 16:25:24 +02:00
fi
2021-05-16 13:14:25 +02:00
fi
2021-06-09 16:25:24 +02:00
}
2021-05-31 17:50:30 +02:00
2021-06-19 09:21:31 +02:00
installFilterRepo() {
2021-07-12 13:10:13 +02:00
echoStageName "Installing git-filter-repo"
2021-06-19 09:21:31 +02:00
if [[ $DOTFILES_OS_NAME == "android-termux" ]]; then
2021-07-12 13:10:13 +02:00
pip install git-filter-repo --upgrade
2021-06-19 09:21:31 +02:00
else
if command -v python3>>/dev/null && [ -f "$HOME/.pyenv/shims/python3" ]; then
2021-08-27 15:37:43 +02:00
"$HOME/.pyenv/shims/pip3" install git-filter-repo --upgrade
2021-06-19 09:21:31 +02:00
else
2021-07-04 08:48:31 +02:00
pip3 install git-filter-repo --user --upgrade
2021-06-19 09:21:31 +02:00
fi
fi
}
2021-07-01 16:37:36 +02:00
# usage stuff
usage() {
echo "Accepted bootstrap script arguments are:"
2021-07-04 16:20:14 +02:00
echo "* --help|-h - Show this text."
echo "* -i - Skip installing different dependencies and packages"
echo "* -d - Enable debugging"
echo "* -l - Skip symlinking config files (nanorc, bashrc, etc.)"
2021-07-04 08:33:18 +02:00
}
customizeCloudShell() {
echoStageName "Adding customizations for Cloud Shell Environment"
if [ -f ~/.customize_environment ]; then
warn "Envirnment customization script found, deleting old one..."
rm -fv ~/.customize_environment
fi
2021-09-30 16:54:34 +02:00
2022-02-27 16:28:07 +01:00
ln -s ~/.dotfiles/.config/devshell.env ~/.customize_environment && chmod +x ~/.customize_environment
2021-07-12 13:10:13 +02:00
if [ ! -d "$HOME/.cloudshell" ]; then
2021-08-28 16:21:05 +02:00
mkdir "$HOME/.cloudshell"
2021-07-12 13:10:13 +02:00
fi
if [ ! -f "$HOME/.cloudshell/no-apt-get-warning" ]; then
2021-08-28 16:21:05 +02:00
touch "$HOME/.cloudshell/no-apt-get-warning"
2021-07-12 13:10:13 +02:00
fi
echoStageName "Running ~/.customize_environment for you"
2021-08-28 16:21:05 +02:00
sudo "$HOME/.customize_environment"
2021-07-01 16:37:36 +02:00
}
2021-08-24 15:59:44 +02:00
# Install VS Code here (or code-server)
installCode() {
if [[ $USE_CODE_SERVER != "" ]]; then
# We'll use the officil script here, because why not? This may take longer on Termux if that's the case.
2021-08-27 15:37:43 +02:00
echoStageName "Installing Code Server"
2021-08-24 15:59:44 +02:00
curl -fsSL https://code-server.dev/install.sh | sh
2021-08-29 15:18:42 +02:00
elif [[ $XDG_CURRENT_DESKTOP != "" ]]; then
2021-08-24 15:59:44 +02:00
true # It's true for now
fi
}
2021-08-15 16:11:55 +02:00
2021-06-09 16:25:24 +02:00
main() {
2021-07-01 16:37:36 +02:00
# check if the help flag is here
[[ $DEBUG != "" ]] && echo "flags: $*"
while [[ $# -gt 0 ]]; do
case $1 in
"--help"|-h)
shift
usage
exit
;;
*)
shift
error "Invalid arguments, add the help flag for usage." && exit 1
esac
shift
done
# import colors and show the banner
2021-06-09 16:25:24 +02:00
useColor
2021-07-01 16:37:36 +02:00
banner
2021-09-30 16:54:34 +02:00
2021-06-09 16:25:24 +02:00
# step 1: check the OS first
checkOs
2021-07-04 10:39:57 +02:00
# step 2: install needed tools and create ~/.local/bin
2021-06-09 16:25:24 +02:00
installDeps
2021-07-04 10:39:57 +02:00
userspcaeBinDirCheck
2021-09-29 12:12:51 +02:00
[[ $USE_GH_SECRETS_MIRROR != "" ]] && ghCli
# Possibly interactively sign in to the CLI if GITHUB_TOKEN isn't provided
[[ $GITHUB_TOKEN == "" && $USE_GH_SECRETS_MIRROR == "" ]] && gh auth login
2021-06-09 16:25:24 +02:00
2021-07-04 08:33:18 +02:00
# step 3.1: then clone the repo
2021-06-09 16:25:24 +02:00
cloneRepo
2021-09-30 16:54:34 +02:00
2021-07-04 08:33:18 +02:00
# step 3.2: if we're in Cloud Shell, do this
2021-08-29 15:18:42 +02:00
[[ $GOOGLE_CLOUD_SHELL == "true" ]] && customizeCloudShell
2021-06-09 16:25:24 +02:00
# step 4: install additional needed tools
installAscinema
installTF
2021-06-19 09:21:31 +02:00
installFilterRepo
2021-07-12 13:10:13 +02:00
installShellCheck
2021-08-27 15:37:43 +02:00
[[ $USE_NVM != "" ]] && installNodeVerManager
2021-08-24 15:59:44 +02:00
installCode
2021-06-09 16:25:24 +02:00
# step 5: copy and symlink files
copyGitConfig
copyNanoConfig
copyBashrc
2021-09-29 12:30:57 +02:00
# step 5.2: copy our secrets btw
cloneSecretsRepo # Run this before we even copy the ssh keys!
2021-06-09 16:25:24 +02:00
copyKeysSSH
2021-06-19 09:21:31 +02:00
# step 6: finally clean up bullshit
2021-06-09 16:25:24 +02:00
cleanup
}
2021-06-19 09:21:31 +02:00
main "$@"
2021-08-27 15:43:05 +02:00
} # curybrackets is included to ensure everything is downloaded