diff --git a/.vscode/settings.json b/.vscode/settings.json index 0869c7a..a8d7102 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -1,4 +1,5 @@ { - "workbench.iconTheme": "vscode-icons", + "workbench.iconTheme": "material-icon-theme", + "workbench.productIconTheme": "material-product-icons", "git.alwaysSignOff": true } \ No newline at end of file diff --git a/README.md b/README.md index f1de6a5..4e90fa1 100644 --- a/README.md +++ b/README.md @@ -7,7 +7,7 @@ working at The Pins Team, see [our dotfiles][df-gl]. ## Getting Started -### Using the bootstraper script without cloning +### Running from ```sh # configure required variables diff --git a/bashrc/chain-source b/bashrc/chain-source deleted file mode 100644 index 867fbe1..0000000 --- a/bashrc/chain-source +++ /dev/null @@ -1,6 +0,0 @@ -#!/bin/bash - -# these commands should be triggered on shell startup -. ~/.dotfiles/bashrc/aliases -. ~/.dotfiles/bashrc/worthwhile-functions -guild-test diff --git a/bin/cloudflarectl b/bin/cloudflarectl index 7922221..ee6cf24 100755 --- a/bin/cloudflarectl +++ b/bin/cloudflarectl @@ -1,5 +1,6 @@ #!/bin/bash +# TODO: Detect whenever we can use HTTPie in the shell environment or use plain old curl. HTTP_CLIENT_PATH=$(command -v curl) if [[ $HTTP_CLIENT_PATH == "" ]]; then @@ -8,12 +9,38 @@ if [[ $HTTP_CLIENT_PATH == "" ]]; then fi if command -v jq >> /dev/null; then - echo "OK" >> /dev/null + true else echo "Please install jq to prettify JSON responses from API." exit 1 fi +### COLORS ### +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') +### COLORS ### + +warn() { + if [[ $NO_COLOR == "" ]]; then + echo "${YELLOW}warning: $* ${RESET}" + else + echo "warninh: $*" + fi +} + +error() { + echo "${RED}error: $* ${RESET}" +} + +info() { + echo "info: $*" +} + # API Handler apiHandler() { CF_HOST="https://api.cloudflare.com/client/v4" @@ -30,7 +57,7 @@ if [[ $# == "0" ]] || [[ $1 == "help" ]]; then echo "validate-token Check if an token is still working" echo "zones Manage your Cloudflare zones" else - if [[ $@ == "validate-token" ]]; then + if [[ $1 == "validate-token" ]]; then if [[ $CF_API_EMAIL != "" ]]; then echo "Unsupported variable found: CF_API_EMAIL" echo "Please use API keys instead of global API token." @@ -42,7 +69,7 @@ else echo "No token found! Set your API token with:" echo " export CF_API_KEY=abcdef123456" fi - elif [[ $@ == "zones" ]]; then + elif [[ $1 == "zones" ]]; then echo "Usage: $0 zones [ARGS]" echo echo "Manage and list your zones managed by Cloudflare." @@ -51,7 +78,7 @@ else echo "add Add new zone" echo "remove Remove an zone" exit - elif [[ $@ == "zones list" ]]; then + elif [[ $1 == "zones" && $2 == "list" ]]; then apiHandler zones GET | jq .result else echo "Unsupported command! See the help command for details" diff --git a/bin/code b/bin/code index 50a8112..feeec5b 100755 --- a/bin/code +++ b/bin/code @@ -1,3 +1,5 @@ #!/bin/bash -echo "Work in progres on rewrite..." +if [[ -f "/snap/bin/code" ]]; then + exec /snap/bin/code $* +fi diff --git a/bin/gcshell b/bin/gcshell index 552dfdc..4389b28 100755 --- a/bin/gcshell +++ b/bin/gcshell @@ -1,12 +1,18 @@ #!/bin/bash #shellcheck disable=SC2034,SC1091 -# Configuration variables -if [ -f "$DOTFILES_HOME/.config/gcshell.env" ]; then - source "$DOTFILES_HOME/.config/gcshell.env" +if [[ $DEBUG != "" ]]; then + set -x fi -CLOUD_SHELL_SSH_KEY=${GCLOUD_CLOUD_SHELL_SSH_KEY:="$HOME/.ssh/google_compute_engine"} -OVERWRITE_CLOUD_SHELL_KEY=${OVERWRITE_CLOUD_SHELL_KEy:=false} + +# Init config +DOTFILES_HOME=${DOTFILES_HOME:-"$HOME/.dotfiles"} +if [ -f "$DOTFILES_HOME/config/gcshell.env" ]; then + source "$DOTFILES_HOME/config/gcshell.env" +fi + +CLOUD_SHELL_SSH_KEY=${GCLOUD_CLOUD_SHELL_SSH_KEY:-"$HOME/.ssh/google_compute_engine"} +OVERWRITE_CLOUD_SHELL_KEY=${OVERWRITE_CLOUD_SHELL_KEy:-"false"} # Only use colors if connected to a terminal if [ -t 1 ]; then @@ -48,10 +54,8 @@ fi if [[ $1 == "debug" ]]; then echo "===== CONFIG DEBUG =====" echo "Cloud Shell/Compute Engine SSH key path: $CLOUD_SHELL_SSH_KEY [set \$CLOUD_SHELL_SSH_KEY to change path]" - if [ -f "$CLOUD_SHELL_SSH_KEY" ]; then - echo "Cloud Shell/Compute Engine Public Key: $(cat "$CLOUD_SHELL_SSH_KEY.pub")" - else - warn "Cloud Shell/Compute Engine Public key was Not Found" + if [ ! -f "$CLOUD_SHELL_SSH_KEY" ]; then + warn "Cloud Shell/Compute Engine SSH key was doesn't exist" fi if [[ $OVERWRITE_CLOUD_SHELL_KEY == "true" ]]; then echo "Overwrite SSH keys: enabled" diff --git a/bin/ghcli-installer b/bin/ghcli-installer deleted file mode 100755 index 113347f..0000000 --- a/bin/ghcli-installer +++ /dev/null @@ -1,16 +0,0 @@ -#!/bin/env bash -# shellcheck shell=bash - -if [[ "$(command -v gh)" == "" ]]; then - echo "info: Installing GitHub CLI..." - if echo "$OSTYPE" | grep -qE '^linux-gnu.*' && [ -f '/etc/debian_version' ]; 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 -else - echo "info: Upgrading GitHub CLI..." - if echo "$OSTYPE" | grep -qE '^linux-gnu.*' && [ -f '/etc/debian_version' ]; then - sudo apt update; sudo apt install gh - fi -fi diff --git a/bin/homebrew-installer b/bin/homebrew-installer deleted file mode 100755 index fe3b14e..0000000 --- a/bin/homebrew-installer +++ /dev/null @@ -1,783 +0,0 @@ -#!/bin/bash -set -u - -abort() { - printf "%s\n" "$@" - exit 1 -} - -if [ -z "${BASH_VERSION:-}" ]; then - abort "Bash is required to interpret this script." -fi - -# Check if script is run non-interactively (e.g. CI) -# If it is run non-interactively we should not prompt for passwords. -if [[ ! -t 0 || -n "${CI-}" ]]; then - NONINTERACTIVE=1 -fi - -# First check OS. -OS="$(uname)" -if [[ "$OS" == "Linux" ]]; then - HOMEBREW_ON_LINUX=1 -elif [[ "$OS" != "Darwin" ]]; then - abort "Homebrew is only supported on macOS and Linux." -fi - -# Required installation paths. To install elsewhere (which is unsupported) -# you can untar https://github.com/Homebrew/brew/tarball/master -# anywhere you like. -if [[ -z "${HOMEBREW_ON_LINUX-}" ]]; then - UNAME_MACHINE="$(/usr/bin/uname -m)" - - if [[ "$UNAME_MACHINE" == "arm64" ]]; then - # On ARM macOS, this script installs to /opt/homebrew only - HOMEBREW_PREFIX="/opt/homebrew" - HOMEBREW_REPOSITORY="${HOMEBREW_PREFIX}" - else - # On Intel macOS, this script installs to /usr/local only - HOMEBREW_PREFIX="/usr/local" - HOMEBREW_REPOSITORY="${HOMEBREW_PREFIX}/Homebrew" - fi - HOMEBREW_CACHE="${HOME}/Library/Caches/Homebrew" - HOMEBREW_CORE_DEFAULT_GIT_REMOTE="https://github.com/Homebrew/homebrew-core" - - STAT="stat -f" - CHOWN="/usr/sbin/chown" - CHGRP="/usr/bin/chgrp" - GROUP="admin" - TOUCH="/usr/bin/touch" -else - UNAME_MACHINE="$(uname -m)" - - # On Linux, it installs to /home/linuxbrew/.linuxbrew if you have sudo access - # and ~/.linuxbrew (which is unsupported) if run interactively. - HOMEBREW_PREFIX_DEFAULT="/home/linuxbrew/.linuxbrew" - HOMEBREW_CACHE="${HOME}/.cache/Homebrew" - HOMEBREW_CORE_DEFAULT_GIT_REMOTE="https://github.com/Homebrew/linuxbrew-core" - - STAT="stat --printf" - CHOWN="/bin/chown" - CHGRP="/bin/chgrp" - GROUP="$(id -gn)" - TOUCH="/bin/touch" -fi -HOMEBREW_BREW_DEFAULT_GIT_REMOTE="https://github.com/Homebrew/brew" - -# Use remote URLs of Homebrew repositories from environment if set. -HOMEBREW_BREW_GIT_REMOTE="${HOMEBREW_BREW_GIT_REMOTE:-"${HOMEBREW_BREW_DEFAULT_GIT_REMOTE}"}" -HOMEBREW_CORE_GIT_REMOTE="${HOMEBREW_CORE_GIT_REMOTE:-"${HOMEBREW_CORE_DEFAULT_GIT_REMOTE}"}" -# The URLs with and without the '.git' suffix are the same Git remote. Do not prompt. -if [[ "$HOMEBREW_BREW_GIT_REMOTE" == "${HOMEBREW_BREW_DEFAULT_GIT_REMOTE}.git" ]]; then - HOMEBREW_BREW_GIT_REMOTE="${HOMEBREW_BREW_DEFAULT_GIT_REMOTE}" -fi -if [[ "$HOMEBREW_CORE_GIT_REMOTE" == "${HOMEBREW_CORE_DEFAULT_GIT_REMOTE}.git" ]]; then - HOMEBREW_CORE_GIT_REMOTE="${HOMEBREW_CORE_DEFAULT_GIT_REMOTE}" -fi -export HOMEBREW_{BREW,CORE}_GIT_REMOTE - -# TODO: bump version when new macOS is released or announced -MACOS_NEWEST_UNSUPPORTED="12.0" -# TODO: bump version when new macOS is released -MACOS_OLDEST_SUPPORTED="10.14" - -# For Homebrew on Linux -REQUIRED_RUBY_VERSION=2.6 # https://github.com/Homebrew/brew/pull/6556 -REQUIRED_GLIBC_VERSION=2.13 # https://docs.brew.sh/Homebrew-on-Linux#requirements - -# no analytics during installation -export HOMEBREW_NO_ANALYTICS_THIS_RUN=1 -export HOMEBREW_NO_ANALYTICS_MESSAGE_OUTPUT=1 - -# string formatters -if [[ -t 1 ]]; then - tty_escape() { printf "\033[%sm" "$1"; } -else - tty_escape() { :; } -fi -tty_mkbold() { tty_escape "1;$1"; } -tty_underline="$(tty_escape "4;39")" -tty_blue="$(tty_mkbold 34)" -tty_red="$(tty_mkbold 31)" -tty_bold="$(tty_mkbold 39)" -tty_reset="$(tty_escape 0)" - -have_sudo_access() { - local -a args - if [[ -n "${SUDO_ASKPASS-}" ]]; then - args=("-A") - elif [[ -n "${NONINTERACTIVE-}" ]]; then - args=("-n") - fi - - if [[ -z "${HAVE_SUDO_ACCESS-}" ]]; then - if [[ -n "${args[*]-}" ]]; then - SUDO="/usr/bin/sudo ${args[*]}" - else - SUDO="/usr/bin/sudo" - fi - if [[ -n "${NONINTERACTIVE-}" ]]; then - ${SUDO} -l mkdir &>/dev/null - else - ${SUDO} -v && ${SUDO} -l mkdir &>/dev/null - fi - HAVE_SUDO_ACCESS="$?" - fi - - if [[ -z "${HOMEBREW_ON_LINUX-}" ]] && [[ "$HAVE_SUDO_ACCESS" -ne 0 ]]; then - abort "Need sudo access on macOS (e.g. the user $USER needs to be an Administrator)!" - fi - - return "$HAVE_SUDO_ACCESS" -} - -shell_join() { - local arg - printf "%s" "$1" - shift - for arg in "$@"; do - printf " " - printf "%s" "${arg// /\ }" - done -} - -chomp() { - printf "%s" "${1/"$'\n'"/}" -} - -ohai() { - printf "${tty_blue}==>${tty_bold} %s${tty_reset}\n" "$(shell_join "$@")" -} - -warn() { - printf "${tty_red}Warning${tty_reset}: %s\n" "$(chomp "$1")" -} - -execute() { - if ! "$@"; then - abort "$(printf "Failed during: %s" "$(shell_join "$@")")" - fi -} - -execute_sudo() { - local -a args=("$@") - if have_sudo_access; then - if [[ -n "${SUDO_ASKPASS-}" ]]; then - args=("-A" "${args[@]}") - fi - ohai "/usr/bin/sudo" "${args[@]}" - execute "/usr/bin/sudo" "${args[@]}" - else - ohai "${args[@]}" - execute "${args[@]}" - fi -} - -getc() { - local save_state - save_state=$(/bin/stty -g) - /bin/stty raw -echo - IFS= read -r -n 1 -d '' "$@" - /bin/stty "$save_state" -} - -ring_bell() { - # Use the shell's audible bell. - if [[ -t 1 ]]; then - printf "\a" - fi -} - -wait_for_user() { - local c - echo - echo "Press RETURN to continue or any other key to abort" - getc c - # we test for \r and \n because some stuff does \r instead - if ! [[ "$c" == $'\r' || "$c" == $'\n' ]]; then - exit 1 - fi -} - -major_minor() { - echo "${1%%.*}.$(x="${1#*.}"; echo "${x%%.*}")" -} - -version_gt() { - [[ "${1%.*}" -gt "${2%.*}" ]] || [[ "${1%.*}" -eq "${2%.*}" && "${1#*.}" -gt "${2#*.}" ]] -} -version_ge() { - [[ "${1%.*}" -gt "${2%.*}" ]] || [[ "${1%.*}" -eq "${2%.*}" && "${1#*.}" -ge "${2#*.}" ]] -} -version_lt() { - [[ "${1%.*}" -lt "${2%.*}" ]] || [[ "${1%.*}" -eq "${2%.*}" && "${1#*.}" -lt "${2#*.}" ]] -} - -should_install_command_line_tools() { - if [[ -n "${HOMEBREW_ON_LINUX-}" ]]; then - return 1 - fi - - if version_gt "$macos_version" "10.13"; then - ! [[ -e "/Library/Developer/CommandLineTools/usr/bin/git" ]] - else - ! [[ -e "/Library/Developer/CommandLineTools/usr/bin/git" ]] || - ! [[ -e "/usr/include/iconv.h" ]] - fi -} - -get_permission() { - $STAT "%A" "$1" -} - -user_only_chmod() { - [[ -d "$1" ]] && [[ "$(get_permission "$1")" != "755" ]] -} - -exists_but_not_writable() { - [[ -e "$1" ]] && ! [[ -r "$1" && -w "$1" && -x "$1" ]] -} - -get_owner() { - $STAT "%u" "$1" -} - -file_not_owned() { - [[ "$(get_owner "$1")" != "$(id -u)" ]] -} - -get_group() { - $STAT "%g" "$1" -} - -file_not_grpowned() { - [[ " $(id -G "$USER") " != *" $(get_group "$1") "* ]] -} - -# Please sync with 'test_ruby()' in 'Library/Homebrew/utils/ruby.sh' from Homebrew/brew repository. -test_ruby() { - if [[ ! -x $1 ]] - then - return 1 - fi - - "$1" --enable-frozen-string-literal --disable=gems,did_you_mean,rubyopt -rrubygems -e \ - "abort if Gem::Version.new(RUBY_VERSION.to_s.dup).to_s.split('.').first(2) != \ - Gem::Version.new('$REQUIRED_RUBY_VERSION').to_s.split('.').first(2)" 2>/dev/null -} - -no_usable_ruby() { - local ruby_exec - IFS=$'\n' # Do word splitting on new lines only - for ruby_exec in $(which -a ruby 2>/dev/null); do - if test_ruby "$ruby_exec"; then - IFS=$' \t\n' # Restore IFS to its default value - return 1 - fi - done - IFS=$' \t\n' # Restore IFS to its default value - return 0 -} - -outdated_glibc() { - local glibc_version - glibc_version=$(ldd --version | head -n1 | grep -o '[0-9.]*$' | grep -o '^[0-9]\+\.[0-9]\+') - version_lt "$glibc_version" "$REQUIRED_GLIBC_VERSION" -} - -if [[ -n "${HOMEBREW_ON_LINUX-}" ]] && no_usable_ruby && outdated_glibc -then - abort "$(cat <<-EOFABORT - Homebrew requires Ruby $REQUIRED_RUBY_VERSION which was not found on your system. - Homebrew portable Ruby requires Glibc version $REQUIRED_GLIBC_VERSION or newer, - and your Glibc version is too old. - See ${tty_underline}https://docs.brew.sh/Homebrew-on-Linux#requirements${tty_reset} - Install Ruby $REQUIRED_RUBY_VERSION and add its location to your PATH. - EOFABORT - )" -fi - -# USER isn't always set so provide a fall back for the installer and subprocesses. -if [[ -z "${USER-}" ]]; then - USER="$(chomp "$(id -un)")" - export USER -fi - -# Invalidate sudo timestamp before exiting (if it wasn't active before). -if ! /usr/bin/sudo -n -v 2>/dev/null; then - trap '/usr/bin/sudo -k' EXIT -fi - -# Things can fail later if `pwd` doesn't exist. -# Also sudo prints a warning message for no good reason -cd "/usr" || exit 1 - -####################################################################### script -if ! command -v git >/dev/null; then - abort "$(cat </dev/null; then - abort "$(cat </dev/null; then - ohai "Select the Homebrew installation directory" - echo "- ${tty_bold}Enter your password${tty_reset} to install to ${tty_underline}${HOMEBREW_PREFIX_DEFAULT}${tty_reset} (${tty_bold}recommended${tty_reset})" - echo "- ${tty_bold}Press Control-D${tty_reset} to install to ${tty_underline}$HOME/.linuxbrew${tty_reset}" - echo "- ${tty_bold}Press Control-C${tty_reset} to cancel installation" - fi - if have_sudo_access; then - HOMEBREW_PREFIX="$HOMEBREW_PREFIX_DEFAULT" - else - HOMEBREW_PREFIX="$HOME/.linuxbrew" - fi - trap - SIGINT - fi - HOMEBREW_REPOSITORY="${HOMEBREW_PREFIX}/Homebrew" -fi -HOMEBREW_CORE="${HOMEBREW_REPOSITORY}/Library/Taps/homebrew/homebrew-core" - -if [[ "${EUID:-${UID}}" == "0" ]]; then - # Allow Azure Pipelines/GitHub Actions/Docker/Concourse/Kubernetes to do everything as root (as it's normal there) - if ! [[ -f /proc/1/cgroup ]] || - ! grep -E "azpl_job|actions_job|docker|garden|kubepods" -q /proc/1/cgroup; then - abort "Don't run this as root!" - fi -fi - -if [[ -d "${HOMEBREW_PREFIX}" && ! -x "${HOMEBREW_PREFIX}" ]]; then - abort "$(cat </dev/null || return - - # we do it in four steps to avoid merge errors when reinstalling - execute "git" "init" "-q" - - # "git remote add" will fail if the remote is defined in the global config - execute "git" "config" "remote.origin.url" "${HOMEBREW_BREW_GIT_REMOTE}" - execute "git" "config" "remote.origin.fetch" "+refs/heads/*:refs/remotes/origin/*" - - # ensure we don't munge line endings on checkout - execute "git" "config" "core.autocrlf" "false" - - execute "git" "fetch" "--force" "origin" - execute "git" "fetch" "--force" "--tags" "origin" - - execute "git" "reset" "--hard" "origin/master" - - if [[ "${HOMEBREW_REPOSITORY}" != "${HOMEBREW_PREFIX}" ]]; then - execute "ln" "-sf" "${HOMEBREW_REPOSITORY}/bin/brew" "${HOMEBREW_PREFIX}/bin/brew" - fi - - if [[ ! -d "${HOMEBREW_CORE}" ]]; then - ohai "Tapping homebrew/core" - ( - execute "/bin/mkdir" "-p" "${HOMEBREW_CORE}" - cd "${HOMEBREW_CORE}" >/dev/null || return - - execute "git" "init" "-q" - execute "git" "config" "remote.origin.url" "${HOMEBREW_CORE_GIT_REMOTE}" - execute "git" "config" "remote.origin.fetch" "+refs/heads/*:refs/remotes/origin/*" - execute "git" "config" "core.autocrlf" "false" - execute "git" "fetch" "--force" "origin" "refs/heads/master:refs/remotes/origin/master" - execute "git" "remote" "set-head" "origin" "--auto" >/dev/null - execute "git" "reset" "--hard" "origin/master" - - cd "${HOMEBREW_REPOSITORY}" >/dev/null || return - ) || exit 1 - fi - - execute "${HOMEBREW_PREFIX}/bin/brew" "update" "--force" "--quiet" -) || exit 1 - -if [[ ":${PATH}:" != *":${HOMEBREW_PREFIX}/bin:"* ]]; then - warn "${HOMEBREW_PREFIX}/bin is not in your PATH." -fi - -ohai "Installation successful!" -echo - -ring_bell - -# Use an extra newline and bold to avoid this being missed. -ohai "Homebrew has enabled anonymous aggregate formulae and cask analytics." -echo "$(cat </dev/null || return - execute "git" "config" "--replace-all" "homebrew.analyticsmessage" "true" - execute "git" "config" "--replace-all" "homebrew.caskanalyticsmessage" "true" -) || exit 1 - -ohai "Next steps:" -case "$SHELL" in - */bash*) - if [[ -r "$HOME/.bash_profile" ]]; then - shell_profile="$HOME/.bash_profile" - else - shell_profile="$HOME/.profile" - fi - ;; - */zsh*) - shell_profile="$HOME/.zprofile" - ;; - *) - shell_profile="$HOME/.profile" - ;; -esac -if [[ "$UNAME_MACHINE" == "arm64" ]] || [[ -n "${HOMEBREW_ON_LINUX-}" ]]; then - cat <> ${shell_profile} - eval "\$(${HOMEBREW_PREFIX}/bin/brew shellenv)" -EOS -fi -if [[ -n "${non_default_repos}" ]]; then - s="" - if [[ "${#additional_shellenv_commands[@]}" -gt 1 ]]; then - s="s" - fi - echo "- Add the non-default Git remote${s} for ${non_default_repos} in ${tty_underline}${shell_profile}${tty_reset}:" - printf " echo '%s' >> ${shell_profile}\n" "${additional_shellenv_commands[@]}" - printf " %s\n" "${additional_shellenv_commands[@]}" -fi - -echo "- Run \`brew help\` to get started" -echo "- Further documentation: " -echo " ${tty_underline}https://docs.brew.sh${tty_reset}" - -if [[ -n "${HOMEBREW_ON_LINUX-}" ]]; then - echo "- Install the Homebrew dependencies if you have sudo access:" - - if [[ $(command -v apt-get) ]]; then - echo " sudo apt-get install build-essential" - elif [[ $(command -v yum) ]]; then - echo " sudo yum groupinstall 'Development Tools'" - elif [[ $(command -v pacman) ]]; then - echo " sudo pacman -S base-devel" - elif [[ $(command -v apk) ]]; then - echo " sudo apk add build-base" - fi - - cat < $* ${RESET}" -} - -echoStageNameAdd() { - echo "${BOLD} $* ${RESET}" -} - -warn() { - echo "${YELLOW}warning: $* ${RESET}" -} - -error() { - # this will be long, so I must do "&& exit 1" manually - echo "${RED}error: $* ${RESET}" -} - -success() { - echo "${GREEN}success: $* ${RESET}" -} - -info() { - echo "info: $*" -} - -checkOs() { - # This step is required for different actions, like installing deps from system-wide package managers - # among other sorts of shitfuckery. We may need to also run tests through the CI to ensure nothing breaks. - if echo "$OSTYPE" | grep -qE "linux-android.*"; then - export DOTFILES_OS_NAME=android-termux - elif echo "$OSTYPE" | grep -qE '^linux-gnu.*' && [ "$(lsb_release -is)" == "Debian" ]; then - export DOTFILES_OS_NAME=debian - if [ -d '/google/devshell' ] && [ -f '/google/devshell/bashrc.google' ]; then - export GOOGLE_CLOUD_SHELL=true - fi - elif $OSTYPE | grep -qE '^linux-gnu.*' && [ "$(lsb_release -is)" == "Ubuntu" ]; then - export DOTFILES_OS_NAME=ubuntu - else - error "Script unsupported for this specific distro. If this was an downstream fork of another repo, you could override" - error "the DOTFILES_OS_NAME variable" - fi -} - -setupSysPkgs() { - echoStageName "Installating essiential dependencies" - if [[ $DOTFILES_OS_NAME == "android-termux" ]] && [[ $SKIP_DEPENDENCY_INSTALL == "" ]]; then - pkg install -y man git nano gnupg openssh proot resolv-conf asciinema openssl-tool pass - setupGhCli - setupGLabCli - elif [[ $DOTFILES_OS_NAME == "debian" ]] && [[ $SKIP_DEPENDENCY_INSTALL == "" ]]; then - sudo apt install gnupg git nano pass openssh-client -y - setupGhCli - setupGLabCli - elif [[ $DOTFILES_OS_NAME == "ubuntu" ]] && [[ $SKIP_DEPENDENCY_INSTALL == "" ]]; then - sudo apt install gnupg nano pass openssh-client -y - setupGhCli - setupGLabCli - else - warn "Dependency installs are being skipped" - fi - sleep 5 -} - -setupAsdf() { - warn WIP -} - -setupNode() { - if [[ $USE_NVM == "1" ]]; then - echoStagName "Installing Node.js Version Manager" - $(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 - fi -} - -setupPython() { - if [[ $USE_PYENV == "1" ]]; then - 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" - if [[ $DOTFILES_OS_NAME == "debian" ]] || [[ $DOTFILES_OS_NAME == "ubuntu" ]]; then - sudo apt-get update; sudo apt-get install make build-essential libssl-dev zlib1g-dev libbz2-dev libreadline-dev libsqlite3-dev llvm libncursesw5-dev xz-utils tk-dev libxml2-dev libxmlsec1-dev libffi-dev liblzma-dev -y - fi - echoStageName "Installing Python3 through Pyenv" - "${PYENV_ROOT}/bin/pyenv" install 3.9.6 - "${PYENV_ROOT}/bin/pyenv" global 3.9.6 - elif [[ $UPDATE_SYSTEM_PYTHON_INSTALL != "" ]]; then - echoStageName "Updating Python install" - sudo apt install python3 python3-pip --yes - fi -} - -userspcaeBinDirCheck() { - echoStageName "checking if PREFIX/bin exists" - if [ ! -d "$PREFIX/bin" ]; then - warn "$PREFIX/bin doesn't exists, creating..." - mkdir -p "$PREFIX/bin" - else - success "Looks good! $PREFIX/bin directory exists." - fi -} - -cloneRepo() { - if [ ! -d "$DOTFILES_PATH" ]; then - echoStageName "Cloning the dotfiles repo" - git clone https://github.com/ajhalili2006/dotfiles.git $DOTFILES_PATH - else - echoStageName "Dotfiles repo found, pulling remote changes instead" - git -C "$DOTFILES_PATH" fetch --all - git -C "$DOTFILES_PATH" pull origin - fi - sleep 5 -} - -# Decouple secrets repo cloning process from the main -cloneSecretsRepo() { - case $FF_UNENCRYPTED_SECRETS_REPO in - "true") ;; - *) - warn "Cloning your unencrypted secrets repo to $DOTFILES_PATH/secrets is no longer supported. Please set FF_UNENCRYPTED_SECRETS_REPO" - warn "variable or migrate your secrets to PasswordStore to avoid disruptions. In meanwhile, this script will setup GPG for you" - return - ;; - esac - - # 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 "$DOTFILES_PATH/secrets" ]; then - warn "GitLab login and token is blank, skipping..." && true - # Probably change my GitLab SaaS username with yours - elif [[ $GITLAB_LOGIN != "ajhalili2006" ]] && [ ! -d "$DOTFILES_PATH/secrets" ]; then - warn "Only Andrei Jiroh can do this!" && true - elif [[ $GITLAB_LOGIN == "ajhalili2006" ]] && [[ $GITLAB_TOKEN == "" ]] && [ ! -d "$DOTFILES_PATH/secrets" ]; then - warn "Missing GitLab SaaS PAT! Check your Bitwarden vault for that PAT with atleast read_repository scope, or use GitHub mirror instead." - else - if [ ! -d "$DOTFILES_PATH/secrets" ]; then - echoStageName "Cloning secrets repo" "$DOTFILES_PATH/secrets" - warn "The unencrypted secrets repo is currently deprecated and may be removed from the bootstrapping process. Please migrate to" - warn "Pass" - if [[ $USE_GH_SECRETS_MIRROR != "" ]]; then - gh repo clone ajhalili2006/dotfiles-secrets "$DOTFILES_PATH/secrets" - elif ! glab repo clone $HOME/.dotfiles/secrets; then - warn "There was an problem while cloning the repo, please check the credentials and try again" - warn "gracefully skipping this step" - fi - chmod 760 "$DOTFILES_PATH/secrets" - #git -C "$DOTFILES_PATH/secrets" remote set-url origin git@gitlab.com:ajhalili2006/dotfiles-secrets - elif [[ -d "$DOTFILES_PATH/secrets" ]] ; then - chmod 760 "$DOTFILES_PATH/secrets" - git -C "$DOTFILES_PATH/secrets" fetch --all - git -C "$DOTFILES_PATH/secrets" pull - fi - fi - sleep 5 -} - -# TODO: Check whenever Linuxbrew is installed and use local Homebrew install instead when detected. -# TODO: If installed using this script via FF_SETUP_HOMEBREW environment variable, defaults to -# TODO: /home/linuxbrew/.nrew as per my bashrc and zshrc files. -# Install GitHub CLI if we're gonna use that GitHub mirror -setupGhCli() { - if command -v gh >>/dev/null; then - info "GitHub CLI installed for this environment, skipping system package manager setup" - return - fi - - if [[ $DOTFILES_OS_NAME == "android-termux" ]]; then - pkg install gh # TODO: check Linux install docs in cli/cli - elif [[ $DOTFILES_OS_NAME == "debian" || $DOTFILES_OS_NAME == "ubuntu" ]] && ! command -v gh >> /dev/null; 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 -} -# Also setup GLab CLI too -setupGLabCli() { - if command -v glab >>/dev/null; then - info "GLab CLI installed for this environment, skipping running scripts from Git repo rawfile/Termux pkgrepo" - return - fi - - if [[ "$DOTFILES_OS_NAME" == "android-termux" ]]; then - warn "GLab CLI is currently unavailable on Termux package repos yet." - return - #pkg install glab - else - curl -fsSL https://raw.githubusercontent.com/profclems/glab/trunk/scripts/install.sh | sh - "$PREFIX" - fi -} - -cleanup() { - echoStageName "Bootstrapper successfully ran, cleaning up to ensure no secrets are leaked on env vars..." - # just add chaos to these secrets to avoid leaks - export GITLAB_LOGIN=gildedguy - export GITLAB_TOKEN=build-guid-sus-among-computers-moment - if echo "$OSTYPE" | grep -qE "linux-android.*"; then - rm -rfv ~/{shellcheck,flarectl,LICENSE,README.txt,README.md} - pkg uninstall clang --yes && apt autoremove --yes - else - rm -rfv ~/{shellcheck,flarectl,LICENSE,README.txt,README.md}* || true - unset PREFIX - fi - 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." - [[ $GOOGLE_CLOUD_SHELL == "true" ]] && warn "Looks like you're on Google Cloud Shell, please restart your virtual machine for changes to take effect." - sleep 2 - unset DOTFILES_OS_NAME GOOGLE_CLOUD_SHELL - exit -} - -setupSshConfig() { - 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.*'; then - [ ! -f "$HOME/.ssh/config" ] && ln -s "$HOME/.dotfiles/ssh-client/linux" "$HOME/.ssh/config" - fi - sleep 5 -} - -copyBashrc() { - if [[ $DOTFILES_OS_NAME == "android-termux" ]]; then - ln -s $HOME/.dotfiles/termux.bashrc ~/.bashrc - elif [[ $DOTFILES_OS_NAME == "debian" ]] || [[ $DOTFILES_OS_NAME == "ubuntu" ]]; then - if [[ $SKIP_CONFIG_LINKING == "" ]] && [ ! -f "$HOME/.bashrc" ]; then - ln -s "$HOME/.dotfiles/ubuntu.bashrc" ~/.bashrc - elif [[ $GOOGLE_CLOUD_SHELL == "true" ]] && [[ $SKIP_CONFIG_LINKING == "" ]] && [ -f "$HOME/.bashrc" ]; then - rm "$HOME/.bashrc" - ln -s "$HOME/.dotfiles/bashrc/googlecloudshell.bashrc" "$HOME/.bashrc" - elif [[ $SKIP_CONFIG_LINKING == "" ]] && [ -f "$HOME/.bashrc" ]; then - 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" - fi - fi - fi -} - -copyGitConfig() { - echoStageName "Symlinking Git config" - if [[ $DOTFILES_OS_NAME == "android-termux" ]] && [[ $SKIP_CONFIG_LINKING == "" ]]; then - [ ! -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!" - # TODO: Write checks if it's Ubuntu or Debian - # See https://superuser.com/a/741610/1124908 for details - # By default, we'll use the one-size-fits-all Linux config for Git - elif echo $OSTYPE | grep -qE '^linux-gnu.*' && [[ $SKIP_CONFIG_LINKING == "" ]]; then - [ ! -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!" - fi -} - -copyNanoConfig() { - echoStagename "Symlinking GNU nano config file" - if [[ $DOTFILES_OS_NAME == "android-termux" ]]; then - [ "$SKIP_CONFIG_LINKING" == "" ] && ln -s "$HOME/.dotfiles/nanorc/config/termux" "$HOME/.nanorc" - else - [ "$SKIP_CONFIG_LINKING" == "" ] && [ ! -L "$HOME/.gitconfig" ] && ln -s "$HOME/.dotfiles/nanorc/config/linux.nanorc" "$HOME/.nanorc" - fi - -} - -setupSC() { - echoStageName "Installing Shellcheck" - - scversion="stable" - case $(uname -m) in - amd64) SHELLCHECK_ARCHIVE_URL="https://github.com/koalaman/shellcheck/releases/download/${scversion?}/shellcheck-${scversion?}.linux.x86_64.tar.xz";; - aarch64) SHELLCHECK_ARCHIVE_URL="https://github.com/koalaman/shellcheck/releases/download/${scversion?}/shellcheck-${scversion?}.linux.aarch64.tar.xz";; - *) warn "ShellCheck release binaries from GitHub is probably unsupported, try using your system package manager instead." && return;; - esac - if [[ $SKIP_DEPENDENCY_INSTAL == "" ]]; then - current_shellcheck_path=$(command -v shellcheck) - isOwnedByUser="$(find $PREFIX/bin -user $USER -name shellcheck)" - current_path_dir="$(dirname $current_shellcheck_path)" - wget -qO- "$SHELLCHECK_ARCHIVE_URL" | tar -xJv -C "$HOME" - if [[ $current_shellcheck_path == "" ]]; then - cp "$HOME/shellcheck-${scversion}/shellcheck" "$PREFIX/bin" - elif [[ $current_shellcheck_path == "$PREFIX/bin/shellcheck" ]]; then - warn "Current ShellCheck install found in $PREFIX/bin, replacing with latest stable release..." - if [[ $isOwnedByUser == "" ]]; then - [ -f "$PREFIX/bin/shellcheck" ] && warn "Owned by either other user/root, summoning root" && sudo rm "${PREFIX}/bin/shellcheck" - else - rm "${PREFIX}/bin/shellcheck" - fi - cp "$HOME/shellcheck-${scversion}/shellcheck" "$PREFIX/bin" - else - warn "Current ShellCheck install found in $current_path_dir, will be removed..." - if [[ $isOwnedByUser == "" ]]; then - warn "Owned by either other user/root, summoning root" - sudo rm "$current_path_dir/shellcheck" - else - rm "${PREFIX}/bin/shellcheck" - fi - cp "$HOME/shellcheck-${scversion}/shellcheck" "$PREFIX/bin" - fi - else - warn "Shellcheck install/upgrade is being skipped!" - fi -} - -setupAscinema() { - echoStageName "Installing Asciinema" - if [[ $DOTFILES_OS_NAME == "android-termux" ]] && [[ $SKIP_DEPENDENCY_INSTALL == "" ]]; then - pkg install aciinema -y - 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 - pip3 install asciinema --user --upgrade - fi - fi -} - -setupTF() { - echoStageName "Installing pip3:thefuck" - if [[ $DOTFILES_OS_NAME == "android-termux" ]]; then - pkg install clang -y && pip install thefuck --user --upgrade - else - # TODO: Also handle asdf shims - if command -v python3>>/dev/null && [ -f "$HOME/.pyenv/shims/python3" ]; then - "$HOME/.pyenv/shims/pip3" install thefuck --upgrade - else - pip3 install thefuck --user --upgrade - fi - fi -} - -setupFilterRepo() { - echoStageName "Installing pip3:git-filter-repo" - if [[ $DOTFILES_OS_NAME == "android-termux" ]]; then - pip install git-filter-repo --upgrade - else - # TODO: handle asdf shims and other version mgnrs for Python - if command -v python3>>/dev/null && [ -f "$HOME/.pyenv/shims/python3" ]; then - "$HOME/.pyenv/shims/pip3" install git-filter-repo --upgrade - else - pip3 install git-filter-repo --user --upgrade - fi - fi -} - -# usage stuff -usage() { - echo "Accepted bootstrap script arguments are:" - echo " * --help|-h - Show this text." - echo " * -i|--skip-install-packages - Skip installing different dependencies and packages" - echo " * -d|--debug - Enable debugging" - echo " * -l|--config-symlink - Skip symlinking config files (nanorc, bashrc, etc.)" - echo " * --deprecated-secrets-repo - Clone also deprecated dotfiles-secrets repo, alongside the" - echo " experimential personal PasswordStore git repo" -} - -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 - - ln -s ~/.dotfiles/.config/devshell.env ~/.customize_environment && chmod +x ~/.customize_environment - if [ ! -d "$HOME/.cloudshell" ]; then - mkdir "$HOME/.cloudshell" - fi - if [ ! -f "$HOME/.cloudshell/no-apt-get-warning" ]; then - touch "$HOME/.cloudshell/no-apt-get-warning" - fi - - echoStageName "Running ~/.customize_environment for you" - sudo "$HOME/.customize_environment" -} - -# 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. - echoStageName "Installing Code Server" - curl -fsSL https://code-server.dev/install.sh | sh - fi - if [[ $XDG_CURRENT_DESKTOP != "" ]]; then - true # It's true for now - #echo "Installing VS Code from Microsoft" - # TODO - fi -} - -importGpgKeys() { - if [[ $STORJ_ACCESS_GRANT == "" ]]; then - warn "Storj DCS access grant is missing, skipping gpg keys import" - return - fi +if ! command -v git >>/dev/null; then - BASE_URL="https://link.eu1.storjshare.io/s" - BUCKET_PATH="ajhalili2006-files-private/gpg-key-backups" - PERSONAL_KEY_URL="$BASE_URL/$STORJ_ACCESS_GRANT/$BUCKET_PATH/personal-main-backup.gpg?download=1" - PASSWORD_STORE_KEY_URL="$BASE_URL/$STORJ_ACCESS_GRANT/$BUCKET_PATH/personal-passwordstore-backup.gpg?download=1" - OSS_RELEASES_PERSONAL_KEY_URL="$BASE_URL/$STORJ_ACCESS_GRANT/$BUCKET_PATH/personal-releases-backup.gpg?download=1" - mkdir -p /tmp/keys-import-tmp # TODO: check if /dev/shm is usuable and use that dir instead for security reasons - wget $PERSONAL_KEY_URL -O /tmp/keys-import-tmp/personal - wget $PASSWORD_STORE_KEY_URL -O /tmp/keys-import-tmp/password-store - wget $OSS_RELEASES_PERSONAL_KEY_URL -O /tmp/keys-import-tmp/releases-key - gpg --batch --no-tty --yes --import /tmp/keys-import-tmp/personal - gpg --batch --no-tty --yes --import /tmp/keys-import-tmp/password-store - gpg --batch --no-tty --yes --import /tmp/keys-import-tmp/releases-key -} +fi -importSshKeys() { - if [[ -d "$DOTFILES_PATH/secrets" ]]; then - true - elif [[ -d "$PASSWORD_STORE_DIR" ]]; then - pass show keys/ssh/personal | tee ~/.ssh/personal >>/dev/null - pass show keys/ssh/recaptime.dev | tee ~/.ssh/ajhalili2006.recaptime.dev >> /dev/null - fi -} +DOTFILES_HOME=${DOTFILES_HOME:-"$HOME/.odtfiles"} +DOTFILES_GIT_MIRROR=${DOTFILES_GIT_MIRROR:-"https://gitlab.com/ajhalili2006/dotfiles"} -main() { - # 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 +if [[ ! -d "$DOTFILES_HOME" ]]; then + git clone "$DOTFILES_GIT_MIRROR" "$DOTFILES_HOME" +else + git -C "$DOTFILES_HOME" pull +fi - # import colors and show the banner - useColor - banner - - # step 1: check the OS first - checkOs - - # step 2: install needed tools and create ~/.local/bin - setupSysPkg - userspcaeBinDirCheck - - # step 3.1: then clone the repo - cloneRepo - - # step 3.2: if we're in Cloud Shell, do this - [[ $GOOGLE_CLOUD_SHELL == "true" ]] && customizeCloudShell - - # step 4: install additional needed tools - setupAscinema - setupTF - setupFilterRepo - setupSC - setupNodejs - installCode - - # step 5: copy and symlink files - copyGitConfig - copyNanoConfig - copyBashrc - setupSshConfig - - # step 5.2: copy our secrets btw - cloneSecretsRepo # Run this before we even copy the ssh keys! - importGpgKeys - importSshKeys - - # step 6: finally clean up BS ScoMo from marketing did - cleanup -} - -main "$@" - -} # curybrackets is included to ensure everything is downloaded +} \ No newline at end of file diff --git a/bashrc/aliases b/config/bashrc/aliases similarity index 100% rename from bashrc/aliases rename to config/bashrc/aliases diff --git a/config/bashrc/chain-source b/config/bashrc/chain-source new file mode 100644 index 0000000..5f9d539 --- /dev/null +++ b/config/bashrc/chain-source @@ -0,0 +1,6 @@ +#!/bin/bash + +# these commands should be triggered on shell startup +source "$DOTFILES_HOME/config/bashrc/aliases" +source "$DOTFILES_HOME/config/bashrc/worthwhile-functions" +#guild-test diff --git a/bashrc/google.bashrc b/config/bashrc/google.bashrc similarity index 100% rename from bashrc/google.bashrc rename to config/bashrc/google.bashrc diff --git a/bashrc/googlecloudshell.bashrc b/config/bashrc/googlecloudshell.bashrc similarity index 100% rename from bashrc/googlecloudshell.bashrc rename to config/bashrc/googlecloudshell.bashrc diff --git a/bashrc/termux b/config/bashrc/termux similarity index 100% rename from bashrc/termux rename to config/bashrc/termux diff --git a/bashrc/ubuntu.bashrc b/config/bashrc/ubuntu.bashrc similarity index 90% rename from bashrc/ubuntu.bashrc rename to config/bashrc/ubuntu.bashrc index cee5187..d308362 100644 --- a/bashrc/ubuntu.bashrc +++ b/config/bashrc/ubuntu.bashrc @@ -19,8 +19,8 @@ HISTCONTROL=ignoreboth shopt -s histappend # for setting history length see HISTSIZE and HISTFILESIZE in bash(1) -HISTSIZE=1000 -HISTFILESIZE=2000 +HISTSIZE=10000 +HISTFILESIZE=10000 # check the window size after each command and, if necessary, # update the values of LINES and COLUMNS. @@ -130,8 +130,8 @@ export PATH="$HOME/.deta/bin:$PATH" # scripts in ~/.local/bin and ~/.dotfiles/bin # also $HOME/.cargo/bin export DOTFILES_HOME="$HOME/.dotfiles" -export DOTFILES_STUFF_BIN="$DOTFILES_HOME/bin" GOLANG_PATH=/usr/local/go/bin -export PATH="$HOME/.local/bin:$HOME/.cargo/bin:$GOLANG_PATH:$DOTFILES_STUFF_BIN:$PATH" +export DOTFILES_STUFF_BIN="$DOTFILES_HOME/bin" +export PATH="$HOME/.local/bin:$HOME/.cargo/bin:$DOTFILES_STUFF_BIN:$PATH" # use nano instead of vi by default when on SSH # for git, there's the option of firing up VS Code, if you prefered. @@ -152,18 +152,18 @@ fi # As long as possible, attempt to setup our GnuPG agent when we're on an SSH session. if [[ -n "$SSH_CLIENT" ]] || [[ -n "$SSH_TTY" ]]; then - eval $(keychain --agents gpg,ssh --eval --nogui --noinherit) + eval $(keychain --agents gpg,ssh --eval --nogui --noinherit) || true export GPG_TTY=$(tty) else # We'll do some checks here btw, Currently I use GNOME and Xfce4 as my desktop environments case $(ps -o comm= -p $PPID) in # Sometimes, $SSH_CLIENT and/or $SSH_TTY doesn't exists so we'll pull what ps says - sshd | */sshd) eval $(keychain --agents gpg,ssh --eval --nogui --noinherit);; - xfce*) eval $(keychain --agents gpg,ssh --eval);; - gnome*) eval $(keychain --agents gpg,ssh --eval);; + sshd | */sshd) eval $(keychain --agents gpg,ssh --eval --nogui --noinherit) || true;; + xfce*) eval $(keychain --agents gpg,ssh --eval) || true;; + gnome*) eval $(keychain --agents gpg,ssh --eval) || true;; # Don't forget VS Code and code-server! - code) eval $(keychain --agents gpg,ssh --eval);; - *) eval $(keychain --agents gpg,ssh --eval --nogui --noinherit) ;; + code) eval $(keychain --agents gpg,ssh --eval) || true;; + *) eval $(keychain --agents gpg,ssh --eval --nogui --noinherit) || true;; esac fi @@ -172,7 +172,7 @@ eval "$(gh completion -s bash)" # custom aliases and functions I made # sorucing through the chain-source script -source "$HOME/.dotfiles/bashrc/chain-source" +source "$DOTFILES_HOME/config/bashrc/chain-source" # TODO: Remove guild-test stuff # https://packaging.ubuntu.com/html/getting-set-up.html#configure-your-shell export DEBFULLNAME="Andrei Jiroh Halili" @@ -184,7 +184,7 @@ export DEBEMAIL="ajhalili2006@gmail.com" test -d /home/linuxbrew/.linuxbrew && eval "$(/home/linuxbrew/.linuxbrew/bin/brew shellenv)" # Golang, probably we need to tweak this btw -export PATH=/home/gildedguy/go/bin:$PATH GOPATH=/home/gildedguy/go +export PATH="$HOME/go/bin:$PATH" GOPATH="$HOME/go" # Use native builds when doing 'docker build' instead of 'docker buildx build' export DOCKER_BUILDKIT=1 @@ -197,4 +197,6 @@ eval "$(direnv hook bash)" # Don't install gems globally, that would be chaos for file permissions export GEM_HOME="$HOME/.gems" PATH="$HOME/.gems/bin:$PATH" -source "/home/gildedguy/.bashbox/env"; + +# bashbox +[ -s "$HOME/.bashbox/env" ] && source "$HOME/.bashbox/env"; diff --git a/bashrc/worthwhile-functions b/config/bashrc/worthwhile-functions similarity index 100% rename from bashrc/worthwhile-functions rename to config/bashrc/worthwhile-functions diff --git a/linux.gitconfig b/linux.gitconfig deleted file mode 120000 index daf9bcf..0000000 --- a/linux.gitconfig +++ /dev/null @@ -1 +0,0 @@ -gitconfig/linux \ No newline at end of file diff --git a/no-gpg.gitconfig b/no-gpg.gitconfig deleted file mode 100755 index fc7d6ce..0000000 --- a/no-gpg.gitconfig +++ /dev/null @@ -1,71 +0,0 @@ -# Git Credential handlers with GitHub/GLab CLI -[credential "https://github.com"] - helper = !gh auth git-credential -[credential "https://gitlab.com"] - helper = !glab auth git-credential -[credential "https://gitlab.alpinelinux.org"] - helper = !glab auth git-credential -[credential "https://salsa.debian.org"] - helper = !glab auth git-credential -[credential "https://mau.dev"] - helper = !glab auth git-credential -# User config -[user] - email = ajhalili2006@gmail.com - name = Andrei Jiroh Eugenio Halili - #signingkey = A30EBE40AD856D88 - -#[merge] -# tool = vscode -#[mergetool "vscode"] -# cmd = code --wait $MERGED -#[diff] -# tool = vscode -#[difftool "vscode"] -# cmd = code --wait --diff $LOCAL $REMOTE - -# Commit settings -[commit] - #gpgsign = true - -# Enforce SSH -# We commented thus block out coz we use the GitHub CLI's Git Credential -# helper stuff -#[url "git@github.com:"] -# insteadOf = https://github.com/ -# pushInsteadOf = https://github.com/ -[url "git+ssh://ajhalili2006@git.launchpad.net/"] - insteadof = lp: - pushInsteadOf = lp: -[url "git@bitbucket.org:"] - insteadOf = https://bitbucket.org/ -[init] - defaultBranch = main -# TODO: Set up aliases for ther Git hosts, like in Launchpad.net - -# aliases -[alias] - #change-commits = "!f() { VAR=$1; OLD=$2; NEW=$3; shift 3; git filter-branch --env-filter \"if [[ \\\"$`echo $VAR`\\\" = '$OLD' ]]; then export $VAR='$NEW'; fi\" $@; }; f" - signoff = "commit --signoff" - ammend = "commit --amend" - stage = "add" - unstage = "restore --staged" - stats = "status" - sdiff = !git diff && git submodule foreach 'git diff' - spush = push --recurse-submodules=on-demand - supdate = submodule update --remote --merge - skipCi = push -o ci.skip - root = rev-parse --show-toplevel - -# LFS -[filter "lfs"] - clean = git-lfs clean -- %f - smudge = git-lfs smudge -- %f - process = git-lfs filter-process - required = true - -# pull -[pull] - rebase = true -[push] - recurseSubmodules = check diff --git a/termux.bashrc b/termux.bashrc deleted file mode 120000 index a133b1d..0000000 --- a/termux.bashrc +++ /dev/null @@ -1 +0,0 @@ -bashrc/termux \ No newline at end of file diff --git a/termux.gitconfig b/termux.gitconfig deleted file mode 120000 index b2b6ee7..0000000 --- a/termux.gitconfig +++ /dev/null @@ -1 +0,0 @@ -gitconfig/termux \ No newline at end of file diff --git a/tools/bootstrap-utils/.gitkeep b/tools/bootstrap-utils/.gitkeep new file mode 100644 index 0000000..e69de29 diff --git a/tools/bootstrap-utils/00-script-library.sh b/tools/bootstrap-utils/00-script-library.sh new file mode 100644 index 0000000..fc0c36d --- /dev/null +++ b/tools/bootstrap-utils/00-script-library.sh @@ -0,0 +1,21 @@ +#!/usr/bin/env bash +# Library code for the bootstrap scripts + +# Adding colors to some text in termnial based on checks +if [ -t 1 ] && [[ "$NO_COLOR" == "" ]]; then + 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') +else + RED="" + GREEN="" + YELLOW="" + BLUE="" + MAGENTA="" + BOLD="" + RESET="" +fi \ No newline at end of file diff --git a/tools/bootstrap-utils/10-config-symlinking.sh b/tools/bootstrap-utils/10-config-symlinking.sh new file mode 100644 index 0000000..ddaa96c --- /dev/null +++ b/tools/bootstrap-utils/10-config-symlinking.sh @@ -0,0 +1,22 @@ +#!/usr/bin/env bash + +if [[ $DOTFILES_OS_NAME == "android-termux" ]]; then + if [ ! -f "$HOME/.bashrc" ]; then + ln -s $HOME/.dotfiles/termux.bashrc ~/.bashrc + elif [ -f "$HOME/.bashrc" ]; then +elif [[ $DOTFILES_OS_NAME == "debian" ]] || [[ $DOTFILES_OS_NAME == "ubuntu" ]]; then + if [[ $SKIP_CONFIG_LINKING == "" ]] && [ ! -f "$HOME/.bashrc" ]; then + ln -s "$HOME/.dotfiles/ubuntu.bashrc" ~/.bashrc + elif [[ $GOOGLE_CLOUD_SHELL == "true" ]] && [[ $SKIP_CONFIG_LINKING == "" ]] && [ -f "$HOME/.bashrc" ]; then + cp "$HOME/.bashrc" "$HOME/.bashrc.bak" + ln -s "$HOME/.dotfiles/bashrc/googlecloudshell.bashrc" "$HOME/.bashrc" + elif [[ $SKIP_CONFIG_LINKING == "" ]] && [ -f "$HOME/.bashrc" ]; then + if [[ -L "$HOME/.bashrc" ]]; then + warn "$HOME/.bashrc is currently symlinked somewhere, 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" + fi + fi +fi \ No newline at end of file diff --git a/ubuntu.bashrc b/ubuntu.bashrc deleted file mode 120000 index d767056..0000000 --- a/ubuntu.bashrc +++ /dev/null @@ -1 +0,0 @@ -bashrc/ubuntu.bashrc \ No newline at end of file diff --git a/wsl.gitconfig b/wsl.gitconfig deleted file mode 120000 index fb03cc7..0000000 --- a/wsl.gitconfig +++ /dev/null @@ -1 +0,0 @@ -gitconfig/wsl \ No newline at end of file