From 6fbd051cb987e1a58960250d02311f511a45bbb4 Mon Sep 17 00:00:00 2001 From: Jordan Trask Date: Wed, 29 Mar 2023 10:36:59 -0400 Subject: [PATCH] * Moving files around to have a cleaner root * Updated install.sh * Changed README.md to include image. * Fixed issue with installer. --- README.md | 15 +- other.md => doc/other.md | 0 todo.md => doc/todo.md | 0 help.zsh => help/help.zsh | 0 install.sh | 175 +++++++------ kb/gridpane.md | 3 + kb.zsh => kb/kb.zsh | 0 kb/microsoft365.md | 1 - aliases.zsh => lib/aliases.zsh | 2 +- antigen.zsh => lib/antigen.zsh | 0 colors.zsh => lib/colors.zsh | 0 lib/functions-core.zsh | 204 +++++++++++++++ lib/functions.zsh | 455 +++++++++++++++++++++++++++++++++ init.zsh => lib/init.zsh | 8 +- motd/motd.zsh | 31 +++ zshbop.zsh | 14 +- 16 files changed, 819 insertions(+), 89 deletions(-) rename other.md => doc/other.md (100%) rename todo.md => doc/todo.md (100%) rename help.zsh => help/help.zsh (100%) rename kb.zsh => kb/kb.zsh (100%) rename aliases.zsh => lib/aliases.zsh (100%) rename antigen.zsh => lib/antigen.zsh (100%) rename colors.zsh => lib/colors.zsh (100%) create mode 100644 lib/functions-core.zsh create mode 100644 lib/functions.zsh rename init.zsh => lib/init.zsh (98%) create mode 100644 motd/motd.zsh diff --git a/README.md b/README.md index b9e5ae6b..8e923bc2 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,6 @@ -# zshbop -This is my custom ZSH configuration. It uses antidote ~~antigen~~ to install ZSH plugins. +

ZSHBOP

