From fff911321624b3cc4131037ae0c303c5ae338f0b Mon Sep 17 00:00:00 2001 From: Wryn Wagner Date: Wed, 15 Sep 2021 01:48:37 -0600 Subject: [PATCH] new setup version; more modular --- bin/desktop/feh/randomize-background.sh | 2 +- bin/desktop/kitty/alternate-terminal.sh | 2 +- bin/desktop/sfx/play.sh | 2 +- bin/desktop/youtube-music/next.sh | 2 +- bin/desktop/youtube-music/playpause.sh | 2 +- bin/desktop/youtube-music/previous.sh | 2 +- bin/vim/update_colorschemes | 2 +- config/i3/utils | 2 +- config/xorg/screenlayout/gamedock.sh | 2 +- config/xorg/screenlayout/hdmidock.sh | 2 +- config/xorg/screenlayout/homedock.sh | 2 +- config/xorg/screenlayout/tvdock.sh | 2 +- config/xorg/screenlayout/undock.sh | 2 +- config/xorg/set_randr_layout | 2 +- config/xorg/xinitrc | 2 +- env/{env => env.zsh} | 0 setup | 301 ------------------------ setup/dotconfig/setup.zsh | 46 ++++ setup/linux | 129 ++++++++++ setup/os-dependencies/arch.txt | 5 + setup/os-dependencies/debian.txt | 5 + setup/os-dependencies/generic.txt | 5 + setup/os-dependencies/setup.zsh | 78 ++++++ setup/vim/setup.zsh | 80 +++++++ setup/zsh/setup.zsh | 54 +++++ zsh/rc | 2 +- zsh/utils/color.zsh | 21 ++ zsh/utils/color/check.zsh | 26 ++ zsh/utils/color/console-color-out.zsh | 19 ++ zsh/utils/color/messages.zsh | 29 +++ zsh/utils/color/names.zsh | 23 ++ zsh/utils/color/prefix.zsh | 0 zsh/utils/user-input.zsh | 4 + 33 files changed, 540 insertions(+), 317 deletions(-) rename env/{env => env.zsh} (100%) mode change 100755 => 100644 delete mode 100755 setup create mode 100644 setup/dotconfig/setup.zsh create mode 100755 setup/linux create mode 100644 setup/os-dependencies/arch.txt create mode 100644 setup/os-dependencies/debian.txt create mode 100644 setup/os-dependencies/generic.txt create mode 100644 setup/os-dependencies/setup.zsh create mode 100644 setup/vim/setup.zsh create mode 100644 setup/zsh/setup.zsh create mode 100644 zsh/utils/color.zsh create mode 100644 zsh/utils/color/check.zsh create mode 100644 zsh/utils/color/console-color-out.zsh create mode 100644 zsh/utils/color/messages.zsh create mode 100644 zsh/utils/color/names.zsh create mode 100644 zsh/utils/color/prefix.zsh create mode 100644 zsh/utils/user-input.zsh diff --git a/bin/desktop/feh/randomize-background.sh b/bin/desktop/feh/randomize-background.sh index 22436b0..9e63831 100755 --- a/bin/desktop/feh/randomize-background.sh +++ b/bin/desktop/feh/randomize-background.sh @@ -1,4 +1,4 @@ -source "$HOME/.config/wryn/env/env" +source "$HOME/.config/wryn/env/env.zsh" [ -d "$WALLPAPER_PATH" ] \ && feh --recursive --randomize --bg-fill "$WALLPAPER_PATH"; diff --git a/bin/desktop/kitty/alternate-terminal.sh b/bin/desktop/kitty/alternate-terminal.sh index 6e8876c..d81bf66 100755 --- a/bin/desktop/kitty/alternate-terminal.sh +++ b/bin/desktop/kitty/alternate-terminal.sh @@ -1,6 +1,6 @@ #!/bin/sh -source "$HOME/.config/wryn/env/env" +source "$HOME/.config/wryn/env/env.zsh" CONFIG_DIR="$DOTWRYN/config/kitty" diff --git a/bin/desktop/sfx/play.sh b/bin/desktop/sfx/play.sh index 948d1d2..e88ed85 100755 --- a/bin/desktop/sfx/play.sh +++ b/bin/desktop/sfx/play.sh @@ -1,5 +1,5 @@ #!/bin/sh -source "$HOME/.config/wryn/env/env" 2>/dev/null +source "$HOME/.config/wryn/env/env.zsh" 2>/dev/null PLAY() { eval "$MEDIA_ENGINE" "$SFX_PATH/$1" diff --git a/bin/desktop/youtube-music/next.sh b/bin/desktop/youtube-music/next.sh index e481155..12281a9 100755 --- a/bin/desktop/youtube-music/next.sh +++ b/bin/desktop/youtube-music/next.sh @@ -1,3 +1,3 @@ -source "$HOME/.config/wryn/env/env" +source "$HOME/.config/wryn/env/env.zsh" "$DOTWRYN/bin/desktop/youtube-music/controller.sh" next diff --git a/bin/desktop/youtube-music/playpause.sh b/bin/desktop/youtube-music/playpause.sh index 374fb44..f83e0bd 100755 --- a/bin/desktop/youtube-music/playpause.sh +++ b/bin/desktop/youtube-music/playpause.sh @@ -1,3 +1,3 @@ -source "$HOME/.config/wryn/env/env" +source "$HOME/.config/wryn/env/env.zsh" "$DOTWRYN/bin/desktop/youtube-music/controller.sh" playpause diff --git a/bin/desktop/youtube-music/previous.sh b/bin/desktop/youtube-music/previous.sh index 5ccdfd6..fce634d 100755 --- a/bin/desktop/youtube-music/previous.sh +++ b/bin/desktop/youtube-music/previous.sh @@ -1,3 +1,3 @@ -source "$HOME/.config/wryn/env/env" +source "$HOME/.config/wryn/env/env.zsh" "$DOTWRYN/bin/desktop/youtube-music/controller.sh" prev diff --git a/bin/vim/update_colorschemes b/bin/vim/update_colorschemes index f56b515..a28fc95 100755 --- a/bin/vim/update_colorschemes +++ b/bin/vim/update_colorschemes @@ -1,5 +1,5 @@ #!/bin/bash -source "$HOME/.config/wryn/env/env" +source "$HOME/.config/wryn/env/env.zsh" [ ! -d "$HOME/.vim" ] && mkdir "$HOME/.vim" [ ! -d "$HOME/.vim/colors" ] && mkdir "$HOME/.vim/colors" diff --git a/config/i3/utils b/config/i3/utils index bee984d..20945ec 100755 --- a/config/i3/utils +++ b/config/i3/utils @@ -1,6 +1,6 @@ #!/bin/sh -source "$HOME/.config/wryn/env/env" +source "$HOME/.config/wryn/env/env.zsh" UTIL_BIN="$DOTWRYN/bin/desktop" APP_BIN="$HOME/.config/wryn/default-applications" diff --git a/config/xorg/screenlayout/gamedock.sh b/config/xorg/screenlayout/gamedock.sh index d0710fb..4e42aad 100755 --- a/config/xorg/screenlayout/gamedock.sh +++ b/config/xorg/screenlayout/gamedock.sh @@ -1,5 +1,5 @@ #!/bin/sh -source "$HOME/.config/wryn/env/env" +source "$HOME/.config/wryn/env/env.zsh" RESOLUTION='1920x1080'; diff --git a/config/xorg/screenlayout/hdmidock.sh b/config/xorg/screenlayout/hdmidock.sh index 37d8150..33103a0 100755 --- a/config/xorg/screenlayout/hdmidock.sh +++ b/config/xorg/screenlayout/hdmidock.sh @@ -1,5 +1,5 @@ #!/bin/sh -source "$HOME/.config/wryn/env/env" +source "$HOME/.config/wryn/env/env.zsh" NATIVE_MONITOR='eDP1'; CONNECTED_MONITOR=$(xrandr | grep ' connect' | awk '{print $1;}' | grep -v "$NATIVE_MONITOR" | head -n 1); diff --git a/config/xorg/screenlayout/homedock.sh b/config/xorg/screenlayout/homedock.sh index 740517d..657f224 100755 --- a/config/xorg/screenlayout/homedock.sh +++ b/config/xorg/screenlayout/homedock.sh @@ -1,5 +1,5 @@ #!/bin/sh -source "$HOME/.config/wryn/env/env" +source "$HOME/.config/wryn/env/env.zsh" NATIVE_MONITOR='eDP1'; HOMEDOCK_MONITOR=$(xrandr | grep ' connect' | awk '{print $1;}' | grep -v "$NATIVE_MONITOR" | head -n 1); diff --git a/config/xorg/screenlayout/tvdock.sh b/config/xorg/screenlayout/tvdock.sh index fd41d5e..ba4fd5d 100755 --- a/config/xorg/screenlayout/tvdock.sh +++ b/config/xorg/screenlayout/tvdock.sh @@ -1,5 +1,5 @@ #!/bin/sh -source "$HOME/.config/wryn/env/env" +source "$HOME/.config/wryn/env/env.zsh" NATIVE_MONITOR='eDP1'; TV_DISPLAY=$(xrandr | grep ' connect' | awk '{print $1;}' | grep -v "$NATIVE_MONITOR" | head -n 1); diff --git a/config/xorg/screenlayout/undock.sh b/config/xorg/screenlayout/undock.sh index 44cb21e..e5c29b6 100755 --- a/config/xorg/screenlayout/undock.sh +++ b/config/xorg/screenlayout/undock.sh @@ -1,5 +1,5 @@ #!/bin/sh -source "$HOME/.config/wryn/env/env" +source "$HOME/.config/wryn/env/env.zsh" NATIVE_MONITOR='eDP1'; NATIVE_MODE="$(xrandr | grep -A 2 "$NATIVE_MONITOR" | sed -n '2 p' | awk '{print $1;}')"; diff --git a/config/xorg/set_randr_layout b/config/xorg/set_randr_layout index 5364028..93a4872 100755 --- a/config/xorg/set_randr_layout +++ b/config/xorg/set_randr_layout @@ -1,5 +1,5 @@ #!/bin/zsh -source "$HOME/.config/wryn/env/env" +source "$HOME/.config/wryn/env/env.zsh" XSERVER_DIR="$DOTWRYN/config/xorg" AT_HOME(){ diff --git a/config/xorg/xinitrc b/config/xorg/xinitrc index 88779af..7989a83 100644 --- a/config/xorg/xinitrc +++ b/config/xorg/xinitrc @@ -1,6 +1,6 @@ #!/bin/sh -source "$HOME/.config/wryn/env/env" +source "$HOME/.config/wryn/env/env.zsh" X11_SCRIPTS='/etc/X11/xinit/xinitrc.d'; if [ -d $X11_SCRIPTS ] ; then diff --git a/env/env b/env/env.zsh old mode 100755 new mode 100644 similarity index 100% rename from env/env rename to env/env.zsh diff --git a/setup b/setup deleted file mode 100755 index 0d0a14d..0000000 --- a/setup +++ /dev/null @@ -1,301 +0,0 @@ -#!/usr/bin/zsh - -################################################################################ -### SETUP VERIFICATION ######################################################### -################################################################################ - -DOTWRYN_PATH="$(pwd)" -function CHECK_DIR() { - printf "is DOTWRYN.git installed at '$DOTWRYN_PATH'? [Yn] : " - local yn; read yn - - [[ $yn =~ ^[nN] ]] && return 1 || return 0 -} - -function INSTALL_DEPENDENCIES() { - local OS_NAME=$(lsb_release -is | tr '[:upper:]' '[:lower:]') - - local GENERIC_DEPS=(python3 cmake lolcat figlet cowsay) - local ARCH_DEPS=(python cmake lolcat figlet cowsay) - local DEBIAN_DEPS=(python3-dev cmake lolcat figlet cowsay) - - MISSING_DEPS=() - - echo 'checking dependencies...' - for DEP in $GENERIC_DEPS; - do - command -v $DEP >/dev/null 2>&1 || { - echo "missing '$DEP'" - MISSING_DEPS+=$DEP - } - done - - [[ ${#MISSING_DEPS[@]} -eq 0 ]] && { - echo '...all dependencies appear to be satisfied' - } || { - case $OS_NAME in - arch ) - sudo pacman -Syu $ARCH_DEPS - ;; - debian | ubuntu ) - sudo apt-get install $DEBIAN_DEPS - ;; - * ) - echo "manual dependency installation required for os '$OS_NAME'..." - echo "missing : $MISSING_DEPS" - printf 'are you ready to proceed with setup? [yN] : ' - local yn; read yn - [[ $yn =~ ^[yY] ]] && return 0 || return 1 - ;; - esac - } -} - - -CHECK_DIR || exit 1 -INSTALL_DEPENDENCIES || exit 1 - - -################################################################################ -### SHELL SETUP ################################################################ -################################################################################ - -function SOURCE_DOTWRYN_RC { - local HOME_RC="$1"; - local WRYN_RC="$2"; - - [ ! -f "$HOME/$HOME_RC" ] && touch "$HOME/$HOME_RC"; - - grep "$WRYN_RC" "$HOME/$HOME_RC" && { - echo "already set up $HOME_RC"; - } || { - echo "source $WRYN_RC" >> "$HOME/$HOME_RC"; - echo "successfully set up $HOME_RC"; - } -} - -function ENV__SETUP_LOCAL_OVERRIDES() { - local yn - - local DEFAULT_SHELL_ENV="$DOTWRYN_PATH/env/env" - local LOCAL_SHELL_ENV="$HOME/.config/wryn/env/env" - - [ $LOCAL_SHELL_ENV ] && { - printf 'local env override file detected; overwrite? [yN] : ' - read yn - [[ $yn =~ ^[yY] ]] || DO_NOT_OVERWRITE_SHELL=1 - } - - [[ $DO_NOT_OVERWRITE_SHELL -eq 1 ]] && echo 'skipping shell env setup' || { - echo "source $DOTWRYN_PATH/env/env" > "$LOCAL_SHELL_ENV" - echo -e '\n#\n# ~/.wryn/env/env local overrides\n#\n' >> "$LOCAL_SHELL_ENV" - sed 's/[#]*\(.*\)/#\1/' $DEFAULT_SHELL_ENV >> "$LOCAL_SHELL_ENV" - } - - local DEFAULT_VIM_ENV="$DOTWRYN_PATH/env/env.vim" - local LOCAL_VIM_ENV="$HOME/.config/wryn/env/env.vim" - - [ $LOCAL_SHELL_ENV ] && { - printf 'local vim env override file detected; overwrite? [yN] : ' - read yn - [[ $yn =~ ^[yY] ]] || DO_NOT_OVERWRITE_VIM=1 - } - - [[ $DO_NOT_OVERWRITE_VIM -eq 1 ]] && echo 'skipping vim env setup' || { - echo "source $DOTWRYN_PATH/env/env.vim" > "$LOCAL_VIM_ENV" - echo -e '\n"\n" ~/.wryn/env/env.vim local overrides\n"\n' >> "$LOCAL_VIM_ENV" - sed 's/["]*\(.*\)/"\1/' $DEFAULT_VIM_ENV >> "$LOCAL_VIM_ENV" - } -} - -function SHELL__SETUP { - SOURCE_DOTWRYN_RC '.bashrc' "$DOTWRYN_PATH/zsh/rc"; - SOURCE_DOTWRYN_RC '.zshrc' "$DOTWRYN_PATH/zsh/rc"; - - ENV__SETUP_LOCAL_OVERRIDES; -} - - -################################################################################ -### VIM SETUP ################################################################## -################################################################################ - -function VIM__UPDATE_COLORSCHEMES() { - $DOTWRYN_PATH/bin/vim/update_colorschemes -} - -function VIM__INSTALL_VUNDLE_PLUGINS() { - [ ! -d "$HOME/.vim" ] && mkdir "$HOME/.vim" - [ ! -d "$HOME/.vim/bundle" ] && mkdir "$HOME/.vim/bundle" - [ ! -d "$HOME/.vim/bundle/Vundle.vim" ] && { - echo "installing vundle"; - git clone https://github.com/VundleVim/Vundle.vim.git "$HOME/.vim/bundle/Vundle.vim"; - } - - echo "installing vundle plugins" - vim +PluginInstall +qall; - - echo "building plugins" - $DOTWRYN_PATH/bin/vim/rebuild_plugins; -} - -function VIM__SETUP() { - echo 'setting up vim'; - - SOURCE_DOTWRYN_RC '.vimrc' "$DOTWRYN_PATH/vim/rc.vim"; - - VIM__UPDATE_COLORSCHEMES; - VIM__INSTALL_VUNDLE_PLUGINS; - - echo 'vim setup complete'; -} - - -################################################################################ -### LINK CONFIGURATION FILES ################################################### -################################################################################ - -function CONFIG__BASIC_SYMLINK() { - local HOME_CONFIG="$1"; - local WRYN_CONFIG="$2"; - - mv "$HOME_CONFIG" "$HOME_CONFIG.bak" >/dev/null 2>&1; - ln -s "$WRYN_CONFIG" "$HOME_CONFIG"; -} - -function CONFIG__SYMLINK() { - local CONFIG_DIR="$1"; - local FILENAME="$2"; - - local HOME_CONFIG_DIR="$HOME/.config/$CONFIG_DIR"; - local HOME_CONFIG="$HOME_CONFIG_DIR/$FILENAME"; - - local WRYN_CONFIG="$DOTWRYN_PATH/config/$CONFIG_DIR/$FILENAME"; - - [ ! -d "$HOME_CONFIG_DIR" ] && mkdir "$HOME_CONFIG_DIR"; - - CONFIG__BASIC_SYMLINK $HOME_CONFIG $WRYN_CONFIG; -} - - -function CONFIG__I3() { - CONFIG__SYMLINK "i3" "config"; - CONFIG__BASIC_SYMLINK "$HOME/.config/wryn/i3utils" "$DOTWRYN_PATH/config/i3/utils"; - echo "linked i3 configuration"; -} - -function CONFIG__I3STATUS() { - CONFIG__SYMLINK "i3status" "config"; - echo "linked i3status configuration"; -} - -function CONFIG__PGCLI() { - CONFIG__SYMLINK "pgcli" "config"; - echo "linked pgcli configuration"; -} - -function CONFIG__MSSQLCLI() { - CONFIG__SYMLINK "mssqlcli" "config"; - echo "linked mssqlcli configuration"; -} - -function CONFIG__COMPTON() { - CONFIG__SYMLINK "compton" "compton.conf"; - echo "linked compton configuration" -} - -function CONFIG__KITTY() { - CONFIG__SYMLINK "kitty" "kitty.conf"; - CONFIG__SYMLINK "kitty" "theme.conf"; - - echo "linked kitty configuration" -} - -function CONFIG__RIPGREP() { - CONFIG__SYMLINK "ripgrep" "config" - echo "linked ripgrep configuration" -} - -function CONFIG__GIT() { - CONFIG__BASIC_SYMLINK "$HOME/.gitconfig" "$DOTWRYN_PATH/config/git/gitconfig"; - echo "linked global git configuration" -} - -function CONFIG__PYLINT() { - CONFIG__BASIC_SYMLINK "$HOME/.config/pylintrc" "$DOTWRYN_PATH/config/pylint/pylintrc"; - echo "linked pylint configuration" -} - -function CONFIG__SFX_APPLICATION() { - CONFIG__BASIC_SYMLINK "$HOME/.config/wryn/sfx" "$DOTWRYN_PATH/bin/desktop/sfx/play.sh"; - echo "linked xinitrc" -} - -function CONFIG__TMUX() { - CONFIG__BASIC_SYMLINK "$HOME/.tmux.conf" "$DOTWRYN_PATH/config/tmux/tmux.conf"; - echo "linked tmux configuration" -} - -function CONFIG__XINITRC() { - CONFIG__BASIC_SYMLINK "$HOME/.xinitrc" "$DOTWRYN_PATH/config/xorg/xinitrc" - echo "linked xinitrc" -} - - -function CONFIG__TERMINFO() { - echo "adding terminfo files" - for file in $(find "$DOTWRYN_PATH/config/terminfo" -type f); do - tic -x $file >/dev/null 2>&1 || echo "failed to add $file" ; - done -} - -function CLEAN_BACKUP() { - read -p "clean backup files? [Yn] : " yn; - - case $yn in - [nN]* ) echo 'skipping cleanup';; - * ) - echo 'cleaning backup files'; - for file in $(find "$HOME/.config/" -name \*.bak 2>/dev/null); do rm $file && echo cleaned $file; done - for file in $(find "$HOME" -maxdepth 1 -name .\*.bak 2>/dev/null); do rm $file && echo cleaned $file; done - ;; - esac -} - - -function CONFIG__SETUP() { - CONFIG__I3; - CONFIG__I3STATUS; - CONFIG__PGCLI; - CONFIG__MSSQLCLI; - CONFIG__COMPTON; - CONFIG__KITTY; - CONFIG__RIPGREP; - - CONFIG__GIT; - CONFIG__PYLINT; - CONFIG__SFX_APPLICATION; - CONFIG__TMUX; - CONFIG__XINITRC; - - CONFIG__TERMINFO; - - - CLEAN_BACKUP -} - - -################################################################################ -### RUN CONFIG ################################################################# -################################################################################ - - -[ ! -d "$HOME/.config" ] && mkdir "$HOME/.config"; -[ ! -d "$HOME/.config/wryn" ] && mkdir "$HOME/.config/wryn"; -[ ! -d "$HOME/.config/wryn/env" ] && mkdir "$HOME/.config/wryn/env"; - -SHELL__SETUP -VIM__SETUP -CONFIG__SETUP - -echo -e "\nsetup complete" diff --git a/setup/dotconfig/setup.zsh b/setup/dotconfig/setup.zsh new file mode 100644 index 0000000..84a1be2 --- /dev/null +++ b/setup/dotconfig/setup.zsh @@ -0,0 +1,46 @@ +DOTCONFIG__SETUP() { + ############################################################################################ + # Friendly Name ~/.config/THE_REST .wryn/config/THE_REST (if different) + CONFIG__SYMLINK 'compton' 'compton/compton.conf' + CONFIG__SYMLINK 'git config' '../.gitconfig' 'git/gitconfig' + CONFIG__SYMLINK 'i3 config' 'i3/config' + CONFIG__SYMLINK 'i3 status' 'i3status/config' + CONFIG__SYMLINK 'i3 utils' 'wryn/i3utils' 'i3/utils' + CONFIG__SYMLINK 'kitty config' 'kitty/kitty.conf' + CONFIG__SYMLINK 'kitty theme' 'kitty/theme.conf' + CONFIG__SYMLINK 'mssqlcli' 'mssqlcli/config' + CONFIG__SYMLINK 'pgcli' 'pgcli/config' + CONFIG__SYMLINK 'pylint global' 'pylintrc' 'pylint/pylintrc' + CONFIG__SYMLINK 'ripgrep' 'ripgrep/config' + CONFIG__SYMLINK 'sfx app' "wryn/sfx" '../bin/desktop/sfx/play.sh' + CONFIG__SYMLINK 'tmux' '../.tmux.conf' 'tmux/tmux.conf' + CONFIG__SYMLINK 'xinitrc' '../.xinitrc' 'xorg/xinitrc' + ############################################################################################ + + CONFIG__TERMINFO +} + +function CONFIG__SYMLINK() { + local CONFIG_NAME="$1" + + local TARGET="$2" + local LOCAL_CONFIG="$HOME/.config/$TARGET" + + # don't use third argument if config layout is identical + [ $3 ] && TARGET="$3" + local DOTWRYN_CONFIG="$DOTWRYN_PATH/config/$TARGET" + + CHECK "linking $1" + { + mv "$LOCAL_CONFIG" "$LOCAL_CONFIG.bak" + ln -s "$DOTWRYN_CONFIG" "$LOCAL_CONFIG" + } >>$LOG 2>&1 && OK || WARN +} + +function CONFIG__TERMINFO() { + for file in $(find "$DOTWRYN_PATH/config/terminfo" -type f); do + CHECK "adding '$file' terminfo" + tic -x $file >>$LOG 2>&1 \ + && OK || WARN + done +} diff --git a/setup/linux b/setup/linux new file mode 100755 index 0000000..8154666 --- /dev/null +++ b/setup/linux @@ -0,0 +1,129 @@ +#!/usr/bin/zsh +[[ $EUID -eq 0 ]] && { echo 'ERROR::Setup cannot be run as root'; exit 1; } +command -v zsh >/dev/null || { echo 'ERROR::`zsh` required'; exit 1; } + +################################################################################ +### Pre/Post Processing ######################################################## +################################################################################ + +cd "${0:a:h}" +export DOTWRYN_PATH="$(git rev-parse --show-toplevel)" + +INIT() { + source "$DOTWRYN_PATH/zsh/utils/color.zsh" + source "$DOTWRYN_PATH/zsh/utils/user-input.zsh" + STATUS 'starting .wryn install' + + export LOG="$HOME/dotwryn-install.log" + echo "install start : $(date)" > $LOG + STATUS "subprocess log can be found here : $LOG" +} + +CLEANUP() { + local ERROR="$1" + CLEAN_BACKUP + + [ ! $ERROR ] \ + && USER_PROMPT "keep logfile ($LOG)? [y/N]" \ + || USER_PROMPT "keep logfile ($LOG)? [Y/n]" \ + ; + + READ_K yn + case $yn in + y | Y ) + STATUS 'keeping logfile' + ;; + n | N ) + CHECK 'removing logfile' + rm $LOG && OK || WARN "unable to remove '$LOG'" + ;; + * ) + [ $ERROR ] && { STATUS 'keeping logfile'; return; } + CHECK 'removing logfile' + rm $LOG && OK || WARN "unable to remove '$LOG'" + ;; + esac +} + +CLEAN_BACKUP() { + USER_PROMPT 'clean backup files? [Y/n]' + READ_K yn + + case $yn in + [nN]* ) STATUS 'skipping cleanup' ;; + * ) + STATUS 'cleaning backup files' + for file in $(find "$HOME/.config/" -name \*.bak 2>/dev/null) + do + CHECK "removing '$file'" + rm $file >>$LOG 2>&1 && OK || WARN + done + for file in $(find "$HOME" -maxdepth 1 -name .\*.bak 2>/dev/null) + do + CHECK "removing '$file'" + rm $file >>$LOG 2>&1 && OK || WARN + done + ;; + esac +} + +################################################################################ +### General Setup Utilities #################################################### +################################################################################ + +GET_SUDO_PASSWORD() { + sudo echo hi >/dev/null 2>&1 +} + +MAKE_REQUIRED_DIRECTORY_STRUCTURE() { + DIRECTORIES=( + "$HOME/.config" + "$HOME/.config/wryn" + "$HOME/.config/wryn/env" + "$HOME/.vim" + "$HOME/.vim/colors" + "$HOME/.vim/bundle" + ) + FILES=( + "$HOME/.zshrc" + "$HOME/.vimrc" + ) + + for D in $DIRECTORIES; do [ ! -d $D ] && mkdir $D; done + for F in $FILES; do [ ! -f $F ] && touch $F; done +} + +################################################################################ + +source "$DOTWRYN_PATH/setup/os-dependencies/setup.zsh" +source "$DOTWRYN_PATH/setup/zsh/setup.zsh" +source "$DOTWRYN_PATH/setup/vim/setup.zsh" +source "$DOTWRYN_PATH/setup/dotconfig/setup.zsh" + +################################################################################ + +################################################################################ +### Full Setup ################################################################# +################################################################################ + +INIT + +GET_SUDO_PASSWORD +OS_DEPENDENCY__SETUP || FATAL 'user abort' +MAKE_REQUIRED_DIRECTORY_STRUCTURE + +ZSH__SETUP || ERROR=1 +VIM__SETUP || ERROR=2 +DOTCONFIG__SETUP || ERROR=3 + +CLEANUP $ERROR + +################################################################################ + +SUCCESS +SUCCESS '.wryn setup complete; have a nice day :)' +SUCCESS +echo +echo + +exit 0 diff --git a/setup/os-dependencies/arch.txt b/setup/os-dependencies/arch.txt new file mode 100644 index 0000000..8ac64ab --- /dev/null +++ b/setup/os-dependencies/arch.txt @@ -0,0 +1,5 @@ +cmake +cowsay +figlet +lolcat +python diff --git a/setup/os-dependencies/debian.txt b/setup/os-dependencies/debian.txt new file mode 100644 index 0000000..f22323a --- /dev/null +++ b/setup/os-dependencies/debian.txt @@ -0,0 +1,5 @@ +cmake +cowsay +figlet +lolcat +python3-dev diff --git a/setup/os-dependencies/generic.txt b/setup/os-dependencies/generic.txt new file mode 100644 index 0000000..5de4d63 --- /dev/null +++ b/setup/os-dependencies/generic.txt @@ -0,0 +1,5 @@ +cmake +cowsay +figlet +lolcat +python3 diff --git a/setup/os-dependencies/setup.zsh b/setup/os-dependencies/setup.zsh new file mode 100644 index 0000000..e727910 --- /dev/null +++ b/setup/os-dependencies/setup.zsh @@ -0,0 +1,78 @@ +################################################################################ +### Automated System Dependency Install ######################################## +################################################################################ + +[ $DOTWRYN_PATH ]\ + && DEPENDENCY_DIR="$DOTWRYN_PATH/setup/os-dependencies" \ + || DEPENDENCY_DIR="${0:a:h}" + +function OS_DEPENDENCY__SETUP() { + local ERROR=0 + STATUS 'checking os dependencies' + + local OS_NAME=$(lsb_release -is | tr '[:upper:]' '[:lower:]') + STATUS "detected os '$OS_NAME'" + + case $OS_NAME in + arch ) + OS_INSTALL() { OS_INSTALL__ARCH $@; } + ;; + debian | ubuntu ) + OS_INSTALL() { OS_INSTALL__DEBIAN $@; } + OS_NAME='debian' + ;; + * ) + WARNING + WARNING "no automated installer available for '$OS_NAME'" + WARNING "if dependency shows a warning, install the indicated package" + WARNING + OS_INSTALL() { OS_INSTALL__GENERIC $@; } + OS_NAME='generic' + ;; + esac + + for DEPENDENCY in $(cat "$DEPENDENCY_DIR/$OS_NAME.txt") + do + OS_INSTALL $DEPENDENCY || ERROR=1 + done + unset -f OS_INSTALL + + [[ $ERROR -eq 0 ]] && { + SUCCESS 'all dependencies satisfied' + USER_PROMPT 'continue with install? [Y/n]' + READ_K yn + [[ $yn =~ ^[nN] ]] && ERROR=1; true + } || { + WARNING 'detected errors; double check warnings before proceeding!' + USER_PROMPT 'continue with install? [y/N]' + READ_K yn + [[ $yn =~ ^[yY] ]] && ERROR=0 + } + + return $ERROR +} + +function OS_INSTALL__ARCH() { + local TARGET="$1" + CHECK "checking for $TARGET" + pacman -Qq | grep -q "^$TARGET$" && OK || { + WARN "$TARGET not found" + CHECK "installing $TARGET" + sudo pacman -Syu --noconfirm $TARGET >>$LOG 2>&1 \ + && OK || { WARN "failed to install $TARGET"; return 1; } + } +} + +function OS_INSTALL__DEBIAN() { + local TARGET="$1" + CHECK "checking / installing $PACKAGE" + sudo apt-get install --yes $PACKAGE >>$LOG 2>&1 \ + && OK || { WARN "failed to install $TARGET"; return 1; } +} + +function OS_INSTALL__GENERIC() { + local COMMAND="$1" + CHECK "checking for $COMMAND" + command -v $COMMAND >/dev/null 2>&1 \ + && OK || { WARN; return 1; } +} diff --git a/setup/vim/setup.zsh b/setup/vim/setup.zsh new file mode 100644 index 0000000..6459759 --- /dev/null +++ b/setup/vim/setup.zsh @@ -0,0 +1,80 @@ +##################################################################### + +function VIM__SETUP() { + VIM__SOURCE_RC + VIM__SET_LOCAL_CONFIG + VIM__UPDATE_COLORSCHEMES + VIM__INSTALL_VUNDLE_PLUGINS +} + +VIM__VUNDLE_TARGET='https://github.com/VundleVim/Vundle.vim.git' +VIM__VUNDLE_LOCAL="$HOME/.vim/bundle/Vundle.vim" + +##################################################################### + +function VIM__SOURCE_RC() { + local LOCAL_VIMRC="$HOME/.vimrc"; + local SOURCE_LINE="source $DOTWRYN_PATH/vim/rc.vim"; + + grep -q "^$SOURCE_LINE$" $LOCAL_VIMRC && { + STATUS 'already set up vimrc' + } || { + CHECK 'setting up vimrc' + echo $SOURCE_LINE >> $LOCAL_VIMRC \ + && OK || WARN + } +} + +function VIM__SET_LOCAL_CONFIG() { + local DEFAULT_CONFIG="$DOTWRYN_PATH/env/env.vim" + local LOCAL_CONFIG="$HOME/.config/wryn/env/env.vim" + + [ -f $LOCAL_CONFIG ] && { + WARNING "local vim env configuration ($LOCAL_CONFIG)" + USER_PROMPT 'overwrite? [y/N]' + READ_K yn + [[ $yn =~ ^[yY] ]] && { + CHECK "backing up local copy ($LOCAL_CONFIG.bak)" + mv "$LOCAL_CONFIG" "$LOCAL_CONFIG.bak" && OK || WARN + } || { + STATUS 'skipping' + return + } + } + + CHECK "setting vim configuration file ($LOCAL_CONFIG)" + { + echo "source $DEFAULT_CONFIG" + echo -e '\n"\n" .wryn configuration overrides\n"\n' + sed 's/["]*\(.*\)/"\1/' $DEFAULT_CONFIG + } > $LOCAL_CONFIG && OK || WARN +} + +function VIM__UPDATE_COLORSCHEMES() { + CHECK 'updating colorschemes' + $DOTWRYN_PATH/bin/vim/update_colorschemes >>$LOG 2>&1\ + && OK || WARN +} + +function VIM__INSTALL_VUNDLE_PLUGINS() { + [ ! -d "$HOME/.vim/bundle/Vundle.vim" ] && { + CHECK 'installing Vundle.vim' + git clone $VIM__VUNDLE_TARGET $VIM__VUNDLE_LOCAL >>$LOG 2>&1 \ + && OK || { WARN; return 1; } + } || { + CHECK 'updating Vundle.vim' + local PREV_DIR=$(pwd) + cd $VIM__VUNDLE_LOCAL >>$LOG 2>&1 \ + && git pull >>$LOG 2>&1 \ + && OK || WARN 'unable to pull latest Vundle.vim' + + cd $PREV_DIR >>$LOG 2>&1 + } + + CHECK 'installing vundle plugins' + vim +PluginInstall +qall \ + && OK || WARN + + STATUS 'building plugins' + $DOTWRYN_PATH/bin/vim/rebuild_plugins +} diff --git a/setup/zsh/setup.zsh b/setup/zsh/setup.zsh new file mode 100644 index 0000000..a5eabb6 --- /dev/null +++ b/setup/zsh/setup.zsh @@ -0,0 +1,54 @@ +##################################################################### + +function ZSH__SETUP() { + ZSH__SET_DEFAULT_SHELL + ZSH__SOURCE_RC + ZSH__SET_LOCAL_CONFIG +} + +##################################################################### + +function ZSH__SET_DEFAULT_SHELL() { + local DEFAULT_SHELL=$(awk -F: -v user="$USER" '$1 == user {print $NF}' /etc/passwd) + CHECK 'setting zsh as default shell' + sudo chsh -s $(which zsh) $(whoami)>>$LOG 2>&1 \ + && OK || WARN 'failed to set zsh as default shell' +} + +function ZSH__SOURCE_RC() { + local LOCAL_ZSHRC="$HOME/.zshrc"; + local SOURCE_LINE="source $DOTWRYN_PATH/zsh/rc"; + + grep -q "^$SOURCE_LINE$" $LOCAL_ZSHRC && { + STATUS 'already set up zshrc' + } || { + CHECK 'setting up zshrc' + echo $SOURCE_LINE >> $LOCAL_ZSHRC \ + && OK || WARN + } +} + +function ZSH__SET_LOCAL_CONFIG() { + local DEFAULT_CONFIG="$DOTWRYN_PATH/env/env.zsh" + local LOCAL_CONFIG="$HOME/.config/wryn/env/env.zsh" + + [ -f $LOCAL_CONFIG ] && { + WARNING "local zsh env configuration ($LOCAL_CONFIG)" + USER_PROMPT 'overwrite? [y/N]' + READ_K yn + [[ $yn =~ ^[yY] ]] && { + CHECK "backing up local copy ($LOCAL_CONFIG.bak)" + mv "$LOCAL_CONFIG" "$LOCAL_CONFIG.bak" && OK || WARN + } || { + STATUS 'skipping' + return + } + } + + CHECK "setting zsh configuration file ($LOCAL_CONFIG)" + { + echo "source $DEFAULT_CONFIG" + echo -e '\n#\n# .wryn configuration overrides\n#\n' + sed 's/[#]*\(.*\)/#\1/' $DEFAULT_CONFIG + } > $LOCAL_CONFIG && OK || WARN +} diff --git a/zsh/rc b/zsh/rc index e2efe43..424e0a4 100644 --- a/zsh/rc +++ b/zsh/rc @@ -1,6 +1,6 @@ #!/bin/zsh -source "$HOME/.config/wryn/env/env" +source "$HOME/.config/wryn/env/env.zsh" # --- load custom plugins ------------------------------------------ diff --git a/zsh/utils/color.zsh b/zsh/utils/color.zsh new file mode 100644 index 0000000..e129033 --- /dev/null +++ b/zsh/utils/color.zsh @@ -0,0 +1,21 @@ +#!/bin/zsh +[ ! $COLOR_PATH ] && COLOR_PATH="${0:a:h}/color" + +# use colors by name +source "$COLOR_PATH/names.zsh" + + +# console message helper function +source "$COLOR_PATH/console-color-out.zsh" + + +# write full line messages with semantic name +# e.g. 'ERROR : something bad happened' (in red) +source "$COLOR_PATH/messages.zsh" + + +# two-piece message, check message >> run some stuff >> status +# the status appears on the same line as the check +# +# e.g. 'CHECK : installing something... ✔ OK' +source "$COLOR_PATH/check.zsh" diff --git a/zsh/utils/color/check.zsh b/zsh/utils/color/check.zsh new file mode 100644 index 0000000..581e6cb --- /dev/null +++ b/zsh/utils/color/check.zsh @@ -0,0 +1,26 @@ +function CHECK() { + SINGLE_LINE=1 CONSOLE_COLOR_OUT $WHITE $PREFIX_CHK $@'... ' +} + +function CHECK_RESULT() { + local color="$1" + local output="$2" + printf "\\033[$color""m$output\\033[0m\n" +} + +function OK() { + CHECK_RESULT $LIGHT_GREEN '✔ OK' + [ $1 ] && SUCCESS $@ + return 0 +} + +function WARN() { + CHECK_RESULT $YELLOW '⚠ WARN' + [ $1 ] && WARNING $@ + return 0 +} + +function FAIL() { + CHECK_RESULT $LIGHT_RED '✖ FAIL' + FATAL $@ +} diff --git a/zsh/utils/color/console-color-out.zsh b/zsh/utils/color/console-color-out.zsh new file mode 100644 index 0000000..fdd4293 --- /dev/null +++ b/zsh/utils/color/console-color-out.zsh @@ -0,0 +1,19 @@ +[ ! $PREFIX_ERR ] && PREFIX_ERR='ERROR ' +[ ! $PREFIX_FAT ] && PREFIX_FAT='FATAL ' +[ ! $PREFIX_WRN ] && PREFIX_WRN='WARNING' +[ ! $PREFIX_SCS ] && PREFIX_SCS='SUCCESS' +[ ! $PREFIX_STS ] && PREFIX_STS='STATUS ' +[ ! $PREFIX_USR ] && PREFIX_USR='USER ' +[ ! $PREFIX_BLK ] && PREFIX_BLK=' ' +[ ! $PREFIX_CHK ] && PREFIX_CHK='CHECK ' + +function CONSOLE_COLOR_OUT() { + local color="$1" + local prefix="$2" + + local message="\\033[$color""m$prefix :: ${@:3}\\033[0m" + + [ ! $SINGLE_LINE ] && message="$message\n" + + printf $message +} diff --git a/zsh/utils/color/messages.zsh b/zsh/utils/color/messages.zsh new file mode 100644 index 0000000..a9c73cd --- /dev/null +++ b/zsh/utils/color/messages.zsh @@ -0,0 +1,29 @@ +function ERROR() { + CONSOLE_COLOR_OUT $RED $PREFIX_ERR $@ +} + +function FATAL() { + ERROR $@ + CONSOLE_COLOR_OUT $RED $PREFIX_FAT 'exiting' + exit 1 +} + +function WARNING() { + CONSOLE_COLOR_OUT $ORANGE $PREFIX_WRN $@ +} + +function STATUS() { + CONSOLE_COLOR_OUT $PURPLE $PREFIX_STS $@ +} + +function SUCCESS() { + CONSOLE_COLOR_OUT $GREEN $PREFIX_SCS $@ +} + +function USER_PROMPT() { + SINGLE_LINE=1 CONSOLE_COLOR_OUT $CYAN $PREFIX_USR $@ +} + +function MENU() { + CONSOLE_COLOR_OUT $YELLOW $PREFIX_BLK $@ +} diff --git a/zsh/utils/color/names.zsh b/zsh/utils/color/names.zsh new file mode 100644 index 0000000..f942b83 --- /dev/null +++ b/zsh/utils/color/names.zsh @@ -0,0 +1,23 @@ +BLACK='0;30' +DARK_GRAY='1;30' + +RED='0;31' +LIGHT_RED='1;31' + +GREEN='0;32' +LIGHT_GREEN='1;32' + +ORANGE='0;33' +YELLOW='1;33' + +BLUE='0;34' +LIGHT_BLUE='1;34' + +PURPLE='0;35' +LIGHT_PURPLE='1;35' + +CYAN='0;36' +LIGHT_CYAN='1;36' + +LIGHT_GRAY='0;37' +WHITE='1;37' diff --git a/zsh/utils/color/prefix.zsh b/zsh/utils/color/prefix.zsh new file mode 100644 index 0000000..e69de29 diff --git a/zsh/utils/user-input.zsh b/zsh/utils/user-input.zsh new file mode 100644 index 0000000..1846c29 --- /dev/null +++ b/zsh/utils/user-input.zsh @@ -0,0 +1,4 @@ +function READ_K() { + read -k $1 + echo +}