From dff8211b9dac24d8b7449383beb39c35228ca879 Mon Sep 17 00:00:00 2001 From: yage Date: Tue, 27 Jun 2023 18:30:02 -0600 Subject: [PATCH] updated build/setup to match scwrypts v3 --- .docker/Dockerfile | 19 +++++++---- .docker/entrypoint | 19 ++++------- .docker/session/show-warning | 15 +++++++++ .docker/session/start-background | 13 ++++++++ config/tmux.conf | 2 +- setup/cleanup.zsh | 10 +++--- setup/config.zsh | 36 ++++++++++---------- setup/git.zsh | 8 ++--- setup/os.zsh | 56 ++++++++++++++++---------------- setup/requirements.zsh | 4 +-- setup/run | 10 +++--- 11 files changed, 111 insertions(+), 81 deletions(-) create mode 100755 .docker/session/show-warning create mode 100755 .docker/session/start-background diff --git a/.docker/Dockerfile b/.docker/Dockerfile index b010cf3..a48cd5d 100644 --- a/.docker/Dockerfile +++ b/.docker/Dockerfile @@ -20,6 +20,8 @@ RUN : \ openssh \ pciutils \ postgresql \ + py3-virtualenv \ + py3-nodeenv \ redis \ ripgrep \ sed \ @@ -31,21 +33,26 @@ RUN : \ zsh \ && apk add --update --no-cache --repository=http://dl-cdn.alpinelinux.org/alpine/edge/community/ \ helm \ - && apk add --update --no-cache --repository=http://dl-cdn.alpinelinux.org/alpine/edge/testing/ \ kubectl \ + && apk add --update --no-cache --repository=http://dl-cdn.alpinelinux.org/alpine/edge/testing/ \ && mkdir -p /root/.wryn \ ; COPY . /root/.wryn RUN : \ + && echo "#!/bin/zsh" > /bin/hostnamectl && echo "echo container" > /bin/hostnamectl && chmod +x /bin/hostnamectl \ + && echo "#!/bin/zsh" > /bin/scwrypts && echo '/root/.wryn/zsh/plugins/scwrypts/scwrypts $@' >> /bin/scwrypts && chmod +x /bin/scwrypts \ + && mkdir /root/.wryn/bin/container \ + && sed -i 's|/bin/ash|/bin/zsh|g' /etc/passwd \ && /bin/zsh -c '/root/.wryn/setup/run --no-fluff --ci --force-root' \ - && echo 'hostnamectl() { echo docker; }' > $HOME/.config/wryn/env.zsh \ - && echo 'source /root/.wryn/config/dotwryn.env.zsh' >> $HOME/.config/wryn/env.zsh \ - && echo "WELCOME() {}" >> $HOME/.config/wryn/env.zsh \ - && echo "PS1_INDICATOR_SYMBOL=''" >> $HOME/.config/wryn/env.zsh \ - && echo "PS1_USER='root@debugger'" >> $HOME/.config/wryn/env.zsh \ + && echo 'source /root/.wryn/config/dotwryn.env.zsh' > /root/.config/wryn/env.zsh \ + && echo "WELCOME() {}" >> /root/.config/wryn/env.zsh \ + && echo "PS1_INDICATOR_SYMBOL=''" >> /root/.config/wryn/env.zsh \ + && echo "PS1_USER=\"root@\$(ip a | grep inet | grep -v '127\\.0\\.0\.1' | sed 's|/| |g' | awk '{print \$2;}')\"" >> /root/.config/wryn/env.zsh \ + && echo "source /root/.wryn/zsh/plugins/scwrypts/scwrypts.plugin.zsh" >> /root/.config/wryn/env.zsh \ && rm /root/dotwryn-install.log \ + && scwrypts --name scwrypts/virtualenv/update-all --group scwrypts --type zsh \ ; ENTRYPOINT ["/root/.wryn/.docker/entrypoint"] diff --git a/.docker/entrypoint b/.docker/entrypoint index 913125a..5c9395c 100755 --- a/.docker/entrypoint +++ b/.docker/entrypoint @@ -1,18 +1,13 @@ #!/bin/zsh ##################################################################### -echo -e "\\033[1;31m=====================================================================\\033[0m - - \\033[1;32mWelcome to Debugger!\\033[0m - -You are now entering a root-privileged container with a variety of -powerful tools. Be sure to exercise appropriate caution for your -current use-case / environment! - - \\033[1;32mGLHF <3\\033[0m - -\\033[1;31m=====================================================================\\033[0m" ##################################################################### -zsh -l +source /root/.wryn/.docker/session/start-background + +[ -t 0 ] && tmux a -t $SESSION || echo -e "\\033[1;32m +REMINDER: connect by executing 'tmux a -t $SESSION' +\\033[0m" + +until ! tmux list-sessions 2>/dev/null | awk '{print $1;}' | grep -q "${SESSION}:"; do sleep 1; done ##################################################################### echo -e "\\033[1;31m=====================================================================\\033[0m \\033[1;32mExiting Debugger; see you next time!\\033[0m diff --git a/.docker/session/show-warning b/.docker/session/show-warning new file mode 100755 index 0000000..3c3289f --- /dev/null +++ b/.docker/session/show-warning @@ -0,0 +1,15 @@ +#!/bin/zsh +echo -e "\\033[1;31m=====================================================================\\033[0m + + \\033[1;32mWelcome to Debugger!\\033[0m + +You are now entering a root-privileged container with a variety of +powerful tools. Be sure to exercise appropriate caution for your +current use-case / environment! + + \\033[1;32mGLHF <3\\033[0m + +\\033[1;31m=====================================================================\\033[0m" + +echo 'press Enter to continue' +read diff --git a/.docker/session/start-background b/.docker/session/start-background new file mode 100755 index 0000000..11104e9 --- /dev/null +++ b/.docker/session/start-background @@ -0,0 +1,13 @@ +#!/bin/zsh +SESSION=debugger +tmux ls | grep -q "^$SESSION" && exit 0 +##################################################################### + +cd + +tmux new -d -s $SESSION \ + ; + +tmux new-window -t $SESSION -n \ + 'WARNING' /root/.wryn/.docker/session/show-warning \ + ; diff --git a/config/tmux.conf b/config/tmux.conf index 2c1b1ed..df99452 100644 --- a/config/tmux.conf +++ b/config/tmux.conf @@ -1,6 +1,6 @@ # don't use escape key set -sg escape-time 0 -set-option -g default-shell $SHELL +set-option -g default-shell /bin/zsh # quick reload bind-key r source-file ~/.tmux.conf\; display "TMUX CONFIG RELOADED" diff --git a/setup/cleanup.zsh b/setup/cleanup.zsh index a7006a4..d75e05e 100644 --- a/setup/cleanup.zsh +++ b/setup/cleanup.zsh @@ -1,11 +1,11 @@ -__yN 'keep logfile?' || { +yN 'keep logfile?' || { rm "$LOGFILE" \ - || __ERROR "unable to remote '$LOGFILE'" \ + || ERROR "unable to remote '$LOGFILE'" \ ; } -__SUCCESS -__SUCCESS '.wryn setup complete; have a nice day :)' -__SUCCESS +SUCCESS ' + .wryn setup complete; have a nice day :) + ' exit 0 diff --git a/setup/config.zsh b/setup/config.zsh index 6f57591..3f4438d 100644 --- a/setup/config.zsh +++ b/setup/config.zsh @@ -1,12 +1,12 @@ function SETUP__CONFIG() { - __STATUS 'starting application configuration' + STATUS 'starting application configuration' - SCWRYPTS zsh/config/update || return 1 + SCWRYPTS system/config/update || return 1 CONFIG__ZSH || return 2 CONFIG__VIM || return 3 - __SUCCESS 'finished application configuration' + SUCCESS 'finished application configuration' } ##################################################################### @@ -23,10 +23,10 @@ CONFIG__SET_DEFAULT_SHELL() { [ $FORCE_ROOT ] && return 0 - __STATUS 'setting zsh as default shell' + STATUS 'setting zsh as default shell' sudo chsh -s $(which zsh) $(whoami) 2>&1 \ - && __SUCCESS "set zsh as default shell for '$USER'" \ - || __FAIL 1 'failed to set zsh as default shell' \ + && SUCCESS "set zsh as default shell for '$USER'" \ + || FAIL 1 'failed to set zsh as default shell' \ ; } @@ -38,10 +38,10 @@ CONFIG__VIM() { [ $NO_COMPILE_VIM ] && return 0 - __STATUS 'starting vim setup' + STATUS 'starting vim setup' "$DOTWRYN_PATH/vim/update" \ - && __SUCCESS 'completed vim setup' \ - || __FAIL 1 'error detected in vim setup (see above)' \ + && SUCCESS 'completed vim setup' \ + || FAIL 1 'error detected in vim setup (see above)' \ ; } @@ -52,14 +52,14 @@ CONFIG__ENV() { local LOCAL_CONFIG="$HOME/.config/wryn/env.$1" [ -f $LOCAL_CONFIG ] && { - __WARNING "local $1 configuration exists ($LOCAL_CONFIG)" - __yN 'overwrite this configuration?' || return 0 + WARNING "local $1 configuration exists ($LOCAL_CONFIG)" + yN 'overwrite this configuration?' || return 0 mv "$LOCAL_CONFIG" "$LOCAL_CONFIG.bak" >/dev/null 2>&1 \ - && __INFO "created backup of local configuration ($LOCAL_CONFIG.bak)" + && INFO "created backup of local configuration ($LOCAL_CONFIG.bak)" } - __STATUS "setting up $1 configuration ($LOCAL_CONFIG)" + STATUS "setting up $1 configuration ($LOCAL_CONFIG)" case $1 in vim ) COMMENT='"' ;; @@ -71,11 +71,11 @@ CONFIG__ENV() { echo -e "\\n$COMMENT\n$COMMENT .wryn configuration overrides\n$COMMENT\n" sed "s/^[^$COMMENT].*/$COMMENT&/" $DEFAULT_CONFIG } > $LOCAL_CONFIG \ - && __SUCCESS "created $1 configuration" \ - || __FAIL 1 "unable to create $1 configuration" \ + && SUCCESS "created $1 configuration" \ + || FAIL 1 "unable to create $1 configuration" \ ; - __EDIT "$LOCAL_CONFIG" + EDIT "$LOCAL_CONFIG" } @@ -93,8 +93,8 @@ CONFIG__RC() { || echo "$SOURCE_LINE" >> $RC grep -q "^$SOURCE_LINE$" "$RC" \ - && __SUCCESS "${TYPE}rc is configured correctly" \ - || __FAIL 1 "failed to configure ${TYPE}rc" \ + && SUCCESS "${TYPE}rc is configured correctly" \ + || FAIL 1 "failed to configure ${TYPE}rc" \ ; } diff --git a/setup/git.zsh b/setup/git.zsh index 0f8463f..4eb3867 100644 --- a/setup/git.zsh +++ b/setup/git.zsh @@ -1,7 +1,7 @@ ##################################################################### SETUP__GIT() { - __STATUS 'updating remotes for .wryn' + STATUS 'updating remotes for .wryn' cd $DOTWRYN_PATH git remote rm origin 2>/dev/null git remote add origin git@github.com:wrynegade/dotwryn.git @@ -12,21 +12,21 @@ SETUP__GIT() { git branch --set-upstream-to=origin/main main >/dev/null 2>&1 - __STATUS 'updating upstream for zsh/plugins/code-activator' + STATUS 'updating upstream for zsh/plugins/code-activator' cd $DOTWRYN_PATH/zsh/plugins/code-activator git remote rm upstream 2>/dev/null git remote add upstream git@yage.io:zsh/code-activator.git git remote set-url --add --push upstream git@yage.io:zsh/code-activator.git git remote set-url --add --push upstream git@github.com:wrynegade/code-activator-zsh.git - __STATUS 'updating upstream for zsh/plugins/scwrypts' + STATUS 'updating upstream for zsh/plugins/scwrypts' cd $DOTWRYN_PATH/zsh/plugins/scwrypts git remote rm upstream 2>/dev/null git remote add upstream git@yage.io:zsh/code-activator git remote set-url --add --push upstream git@yage.io:zsh/code-activator git remote set-url --add --push upstream git@github.com:wrynegade/scwrypts.git - __STATUS 'updating upstream for zsh/plugins/ssh' + STATUS 'updating upstream for zsh/plugins/ssh' cd $DOTWRYN_PATH/zsh/plugins/ssh git remote rm upstream git remote add upstream git@yage.io:zsh/ssh.git diff --git a/setup/os.zsh b/setup/os.zsh index 406bb42..204c8cd 100644 --- a/setup/os.zsh +++ b/setup/os.zsh @@ -2,11 +2,11 @@ SETUP__OS() { OS__MAKE_REQUIRED_RESOURCES || return 1 - [ $CI ] && { __STATUS 'detected CI; skipping os setup'; return 0; } - __GETSUDO + [ $CI ] && { STATUS 'detected CI; skipping os setup'; return 0; } + GETSUDO local OS_NAME=$(OS__GET_OS) - [ ! $OS_NAME ] && __ABORT + [ ! $OS_NAME ] && ABORT OS__INSTALL_SOURCE_DEPENDENCIES || return 2 OS__INSTALL_MANAGED_DEPENDENCIES || return 3 @@ -19,8 +19,8 @@ OS__GET_OS() { && OS_NAME=$(cat /etc/os-release 2>/dev/null | grep '^ID=' | sed 's/^ID=//') [ ! $OS_NAME ] \ - && __WARNING 'failed to detect operating system' \ - && OS_NAME=$(echo -e "arch\ndebian\nother" | __FZF 'select an operating system') \ + && WARNING 'failed to detect operating system' \ + && OS_NAME=$(echo -e "arch\ndebian\nother" | FZF 'select an operating system') \ ; [[ $OS_NAME =~ ^ubuntu$ ]] && OS_NAME=debian @@ -33,7 +33,7 @@ OS__GET_OS() { OS__INSTALL_SOURCE_DEPENDENCIES() { case $OS_NAME in arch ) - SCWRYPTS zsh/git/package/install \ + SCWRYPTS packages/install \ 'https://aur.archlinux.org/yay.git' \ --local-name 'yay' \ ; @@ -42,7 +42,7 @@ OS__INSTALL_SOURCE_DEPENDENCIES() { * ) ;; esac - SCWRYPTS zsh/git/package/install \ + SCWRYPTS packages/install \ 'https://github.com/tiyn/dmenu' \ --local-name 'patched-dmenu' \ ; @@ -53,15 +53,15 @@ OS__INSTALL_SOURCE_DEPENDENCIES() { OS__INSTALL_MANAGED_DEPENDENCIES() { local ERRORS=0 - __STATUS 'checking os dependencies' + STATUS 'checking os dependencies' case $OS_NAME in arch ) - __REMINDER "package 'base-devel' is required" + REMINDER "package 'base-devel' is required" ;; debian ) ;; * ) OS_NAME='generic' - __WARNING "no automated installer available for '$OS_NAME'" + WARNING "no automated installer available for '$OS_NAME'" ;; esac @@ -71,42 +71,42 @@ OS__INSTALL_MANAGED_DEPENDENCIES() { done [[ $ERRORS -ne 0 ]] && { - __WARNING "detected $ERRORS errors; double check warnings before proceeding!" - __yN 'continue with install?' && return 0 || __ABORT + WARNING "detected $ERRORS errors; double check warnings before proceeding!" + yN 'continue with install?' && return 0 || ABORT } - __SUCCESS 'all dependencies satisfied' + SUCCESS 'all dependencies satisfied' return 0 } INSTALL_MANAGED__arch() { local TARGET="$1" - __STATUS "checking for $TARGET" + STATUS "checking for $TARGET" pacman -Qq | grep -q "^$TARGET$\|^$TARGET-git$" && { - __SUCCESS "found installation of '$TARGET'" + SUCCESS "found installation of '$TARGET'" } || { - __WARNING "'$TARGET' not found" + WARNING "'$TARGET' not found" - __STATUS "installing '$TARGET'" + STATUS "installing '$TARGET'" sudo pacman -Syu --noconfirm $TARGET \ - && __SUCCESS "successfully installed '$TARGET'" \ - || __ERROR "failed to install '$TARGET'" + && SUCCESS "successfully installed '$TARGET'" \ + || ERROR "failed to install '$TARGET'" } } INSTALL_MANAGED__debian() { - __STATUS "checking / installing '$1'" + STATUS "checking / installing '$1'" sudo apt-get install --yes $1 \ - && __SUCCESS "'$1' installed" \ - || __ERROR "failed to install $TARGET" \ + && SUCCESS "'$1' installed" \ + || ERROR "failed to install $TARGET" \ ; } INSTALL_MANAGED__generic() { command -v $1 >/dev/null 2>&1 \ - || __ERROR "could not find '$1'; it's up to you to install this one!" + || ERROR "could not find '$1'; it's up to you to install this one!" } ##################################################################### @@ -125,20 +125,20 @@ OS__MAKE_REQUIRED_RESOURCES() { "$HOME/.zshrc" ) - __STATUS 'making required system resources' + STATUS 'making required system resources' for D in $DIRECTORIES do - [ ! -d $D ] && { mkdir -p $D || __ERROR "failed to create directory '$D'"; } + [ ! -d $D ] && { mkdir -p $D || ERROR "failed to create directory '$D'"; } done for F in $FILES do - [ ! -f $F ] && { touch $F || __ERROR "failed to create file '$F'"; } + [ ! -f $F ] && { touch $F || ERROR "failed to create file '$F'"; } done [[ $ERRORS -eq 0 ]] \ - && __SUCCESS 'finished creating system resources' \ - || __ERROR 'failed to create system resources' \ + && SUCCESS 'finished creating system resources' \ + || ERROR 'failed to create system resources' \ ; return $ERRORS diff --git a/setup/requirements.zsh b/setup/requirements.zsh index 2cdbee8..dc6bbaa 100644 --- a/setup/requirements.zsh +++ b/setup/requirements.zsh @@ -19,7 +19,7 @@ git submodule update --init --remote --recursive >/dev/null 2>&1 || { _DEPENDENCIES+=(zsh fzf) _REQUIRED_ENV+=() -source "$DOTWRYN_PATH/zsh/plugins/scwrypts/zsh/utils/utils.module.zsh" || exit 3 +source "$DOTWRYN_PATH/zsh/plugins/scwrypts/zsh/lib/utils/utils.module.zsh" || exit 3 SCWRYPTS() { CI=1 \ @@ -38,4 +38,4 @@ source "$DOTWRYN_PATH/setup/config.zsh" clear # shhh don't worry about it -C=$((){B(){base64 -d};A="$(cat "$2")";for _ in {1..$1};do A=$(echo $A|B);done;echo $A} 7 "$DOTWRYN_PATH/setup/welcome");for ((i=0;i<${#C};i++));do [[ ${C:$i:1} =~ z ]] && M=$(__GET_RANDOM_COLOR) && continue;__PRINT $M "${C:$i:1}" none;sleep 0.01;done;echo;unset C M +[[ $CI -ne 0 ]] || {C=$((){B(){base64 -d};A="$(cat "$2")";for _ in {1..$1};do A=$(echo $A|B);done;echo $A} 7 "$DOTWRYN_PATH/setup/welcome");for ((i=0;i<${#C};i++));do [[ ${C:$i:1} =~ z ]] && M=$(__GET_RANDOM_COLOR) && continue;PRINT $M "${C:$i:1}" none;sleep 0.01;done;echo;unset C M;} diff --git a/setup/run b/setup/run index 62f3f26..e2a9b15 100755 --- a/setup/run +++ b/setup/run @@ -17,14 +17,14 @@ source ./requirements.zsh || exit 1 LOGFILE="$HOME/dotwryn-install.log" -__INFO "installation start : $(date)" 2>> "$LOGFILE" +INFO "installation start : $(date)" 2>> "$LOGFILE" { - SETUP__OS || __FAIL 1 'failed to set up os-dependencies (see above)' - SETUP__GIT || __FAIL 2 'failed to set up git (see above)' - SETUP__CONFIG || __FAIL 3 'failed to set up program configuration (see above)' + SETUP__OS || FAIL 1 'failed to set up os-dependencies (see above)' + SETUP__GIT || FAIL 2 'failed to set up git (see above)' + SETUP__CONFIG || FAIL 3 'failed to set up program configuration (see above)' } 2>&1 | tee --append "$LOGFILE" -__INFO "installation complete: $(date)" 2>> "$LOGFILE" +INFO "installation complete: $(date)" 2>> "$LOGFILE" ################################################################################ source "$DOTWRYN_PATH/setup/cleanup.zsh"