+ +This is my custom ZSH configuration. It uses antidote to install ZSH plugins. Buy Me A Coffee @@ -48,9 +49,15 @@ Created by [gh-md-toc](https://github.com/ekalinin/github-markdown-toc) |---------------------|---------------| | Quick Install | ```bash <(curl -sL https://zshrc.pl)``` | | Fallback Install | ```bash <(curl -sL https://raw.githubusercontent.com/jordantrizz/zshbop/master/install.sh)``` | -| Development Install | ```bash <(curl -sL https://raw.githubusercontent.com/jordantrizz/zshbop/develop/install.sh)``` | +| Development Install | ```bash <(curl -sL https://raw.githubusercontent.com/jordantrizz/zshbop/develop/install.sh)``` | +| Bleeding Install | ```bash <(curl -sL https://raw.githubusercontent.com/jordantrizz/zshbop/bleeding/install.sh)```| + +# Branches +* main - production releases, fully functional. +* dev - development releases that are somewhat functional. +* bleeding - bleeding releases that most likely won't work. -## Advanced Install +# Advanced Install
Click to Reveal Advanced Install

If you don't want to have zsh within your home directory, then use the following. diff --git a/other.md b/doc/other.md similarity index 100% rename from other.md rename to doc/other.md diff --git a/todo.md b/doc/todo.md similarity index 100% rename from todo.md rename to doc/todo.md diff --git a/help.zsh b/help/help.zsh similarity index 100% rename from help.zsh rename to help/help.zsh diff --git a/install.sh b/install.sh index a5bf78a8..5f028c2b 100755 --- a/install.sh +++ b/install.sh @@ -3,10 +3,8 @@ # -- zshbop Install script # ------------------------ -# ------------ # -- Variables -# ------------ -VERSION="0.0.2" +VERSION="0.0.3" SKIPDEP="0" HELP="0" REQUIRED_SOFTWARE=('jq' 'curl' 'zsh' 'git' 'md5sum' 'sudo' 'screen' 'git' 'joe') @@ -22,20 +20,13 @@ GREENBG="\033[0;42m" DARKGREYBG="\033[0;100m" ECOL="\033[0;0m" -# ------------ # -- Functions -# ------------ - -# -- _error -_error () { echo -e "${RED}** ERROR ** - $@ ${ECOL}"; } -_warning () { echo -e "${YELLOW}** ERROR ** - $@ ${ECOL}"; } -_success () { echo -e "${GREEN}** SUCCESS ** - $@ ${ECOL}"; } -_running () { echo -e "${BLUEBG}${@}${ECOL}"; } - - -# ------------ -# -- Functions -# ------------ +_error () { echo -e "${RED}** ERROR ** - ${*} ${ECOL}"; } +_warning () { echo -e "${YELLOW}** ERROR ** - ${*} ${ECOL}"; } +_success () { echo -e "${GREEN}** SUCCESS ** - ${*} ${ECOL}"; } +_running () { echo -e "${BLUEBG}${*}${ECOL}"; } +_install () { echo -e "${GREENBG}${*}${ECOL}"; } +_debug () { if [[ $DEBUG == "1" ]]; then echo -e "${CYAN}*** DEBUG: ${*}${ECOL}"; fi; } # -- usage usage () { @@ -45,6 +36,7 @@ USAGE=\ Options -h - This help screen -s - Skip dependencies + -d - Debug mode Commands @@ -61,28 +53,60 @@ Version: ${VERSION} echo "$USAGE" } +# -- zshbop_banner +zshbop_banner () { + echo " _ _ "; + echo " | | | | "; + echo " ____ ___ | |__ | |__ ___ _ __ "; + echo "|_ // __|| '_ \ | '_ \ / _ \ | '_ \ "; + echo " / / \__ \| |_) || |_) || (_) || |_) |"; + echo "/___||___/|_.__/ |_.__/ \___/ | .__/ "; + echo " | | "; + echo " |_| "; +} + # -- flight_check -flight_check() { - # Checking if zsh is installed - TOOLS_INSTALL=('') - _running "Checking if required software are installed" - for tool in ${REQUIRED_SOFTWARE[@]}; do - if ! [ -x "$(command -v $tool)" ]; then - _error "$tool is not installed." - TOOLS_INSTALL+=("$tool") - else - TOOL_PATH=`which $tool` - _success "$tool is installed in $TOOL_PATH" - fi - done - if [[ -z TOOLS_INSTALL ]]; then - _success "Not need to install any software" +pre_flight_check () { + # -- Pre-flight Check + _debug "Running pre_flight_check" + if [[ $SKIPDEP == "0" ]]; then + _running "Running pre-flight Check" + local TOOLS_INSTALL + + _debug "Checking if required software are installed" + _debug "\$REQUIRED_SOFTWARE: ${REQUIRED_SOFTWARE[*]}" + for tool in "${REQUIRED_SOFTWARE[@]}"; do + if ! [ -x "$(command -v $tool)" ]; then + _error "$tool is not installed." + TOOLS_INSTALL+=("$tool") + else + TOOL_PATH=`which $tool` + _debug "$tool is installed in $TOOL_PATH" + fi + done + _debug "\$TOOLS_INSTALL: ${TOOLS_INSTALL[*]}" + if [[ ${#TOOLS_INSTALL[@]} -eq 0 ]]; then + _debug "No software to install, proceeding." + else + _running "Installing required packages..." + echo " Packages: ${TOOLS_INSTALL[*]}" + echo "" + read -p "Do you want to install the software above? (y/n): " choice + if [ "$choice" == "y" ] || [ "$choice" == "Y" ]; then + echo "" + echo "${YELLOW}****************************************************${ECOL}" + apt-get install -y --no-install-recommends "${TOOLS_INSTALL[@]}" + echo "${YELLOW}****************************************************${ECOL}" + echo "" + elif [ "$choice" == "n" ] || [ "$choice" == "N" ]; then + echo "Not installing the software...continuing" + else + echo "Invalid choice. Please enter 'y' or 'n'." + fi + fi else - _running "Installing required tools...${TOOLS_INSTALL[@]}" - apt-get install -y --no-install-recommends "${TOOLS_INSTALL[@]}" - + _running "Skipping pre-flight check and installing required packages." fi - return } # -- check_zsh_default @@ -98,34 +122,37 @@ check_zsh_default () { } # -- pkg_install - install packafges. -pkg_install() { +pkg_install () { # Checking what package manager we have _running "Checking what package manager we have...." if [ -x "$(command -v apt-get)" ]; then echo " - We have apt!" - sudo apt install $@ + sudo apt install "${*}" elif [ -x "$(command -v yum)" ]; then echo " - We have yum!" - sudo yum install $@ + sudo yum install "${*}" elif [ -x "$(command -v brew)" ]; then echo " - We have brew!" - brew install $@ + brew install "${*}" else _error "Can't detect package manager :(" fi $(${PKG_MANAGER}) if [ $? -eq 1 ]; then - _error "$@ install failed...." + _error "${*} install failed...." exit 1 else - _success "$@ installed successfully" + _success "${*} installed successfully" fi } # -- install_method - how do you want to install zshbop? -install_method() { - echo "Install (d)efaults or (c)ustomize? (d/c)?" +install_method () { + zshbop_banner + echo "" + _install "Starting zshbop install" + echo "Install (d)efaults or (c)ustomize? (d/c)?" read INSTALL if [ $INSTALL == "d" ];then @@ -204,50 +231,49 @@ setup_system() { fi } + # ------- # -- Main # ------- - POSITIONAL=() - while [[ $# -gt 0 ]] - do - key="$1" +_debug "ARGS: ${*}" + +POSITIONAL=() +while [[ $# -gt 0 ]] +do +key="$1" - case $key in - -h|--help) - HELP="1" - shift # past argument - ;; - -s|--skipdep) - SKIPDEP="1" - shift # past argument - ;; - *) # unknown option - POSITIONAL+=("$1") # save it in an array for later - shift # past argument - ;; - esac - done - set -- "${POSITIONAL[@]}" # restore positional parameters +case $key in + -h|--help) + HELP="1" + shift # past argument + ;; + -s|--skipdep) + SKIPDEP="1" + shift # past argument + ;; + -d) + DEBUG="1" + shift # past argument + ;; + *) # unknown option + POSITIONAL+=("$1") # save it in an array for later + shift # past argument + ;; +esac +done +set -- "${POSITIONAL[@]}" # restore positional parameters # -- set $CMD CMD="$1" -# -- Pre-flight Check -if [[ $SKIPDEP == "0" ]]; then - _running "Running pre-flight Check" - flight_check -else - _running "Skipping pre-flight check" -fi - # -- help if [[ $HELP == "1" ]];then usage exit # -- clean elif [[ $CMD == "clean" ]]; then - _running "Removing zshbop ###" + _running "Removing zshbop from system" echo "Continue (y/n)?" read CLEAN if [ $CLEAN == "y" ]; then @@ -262,14 +288,17 @@ elif [[ $CMD == "clean" ]]; then fi # -- default elif [[ $CMD == "default" ]]; then + pre_flight_check INSTALL=d # -- home elif [[ $CMD == "home" ]]; then + pre_flight_check INSTALL=c BRANCH=m INSTALL_LOCATION=h # -- git elif [[ $CMD == "git" ]]; then + pre_flight_check INSTALL=c BRANCH=d INSTALL_LOCATION=g @@ -279,11 +308,13 @@ elif [[ $CMD == "custom" ]]; then usage exit 1 else + pre_flight_check INSTALL=c BRANCH="$2" INSTALL_LOCATION="$3" fi else + pre_flight_check install_method fi diff --git a/kb/gridpane.md b/kb/gridpane.md index d2de6112..4ae6db50 100644 --- a/kb/gridpane.md +++ b/kb/gridpane.md @@ -120,6 +120,7 @@ The below example will set the redis maxmemory to 300MB gp stack redis -max-memory 300 ``` +<<<<<<< HEAD # Redis Object Cache ## Change Redis maxmemory @@ -129,6 +130,8 @@ The below example will set the redis maxmemory to 300MB gp stack redis -max-memory 300 ``` +======= +>>>>>>> bleeding # PHP ## Change PHP Settings diff --git a/kb.zsh b/kb/kb.zsh similarity index 100% rename from kb.zsh rename to kb/kb.zsh diff --git a/kb/microsoft365.md b/kb/microsoft365.md index c23685ad..385c7c45 100644 --- a/kb/microsoft365.md +++ b/kb/microsoft365.md @@ -1,7 +1,6 @@ # Other ## Enable App Passwords https://support.microsoft.com/en-us/account-billing/manage-app-passwords-for-two-step-verification-d6dc8c6d-4bf7-4851-ad95-6d07799387e9 -======= # Other ## Enable App Passwords https://support.microsoft.com/en-us/account-billing/manage-app-passwords-for-two-step-verification-d6dc8c6d-4bf7-4851-ad95-6d07799387e9 diff --git a/aliases.zsh b/lib/aliases.zsh similarity index 100% rename from aliases.zsh rename to lib/aliases.zsh index 8eb3c037..11bab3a8 100644 --- a/aliases.zsh +++ b/lib/aliases.zsh @@ -57,8 +57,8 @@ function scrc { # - ssh alias sshc="ssh-connect" function sshr { ssh root@$1 } +alias ssh-keygen="ssh-keygen -t ed25519" # - Litespeed alias lsphp74="/usr/local/lsws/lsphp74/bin/php" alias lsphp81="/usr/local/lsws/lsphp81/bin/php" -alias ssh-keygen="ssh-keygen -t ed25519" diff --git a/antigen.zsh b/lib/antigen.zsh similarity index 100% rename from antigen.zsh rename to lib/antigen.zsh diff --git a/colors.zsh b/lib/colors.zsh similarity index 100% rename from colors.zsh rename to lib/colors.zsh diff --git a/lib/functions-core.zsh b/lib/functions-core.zsh new file mode 100644 index 00000000..40800012 --- /dev/null +++ b/lib/functions-core.zsh @@ -0,0 +1,204 @@ +# ----------------------------- +# -- functions-core.zsh +# -- +# -- Core functions for scripts +# ----------------------------- + +# -- Help category +typeset -gA help_files +typeset -gA help_corefunc +help_files[corefunc]='Core functions for scripts' + +# --------------------- +# -- Internal Functions +# --------------------- + +# -- Different colored messages +_echo () { echo "$@" } +_error () { echo "$fg[red] * $@ ${RSC}" } +_warning () { echo "$fg[yellow] * $@ ${RSC}" } +_success () { echo "$fg[green] * $@ ${RSC}" } +_noticebg () { echo "$bg[magenta]$fg[white] * $@ ${RSC}" } +_noticefg () { echo "$fg[magenta] * $@ ${RSC}" } +alias _notice="_noticefg" + +# -- Banners +_banner_red () { echo "$bg[red]$fg[white]${@}${RSC}" } +_banner_green () { echo "$bg[green]$fg[white]${@}${RSC}" } +_banner_yellow () { echo "$bg[yellow]$fg[black]${@}${RSC}" } +_banner_grey () { echo "$bg[bright-grey]$fg[black]${@}${RSC}" } +_loading () { echo "$bg[yellow]$fg[black] * ${@}${RSC}" } +_loading2 () { echo "$bg[bright-grey]$fg[black]${@}${RSC}" } +_loading3 () { echo "$bg[bright-grey]$fg[black]${@}${RSC}" } +_loading4 () { echo "$fg[bright-grey]${@}${RSC}" } +alias _loading_grey=_loading2 + +COLOR_FUNCTIONS=(_error _warning _success _noticebg _noticefg _banner_red _banner_green _banner_grey _loading _loading2 _loading3 _loading4) + +# -- Text Colors +_grey () { echo "$bg[bright-gray]$fg[black] $@ ${RSC}" } +RSC=$reset_color # To replace $reset_color :) + +function colors-print () { + for k in ${(k)color}; do + if [[ ! $k =~ ^(fg|bg|[[:digit:]]{1,3}|no-|none|normal|italic|underline|reverse|bold|conceal|faint|default|blink) ]]; then + echo "${k}: ${fg[$k]} Foreground ${RSC} - ${bg[$k]}Background${RSC}" + fi + done +} + +# ------------ +# -- Debugging +# ------------ +ZSH_DEBUG="0" + +# -- zshbop debugging +if [ -f $ZSHBOP_ROOT/.debug ]; then + export ZSH_DEBUG=1 +elif [ ! -f $ZSHBOP_ROOT/.debug ]; then + export ZSH_DEBUG=0 +fi + +# -- _debug +_debug () { + if [[ $ZSH_DEBUG == 1 ]]; then + echo "$fg[cyan]** DEBUG: $@${RSC}"; + fi +} + +# -- _debug_all +_debug_all () { + _debug "--------------------------" + _debug "arguments - $@" + _debug "funcstack - $funcstack" + _debug "ZSH_ARGZERO - $ZSH_ARGZERO" + _debug "SCRIPT_DIR - $SCRIPT_DIR" + _debug "--------------------------" +} + +# --------------------------------------------------------------- +# -- _require_pkg ($package) +# -- +# -- Check to see if command exists and if not install +# --------------------------------------------------------------- +help_corefunc[_require_pkg]='Check if command exists and if not install using package manager' +_require_pkg () { + _debug_function + _debug "Running _requires_pkg on $1" + _debug "array: ${(P)${array_name}}" + + local array_name=$1 + PKG="" + + for PKG in ${(P)${array_name}}; do + if [[ $(dpkg-query -W -f='${Status}' nano 2>/dev/null | grep -c "ok installed") -eq 1 ]]; then + if [[ $ZSH_DEBUG == 1 ]]; then + _debug "$PKG is installed"; + REQUIRES_PKG=0 + fi + else + if [[ $ZSH_DEBUG == 1 ]]; then + _debug "$PKG not installed"; + fi + echo "$PKG not installed, installing" + sudo apt-get install $PKG + REQUIRES_PKG=1 + fi + done + +} + +# ---------------------------------------- +# -- _requires_cmd ($command) +# -- +# -- Check to see if $command is installed +# ---------------------------------------- +_requires_cmd () { + _debug_function + _debug "Running _requires on $1" + _debug "array: ${(P)${array_name}}" + + local array_name=$1 + CMD="" + + for CMD in ${(P)${array_name}}; do + if (( $+commands[$CMD] )); then + _debug $(which $CMD) + if [[ $ZSH_DEBUG == 1 ]]; then + _debug "$CMD is installed"; + REQUIRES_CMD=0 + fi + else + if [[ $ZSH_DEBUG == 1 ]]; then + _debug "$CMD not installed"; + fi + echo "$CMD not installed" + REQUIRES_CMD=1 + fi + done +} + +# ------------------------------------------------------------------------ +# -- _cexists +# -- +# -- Returns 0 if command exists or 1 if command doesn't exist +# ------------------------------------------------------------------------ +_cexists () { + unset CMD_EXISTS CMD CMD_PATH + CMD="$1" + + # Check if command exists + CE_PATH=$(which $CMD) + CE_EXIT_CODE=$? + if [[ $CE_EXIT_CODE == "0" ]]; then + CMD_PATH=$(which $CMD) + _debug "CMD_PATH: $CMD_PATH" + if [[ $ZSH_DEBUG == 1 ]]; then + _debug "$CMD is installed"; + fi + CMD_EXISTS="0" + else + if [[ $ZSH_DEBUG == 1 ]]; then + _debug "$CMD not installed"; + fi + CMD_EXISTS="1" + fi + + # Check if alias exists + return $CMD_EXISTS +} + +# --------------------------------------- +# -- checkroot() +# -- +# -- checkroot - check if running as root +# --------------------------------------- +_checkroot () { + _debug_function + if [[ $EUID -ne 0 ]]; then + _error "Requires root...exiting." + return + fi +} + +# ------------------------------------------------------ +# -- _if_marray - if in array. +# -- _if_marray "$NEEDLE" HAYSTACK +# -- must use quotes, second argument is array without $ +# ------------------------------------------------------ +_if_marray () { + MARRAY_VALID=1 + _debug "$funcstack[1] - find value = $1 in array = $2" + for value in ${(k)${(P)2[@]}}; do + _debug "$funcstack[2] - array=$2 \$value = $value" + if [[ $value == "$1" ]]; then + _debug "$funcstack[1] - array $2 does contain $1" + MARRAY_VALID="0" + else + _debug "$funcstack[1] - array $2 doesn't contain $1" + fi + done + _debug "MARRAY_VALID = $MARRAY_VALID" + if [[ MARRAY_VALID == "1" ]]; return 0 +} + diff --git a/lib/functions.zsh b/lib/functions.zsh new file mode 100644 index 00000000..a25259d6 --- /dev/null +++ b/lib/functions.zsh @@ -0,0 +1,455 @@ +# ----------------------------------------------------------------------------------- +# -- functions.zsh +# -- This file contains all the required zshbop functions for the main .zshrc script. +# ----------------------------------------------------------------------------------- + +####################################### + +# ----------- +# -- ZSHBOP Aliases +# ----------- +alias update="zshbop_update" +alias rld="zshbop_reload" +alias urld="zshbop_update;zshbop_reload" +alias zb="zshbop" +alias init="init_zshbop" +alias _debug_function="_debug_all" +alias zbr="cd $ZBR" +alias motd="init_motd" + +########################################## +# ------------------- +# -- zshbop functions +# ------------------- +########################################## + +# ------------------------------------- +# -- cc () +# -- +# -- clear cache for various tools +# ------------------------------------- +help_zshbop[cc]='Clear cache for antigen + more' +alias cc="zshbop_cacheclear" +zshbop_cacheclear () { + _loading "Clearing plugin manager cache" + if [[ ${ZSHBOP_PLUGIN_MANAGER} == "init_antigen" ]]; then + _loading_grey $(antigen reset) + elif [[ $ZSHBOP_PLUGIN_MANAGER == "init_antidote" ]]; then + if [[ -a ${ANTIDOTE_STATIC} ]]; then + _loading_grey "Removing antidote static file cache" + rm "${ANTIDOTE_STATIC}" + else + _loading_grey "${ANTIDOTE_STATIC} doesn't exist" + fi + fi + + _loading "Clearing zshrc.zwc file" + rm -f ~/.zshrc.zwc +} + +# -- zshbop_scc +alias scc="zshbop_scc" +help_zshbop[zshbop_scc]='Clear everything, including zsh autocompletion' +zshbop_scc () { + _loading "Clearing rm ~/.zcompdump*" + rm -f ~/.zcompdump* +} + +# ------------------- +# -- zshbop_reload () +# -- +# -- reload zshbop +# ------------------- +help_zshbop[reload]='Reload zshbop' +zshbop_reload () { + _debug_function + _debug "Clearing cache" + zshbop_cacheclear + source $HOME/.zshrc + zshbop_version-check + echo "" + _warning "You may have to close your shell and restart it to see changes" + echo "" +} + +# --------------------- +# -- zshbop_startup () +# -- +# -- Run zshbop startup +# --------------------- +help_zshbop[startup]='Run zshbop startup' +zshbop_startup () { + _debug_function + init_motd +} + +# -------------------------- +# -- zshbop_branch ($branch) +# -- +# -- Change branch of zshbop +# -------------------------- +help_zshbop[branch]='Run main or dev branch of zshbop' +zshbop_branch () { + _debug_function + if [[ -n $2 ]]; then + echo " -- Switching to $2 branch" + GIT_CHECKOUT=$(git --git-dir=$ZSHBOP_ROOT/.git --work-tree=$ZSHBOP_ROOT checkout $2) + if [[ $? -ge "1" ]]; then + _error "Branch doesn't seem to exist" + fi + elif [ -z $2 ]; then + echo " -- zshbop: $ZSHBOP_ROOT branch: $ZSHBOP_BRANCH ----" + echo " -- To switch branch type 'zshbop branch dev' or 'zshbop branch main'" + else + _error "Unknown $@" + fi +} + +# ---------------------------- +# -- zshbop_check-updates () +# -- +# -- Check for zshbop updates. +# ---------------------------- +help_zshbop[check-updates]='Check for zshbop update, not completed yet' +zshbop_check-updates () { + _debug_function + + # Sources for version check + MAIN_UPDATE="https://raw.githubusercontent.com/$ZSHBOP_REPO/main/version" + DEV_UPDATE="https://raw.githubusercontent.com/$ZSHBOP_REPO/dev/version" + + _notice "-- Running $ZSHBOP_VERSION/$ZSHBOP_BRANCH/$ZSHBOP_COMMIT checking $ZSHBOP_BRANCH for updates." + if [[ "$ZSHBOP_BRANCH" = "main" ]]; then + echo "-- Checking version on $MAIN_UPDATE" + NEW_MAIN_VERSION=$(curl -s $MAIN_UPDATE) + if [[ $NEW_MAIN_VERSION != $ZSHBOP_VERSION ]]; then + _warning "Update available $NEW_MAIN_VERSION" + else + _success "Running current version $NEW_MAIN_VERSION" + fi + elif [[ "$ZSHBOP_BRANCH" = "dev" ]]; then + # Get repository dev commit. + ZSHBOP_REMOTE_COMMIT=$(curl -s https://api.github.com/repos/jordantrizz/zshbop/branches/dev | jq -r '.commit.sha') + + # Check remote github.com repository + echo "-- Checking version on $DEV_UPDATE" + NEW_DEV_VERSION=$(curl -s $DEV_UPDATE) + + # Compare versions + if [[ $NEW_DEV_VERSION != $ZSHBOP_VERSION ]]; then + _warning "Update available $NEW_DEV_VERSION" + else + _success "Running current version $NEW_DEV_VERSION" + fi + + # Compare commits + echo "-- Checking commit on branch $ZSHBOP_BRANCH " + if [[ $ZSHBOP_COMMIT != $ZSHBOP_REMOTE_COMMIT ]]; then + _warning "Not on $ZSHBOP_BRANCH latest commit - Local: $ZSHBOP_COMMIT / Remote: $ZSHBOP_REMOTE_COMMIT" + else + _success "On $ZSHBOP_BRANCH latest commit - Local: $ZSHBOP_COMMIT / Remote: $ZSHBOP_REMOTE_COMMIT" + fi + else + _error "Don't know what branch zshbop is on" + fi +} + +# ------------------- +# -- zshbop_update () +# -- +# -- Update ZSHBOP +# ------------------- +help_zshbop[update]='Update zshbop' +zshbop_update () { + _debug_function + _loading "UPDATING ZSHBOP" + + # -- print out zshbop version + zshbop_version + + # -- Pull zshbop down from git using current branch + _loading2 "Pulling zshbop updates" + + # -- Changed branch from develop to dev + if [[ $ZSHBOP_BRANCH == 'develop' ]]; then + _debug "Detected old branch name develop" + git --git-dir=$ZSHBOP_ROOT/.git --work-tree=$ZSHBOP_ROOT checkout dev + git --git-dir=$ZSHBOP_ROOT/.git --work-tree=$ZSHBOP_ROOT pull + else + git --git-dir=$ZSHBOP_ROOT/.git --work-tree=$ZSHBOP_ROOT pull + fi + + # Check if .zshrc is out of date. + # Called from script directly versus cached functions + $ZSHBOP_ROOT/zshbop.zsh previous-version-check + + # Update repos + repos update + + # Update $ZBC aka custom zshbop directory + _loading "Updating custom zshbop directory $ZBC" + if [[ $ZBC ]]; then + _loading2 "Found zshbop custom, running git pull if a git repostiory" + git --git-dir=${ZBC}/.git --work-tree=${ZBC} pull + else + _loading2 "No zshbop-custom to update" + fi + + # -- Update $ZSHBOP_UPDATE_GIT git repositories from custom config. + _loading "Updating \$ZSHBOP_UPDATE_GIT git repositores." + if [[ $ZSHBOP_UPDATE_GIT ]]; then + for GIT in ${ZSHBOP_UPDATE_GIT[@]}; do + if [[ -d ${GIT} ]]; then + _loading2 "Updating ${GIT}" + git --git-dir=${GIT}/.git --work-tree=${GIT} pull + else + _error "Couldn't find ${GIT}" + fi + done + fi + + # Reload scripts + _warning "Type zb reload to reload zshbop, or restart your shell." +} +# ----------------------------------- +# -- zshbop_pervious-version-check () +# ----------------------------------- +help_zshbop[previous-version-check]='Checking if \$HOME/.zshrc is pre v1.1.3 and replacing.' +zshbop_previous-version-check () { + _debug_function + + # Replacing .zshrc previous to v1.1.2 256bb9511533e9697f639821ba63adb9 + _debug " -- Current $HOME/.zshrc md5 is - $ZSHBOP_HOME_MD5" + _debug " -- zshbop .zshrc md5 is - $ZSHBOP_LATEST_MD5" + if [[ "$ZSHBOP_HOME_MD5" != "$ZSHBOP_LATEST_MD5" ]]; then + _error "-- Found old .zshrc" + _notice "-- Replacing $HOME/.zshrc" + cp $ZSHBOP_ROOT/.zshrc $HOME/.zshrc + else + _debug " -- No need to fix .zshrc" + fi +} + +# ----------------------- +# -- zshbop_migrate-check +# ----------------------- +help_zshbop[migrate-check]='Check if running old zshbop.' +zshbop_migrate-check () { + _debug_function + _loading2 "Checking for legacy zshbop" + FOUND="0" + for ZBPATH_MIGRATE in "${ZSHBOP_MIGRATE_PATHS[@]}"; do + if [ -d "$ZBPATH_MIGRATE" ]; then + _error "Detected old zshbop under $ZBPATH_MIGRATE, run 'zshbop migrate'"; + FOUND="1" + fi + done + if [[ "$FOUND" == "0" ]]; then + _loading2 "Don't need to migrate legacy zshbop" + fi + + _banner_yellow "-- Checking for github modules" + if [ -d "$ZSHBOP_ROOT/ultimate-linux-tool-box" ]; then + _debug "Found old ultimate-linux-tool-box" + _warning "Found ultimate-linux-tool-box run 'zshbop migrate'" + else + _success "Didn't find ultimate-linux-tool-box" + fi + + if [ -d "$ZSHBOP_ROOT/ultimate-wordpress-tools" ]; then + _debug "Found old ultimate-wordpress-tools" + _warning "Found ultimate-wordpress-tools run 'zshbop migrate'" + else + _success "Didn't find ultimate-wordpress-tools" + fi + +} +# -------------------- +# -- zshbop_migrate () +# -------------------- +help_zshbop[migrate]='Migrate old zshbop to new zshbop' +zshbop_migrate () { + _debug_function + _debug " -- Migrate old zshbop to legacy zshbop" + FOUND="0" + for ZBPATH_MIGRATE in "${ZSHBOP_MIGRATE_PATHS[@]}"; do + if [ -d "$ZBPATH_MIGRATE" ]; then + _success "Found legacy zshbop...migrating" + echo " -- Moving $ZBPATH_MIGRATE to ${ZBPATH_MIGRATE}bop" + sudo mv $ZBPATH_MIGRATE ${ZBPATH_MIGRATE}bop + echo " -- Copying ${ZBPATH_MIGRATE}bop/.zshrc to your $HOME/.zshrc" + cp ${ZBPATH_MIGRATE}bop/.zshrc $HOME/.zshrc + FOUND="1" + fi + done + if [[ "$FOUND" == "0" ]]; then + _debug " -- Don't need to migrate legacy zshbop" + fi + + _debug "-- Checking for github modules" + if [ -d "$ZSHBOP_ROOT/ultimate-linux-tool-box" ]; then + _debug "Found old ultimate-linux-tool-box" + _warning "Found ultimate-linux-tool-box, removing folder" + rm -r $ZSHBOP_ROOT/ultimate-linux-tool-box + else + _debug "Didn't find ultimate-linux-tool-box" + fi + + if [ -d "$ZSHBOP_ROOT/ultimate-wordpress-tools" ]; then + _debug "Found old ultimate-wordpress-tools" + _warning "Found ultimate-wordpress-tools, removing folder." + rm -r $ZSHBOP_ROOT/ultimate-wordpress-tools + else + _debug "Didn't find ultimate-wordpress-tools" + fi +} + +# -------------------- +# -- zshbop_version () +# -------------------- +help_zshbop[version]='Get version information' +zshbop_version () { + _debug_function + _loading "zshbop Version" + echo "Version: ${fg[green]}${ZSHBOP_VERSION}/${fg[white]}${bg[cyan]}${ZSHBOP_BRANCH}${reset_color}${fg[green]}/$ZSHBOP_COMMIT${RSC}" + echo "Install .zshrc MD5: $fg[green]$ZSHBOP_HOME_MD5${RSC} --" +} + +# -------------------------- +# -- zshbop_version_check () +# -------------------------- +help_zshbop[version-check]='Check zshbop version' +zshbop_version-check () { + _debug_function + zshbop_version + + # -- check .zshrc + _loading "zshbop Version Check" + echo "-- Latest zshbop .zshrc: $fg[green]$ZSHBOP_LATEST_MD5${RSC}" + echo "-- \$ZSHBOP/.zshrc: $fg[green]$ZSHBOP_INSTALL_MD5${RSC}" + echo "-- \$HOME/.zshrc MD5: $fg[green]$ZSHBOP_HOME_MD5${RSC}" + + _loading2 "Checking if $HOME/.zshrc is the same as $ZSHBOP/.zshrc" + if [[ $ZSHBOP_HOME_MD5 == $ZSHBOP_INSTALL_MD5 ]]; then + _success " \$HOME/.zshrc and \$ZSHBOP/.zshrc are the same." + else + _error " \$HOME/.zshrc and \$ZSHBOP/.zshrc are the different." + fi + + # -- checking branch git commit versus current commit + _loading "Checking for branch updates" + echo "-- Current Commit : $fg[green]" + +} + +# ------------------ +# -- zshbop_debug () +# ------------------ +help_zshbop[debug]='Turn debug on and off' +alias debug=zshbop_debug +zshbop_debug () { + _debug_function + echo "test $@" + if [[ $1 == "on" ]] || [[ $2 == "on" ]]; then + echo "Turning debug on" + _debug "Turning debug on" + touch $ZSHBOP_ROOT/.debug + echo "Reloading to enable debug" + rld + elif [[ $1 == "off" ]] || [[ $2 == "off" ]]; then + echo "Turning debug off" + _debug "Turning debug off" + if [[ -f $ZSHBOP_ROOT/.debug ]]; then + rm $ZSHBOP_ROOT/.debug + echo "Reloading to disable debug" + else + _error "$ZSHBOP_ROOT/.debug doesn't exist" + rld + fi + else + _error "nothing passed" + echo "Usage: debug " + echo "Debug is $ZSH_DEBUG" + fi +} + +# ------------------ +# -- zshbop_color () +# ------------------ +help_zshbop[colors]='List variables for using color' +zshbop_colors () { + _debug_function + + _loading "How to use color" + echo " Foreground \$fg[blue] \$fg[red] \$fg[yellow] \$fg[green]" + echo " Background \$fg[blue] \$fg[red] \$fg[yellow] \$fg[green]" + echo " Reset Color: \${RSC}" + echo "" + + _loading "Listing all color functions" + for func in ${COLOR_FUNCTIONS[@]}; do + ${=func} "$func" + done + echo "" + + _loading "Listing colors available" + colors-print +} + +# ---------------- +# -- zshbop_custom +# ---------------- +help_zshbop[custom]='Custom zshbop configuration' +zshbop_custom () { + _banner_green "Instructions on how to utilize custom zshbop configuration." + echo " - Create a file called .zshbop.custom in your /$HOME directory" + echo " - Done!" + echo " - You can also copy the .zshbop.custom file within this repository as a template" +} + +# --------------------- +# -- zshbop_load_custom +# --------------------- +help_zshbop[load_custom]='Load zshbop custom config' +zshbop_load_custom () { + # -- Check for $HOME/.zshbop.config, load last to allow overwritten core functions + _loading "Checking for $HOME/.zshbop.conf" + if [[ -f $HOME/.zshbop.conf ]]; then + ZSHBOP_CUSTOM="$HOME/.zshbop.conf" + _loading_grey "Loaded custom zshbop config at $ZSHBOP_CUSTOM" + source $ZSHBOP_CUSTOM + else + _error "No custom zshbop config found. Type zshbop custom for more information" + fi +} + +# -------------- +# -- zshbop_help +# -------------- +help_zshbop[help]='This help screen :)' +zshbop_help () { + _debug_function + echo "-- zshbop help ------------" + echo "" + for key in ${(kon)help_zshbop}; do + printf '%s\n' " ${(r:25:)key} - ${help_zshbop[$key]}" + done + echo "" +} + +# -------------- +# -- Always Last +# -------------- + +zshbop () { + _debug_function + if [[ -z $1 ]]; then + zshbop_help + elif [[ $1 == "help" ]]; then + zshbop_help + elif [[ -n $1 ]]; then + _debug "-- Running zshbop $1" + zshbop_cmd=(zshbop_${1}) + $zshbop_cmd $@ + fi +} \ No newline at end of file diff --git a/init.zsh b/lib/init.zsh similarity index 98% rename from init.zsh rename to lib/init.zsh index 770ae6dc..dfb4f05a 100644 --- a/init.zsh +++ b/lib/init.zsh @@ -201,10 +201,10 @@ init_antidote () { init_antigen () { _debug "Loading antigen" _loading "Loading antigen" - if [[ -e $ZSHBOP_ROOT/antigen.zsh ]]; then - _debug "- Loading antigen from $ZSHBOP_ROOT/antigen.zsh" + if [[ -e $ZSHBOP_ROOT/lib/antigen.zsh ]]; then + _debug "- Loading antigen from $ZSHBOP_ROOT/lib/antigen.zsh" # shellcheck source=./antigen.zsh - source ${ZSHBOP_ROOT}/antigen.zsh >/dev/null 2>&1 + source ${ZSHBOP_ROOT}/lib/antigen.zsh >/dev/null 2>&1 antigen init ${ZSHBOP_ROOT}/.antigenrc >/dev/null 2>&1 else _echo " - Couldn't load antigen.." @@ -505,7 +505,7 @@ init_motd () { echo "" # -- Load motd - source "${ZBR}/motd.zsh" + source "${ZSHBOP_ROOT}/motd/motd.zsh" # -- env-install _loading "Run env-install to install default and extra tools" diff --git a/motd/motd.zsh b/motd/motd.zsh new file mode 100644 index 00000000..51445ef6 --- /dev/null +++ b/motd/motd.zsh @@ -0,0 +1,31 @@ +# -- MOTD + +# ---------------- +# -- Host MOTD +# ---------------- + +_cexists host_motd +if [[ $? == "0" ]]; then + _loading "Found host motd" + host_motd +else + _notice "No host motd" +fi + +# ---------------- +# -- GridPane +# ---------------- +if [[ -f /root/grid.id ]]; then + _loading "Running GridPane CP - type help gridpane for more commands" + source "${ZBR}/motd/motd-gp.zsh" + motd_gp +fi + +# ---------------- +# -- Runcloud +# ---------------- +if [[ -d /home/runcloud/webapps ]]; then + _loading "Running Runcloud CP - type help runcloud for more commands" + source "${ZBR}/motd/motd-runcloud.zsh" + motd_runcloud +fi \ No newline at end of file diff --git a/zshbop.zsh b/zshbop.zsh index ff5aadc0..48389fcc 100755 --- a/zshbop.zsh +++ b/zshbop.zsh @@ -81,13 +81,13 @@ EDITOR_RUN=${${$(alias $EDITOR)#joe=\'}%\'} # --------------- # -- Source files # --------------- -source ${ZSHBOP_ROOT}/colors.zsh # -- colors first! -source ${ZSHBOP_ROOT}/functions-core.zsh #-- -source ${ZSHBOP_ROOT}/functions.zsh # -- -source ${ZSHBOP_ROOT}/init.zsh # -- include init -source ${ZSHBOP_ROOT}/aliases.zsh # -- include functions -source ${ZSHBOP_ROOT}/help.zsh # -- include help functions -source ${ZSHBOP_ROOT}/kb.zsh # -- Built in Knolwedge Base +source ${ZSHBOP_ROOT}/lib/colors.zsh # -- colors first! +source ${ZSHBOP_ROOT}/lib/functions-core.zsh #-- +source ${ZSHBOP_ROOT}/lib/functions.zsh # -- +source ${ZSHBOP_ROOT}/lib/init.zsh # -- include init +source ${ZSHBOP_ROOT}/lib/aliases.zsh # -- include functions +source ${ZSHBOP_ROOT}/help/help.zsh # -- include help functions +source ${ZSHBOP_ROOT}/kb/kb.zsh # -- Built in Knolwedge Base ############################################################