diff --git a/setup/0-pre-config.sh b/setup/0-pre-config.sh index ab09ff0..accfe6f 100755 --- a/setup/0-pre-config.sh +++ b/setup/0-pre-config.sh @@ -12,6 +12,8 @@ case "${response}" in esac echo '' +# ---------------------------------------------------------- + read -p 'Enable available aliases within your ~/.bashrc? [y/N]: ' response case "${response}" in [Yy]* ) @@ -24,3 +26,91 @@ case "${response}" in esac echo '' +# ---------------------------------------------------------- + +read -p 'Install scripts into your ~/bin? [y/N]: ' response +case "${response}" in + [Yy]* ) + # setup symlinks, if not installed in users bin directory + # need absolute path, so the symbolic links will be created correctly. + script_dir=$(readlink -f "$0" | xargs dirname | xargs dirname) + + # --- home bin folder --- + if [[ ! -d "${HOME}/bin" ]]; then + echo 'making personal bin directory' + mkdir -p "${HOME}/bin" + fi + + # --- general scripts --- + if [[ ! -f "${HOME}/bin/4-public-ip.sh" ]]; then + echo 'installing 4-public-ip.sh' + ln -s "${script_dir}/4-public-ip.sh" "${HOME}/bin/4-public-ip.sh" + fi + + if [[ ! -f "${HOME}/bin/6-public-ip.sh" ]]; then + echo 'installing 6-public-ip.sh' + ln -s "${script_dir}/6-public-ip.sh" "${HOME}/bin/6-public-ip.sh" + fi + + if [[ ! -f "${HOME}/bin/docker-ps.sh" ]]; then + echo 'installing docker-ps.sh' + ln -s "${script_dir}/docker-ps.sh" "${HOME}/bin/docker-ps.sh" + fi + + if [[ ! -f "${HOME}/bin/delay.sh" ]]; then + echo 'installing delay.sh' + ln -s "${script_dir}/delay.sh" "${HOME}/bin/delay.sh" + fi + + if [[ ! -f "${HOME}/bin/enumerate.sh" ]]; then + echo 'installing enumerate.sh' + ln -s "${script_dir}/enumerate.sh" "${HOME}/bin/enumerate.sh" + fi + + if [[ ! -f "${HOME}/bin/is-restart-needed.sh" ]]; then + echo 'installing is-restart-needed.sh' + ln -s "${script_dir}/is-restart-needed.sh" "${HOME}/bin/is-restart-needed.sh" + fi + + if [[ ! -f "${HOME}/bin/named-cat.sh" ]]; then + echo 'installing named-cat.sh' + ln -s "${script_dir}/named-cat.sh" "${HOME}/bin/named-cat.sh" + fi + + if [[ ! -f "${HOME}/bin/restart-if-needed.sh" ]]; then + echo 'installing restart-if-needed.sh' + ln -s "${script_dir}/restart-if-needed.sh" "${HOME}/bin/restart-if-needed.sh" + fi + + if [[ ! -f "${HOME}/bin/upgrade.sh" ]]; then + echo 'installing upgrade.sh' + ln -s "${script_dir}/upgrade.sh" "${HOME}/bin/upgrade.sh" + fi + + # --- git related scripts --- + if [[ ! -f "${HOME}/bin/fetch-all.sh" ]]; then + echo 'installing fetch-all.sh' + ln -s "${script_dir}/fetch-all.sh" "${HOME}/bin/fetch-all.sh" + fi + + if [[ ! -f "${HOME}/bin/list-all.sh" ]]; then + echo 'installing list-all.sh' + ln -s "${script_dir}/list-all.sh" "${HOME}/bin/list-all.sh" + fi + + if [[ ! -f "${HOME}/bin/pull-all.sh" ]]; then + echo 'installing pull-all.sh' + ln -s "${script_dir}/pull-all.sh" "${HOME}/bin/pull-all.sh" + fi + + if [[ ! -f "${HOME}/bin/status-all.sh" ]]; then + echo 'installing status-all.sh' + ln -s "${script_dir}/status-all.sh" "${HOME}/bin/status-all.sh" + fi + ;; + * ) + echo 'Skipping' + ;; +esac +echo '' + diff --git a/setup/1-choose-packages.sh b/setup/1-choose-packages.sh index 89b61c4..a5e9db0 100755 --- a/setup/1-choose-packages.sh +++ b/setup/1-choose-packages.sh @@ -41,8 +41,7 @@ install_collection 'Ruby: (ruby, build-essential)' ruby-full build-essential zli read -p 'Configure GEM_HOME and PATH for Ruby support? [y/N]: ' response case "${response}" in [Yy]* ) - ( - cat << 'BASHRC' + ( cat << 'BASHRC' # Install Ruby Gems to ~/gems export GEM_HOME="$HOME/gems" @@ -91,7 +90,7 @@ echo '' read -p 'Install GoLang? [y/N]: ' response case "${response}" in [Yy]* ) - sudo apt install jq -y + sudo apt install wget jq -y # load json file with version info, filter to only stable versions, take the first (newest), strip to just numeric version_flag='' go_version=$(wget --quiet --output-document - 'https://go.dev/dl/?mode=json' | jq -r '.[] | select( .stable ) | .version' | head -n 1 | sed 's/[^0-9.]*//g') diff --git a/setup/2-config.sh b/setup/2-config.sh new file mode 100644 index 0000000..a14573e --- /dev/null +++ b/setup/2-config.sh @@ -0,0 +1,255 @@ +#!/usr/bin/env bash + +called_backup=false +curdate=$(date '+%Y-%m-%d') +script_dir=$(dirname "$0") + +# ---------------------------------------------------------- + +# call this function before editing bashrc, will only make backup if needed +function make_bashrc_backup () { + if [ "${called_backup}" = false ]; then + called_backup=true + if [[ ! -f "${HOME}/bashrc.backup.${curdate}" ]]; then + echo 'backing up existing bashrc' + cp "${HOME}/.bashrc" "${HOME}/bashrc.backup.${curdate}" + fi + fi +} + +# ---------------------------------------------------------- + +read -p 'Install git-prompt and include in ~/.bashrc? [y/N]: ' response +case "${response}" in + [Yy]* ) + make_bashrc_backup + sudo apt install wget jq -y + # make home bin folder if needed + [ ! -d "${HOME}/bin" ] && mkdir "${HOME}/bin" + # download git-prompt + wget 'https://raw.githubusercontent.com/git/git/master/contrib/completion/git-prompt.sh' -O "${HOME}/bin/git-prompt.sh" -q && ( cat << 'BASHRC' + +# ABS git prompt +source ~/bin/git-prompt.sh + +BASHRC +) >> "${HOME}/.bashrc" + chmod +x "${HOME}/bin/git-prompt.sh" + ;; + * ) + echo 'Skipping' + ;; +esac +echo '' + +# ---------------------------------------------------------- + +read -p 'Use colorful prompt style to ~/.bashrc? [y/N]: ' response +case "${response}" in + [Yy]* ) + make_bashrc_backup + ( cat << 'BASHRC' + +# ABS prompt color +abs_user="\[\e[31m\]\u" # username (red) +abs_host="\[\e[m\]@\[\e[36m\]\h" # hostname (teal) +abs_work="\[\e[m\]:\[\e[33m\]\w" # work-dir (yellow) +abs_git="\[\e[m\](\[\e[35m\]%s\[\e[m\])" # branch (purple) +abs_tail="\[\e[34m\]\$\[\e[m\] " # $ or # (blue) +if [[ -f "$HOME/.sudo_as_admin_successful" ]] || [[ "0" == $(id -u) ]]; then + abs_user="\[\e[32m\]\u" # username (green) if sudo/root +fi + +if [ "$(type -t __git_ps1)" == 'function' ]; then + PROMPT_COMMAND="__git_ps1 \"$abs_user$abs_host$abs_work\" \"$abs_tail\" \"$abs_git\"" +else + PS1="$abs_user$abs_host$abs_work$abs_tail" +fi + +BASHRC +) >> "${HOME}/.bashrc" + ;; + * ) + echo 'Skipping' + ;; +esac +echo '' + +# ---------------------------------------------------------- + +git_name=$(git config --global user.name) +read -p "Name for GIT (blank to leave unaltered), currently '${git_name}': " response +if [[ ! -z "${response}" ]]; then + git config --global user.name "${response}" +else + echo 'Skipping' +fi +echo '' + +# ---------------------------------------------------------- + +git_email=$(git config --global user.email) +read -p "Email for GIT (blank to leave unaltered), currently '${git_email}': " response +if [[ ! -z "${response}" ]]; then + git config --global user.email "${response}" +else + echo 'Skipping' +fi +echo '' + +# ---------------------------------------------------------- + +read -p 'Set GIT pager to display short output directly? [y/N]: ' response +case "${response}" in + [Yy]* ) + git config --global core.pager "less -X -F" + ;; + * ) + echo 'Skipping' + ;; +esac +echo '' + +# ---------------------------------------------------------- + +read -p 'Set GIT default branch name to "main"? [y/N]: ' response +case "${response}" in + [Yy]* ) + git config --global init.defaultBranch main + ;; + * ) + echo 'Skipping' + ;; +esac +echo '' + +# ---------------------------------------------------------- + +read -p 'Add GIT alias "gittree"? [y/N]: ' response +case "${response}" in + [Yy]* ) + make_bashrc_backup + ( cat << 'TERM' + +# ABS gittree alias +alias gittree='git log --all --decorate --oneline --graph' + +TERM +) >> "${HOME}/.bashrc" + ;; + * ) + echo 'Skipping' + ;; +esac +echo '' + +# ---------------------------------------------------------- + +read -p 'Set "cd" to resolve symbolic directories in ~/.bashrc? [y/N]: ' response +case "${response}" in + [Yy]* ) + make_bashrc_backup + ( cat << 'TERM' + +# ABS when changing directory through a symlink, resolve real location +alias cd='cd -P' + +TERM +) >> "${HOME}/.bashrc" + ;; + * ) + echo 'Skipping' + ;; +esac +echo '' + +# ---------------------------------------------------------- + +read -p 'Set "ssh" alias to ssh-ident"? (and set python3 as python) [y/N]: ' response +case "${response}" in + [Yy]* ) + sudo apt install python-is-python3 -y + if [[ ! -f "${HOME}/bin/ssh" ]]; then + ln -s "${script_dir}/ssh-ident" "${HOME}/bin/ssh" + fi + ;; + * ) + echo 'Skipping' + ;; +esac +echo '' + +# ---------------------------------------------------------- + +read -p 'Setup improved shell history? [y/N]: ' response +case "${response}" in + [Yy]* ) + make_bashrc_backup + # disable any existing history config + sed -i -e '/^\(HISTCONTROL\|HISTFILESIZE\|HISTFILE\|HISTIGNORE\|HISTSIZE\|HISTTIMEFORMAT\|shopt -s histappend\|shopt -s histreedit\|shopt -s histverify\)/s/^/# ABS #/' "${HOME}/.bashrc" + ( cat << 'BASHRC' + +# ABS improved shell history +shopt -s histappend # append to the history file, don't overwrite it +HISTSIZE=10000 # cache the last 10,000 commands +HISTFILESIZE=100000 # remember the last 100,000 commands +HISTCONTROL="ignoredups" # ignore duplicates +HISTIGNORE="l:la:ll:ls:cd:clear:history:pwd" # ignore select simple commands + +# if we have already sourced this file, don't do it again +if [[ "${PROMPT_COMMAND}" != *"history"* ]]; then + # append history as you go + PROMPT_COMMAND="${PROMPT_COMMAND:+${PROMPT_COMMAND/%;};}history -a" +fi + +BASHRC +) >> "${HOME}/.bashrc" + # update live config + shopt -s histappend + shopt -u histreedit + shopt -u histverify + export HISTSIZE=10000 + export HISTFILESIZE=100000 + export HISTCONTROL="ignoredups" + export HISTIGNORE="l:la:ll:ls:cd:clear:history:pwd" + if [[ "${PROMPT_COMMAND}" != *"history"* ]]; then + export PROMPT_COMMAND="${PROMPT_COMMAND:+${PROMPT_COMMAND/%;};}history -a" + fi + ;; + * ) + echo 'Skipping' + ;; +esac +echo '' + +# ---------------------------------------------------------- + +read -p 'Set screen layout to autosave to ~/.screenrc? [y/N]: ' response +case "${response}" in + [Yy]* ) + ( cat << 'SCREENRC' + +# ABS detach and re-attach without losing layout +layout save default + +SCREENRC +) >> "${HOME}/.screenrc" + ;; + * ) + echo 'Skipping' + ;; +esac +echo '' + +# ---------------------------------------------------------- + +# TODO vim config +# TODO if bashrc was edited, show "source to take effect now"... + + + + + + + +