2021-09-15 07:48:37 +00:00
|
|
|
#!/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)"
|
2021-09-16 17:23:40 +00:00
|
|
|
cd $DOTWRYN_PATH
|
2021-09-15 07:48:37 +00:00
|
|
|
|
2021-09-16 17:50:22 +00:00
|
|
|
SOURCE_ZSH_SUBMODULE() {
|
|
|
|
local NAME="$1"
|
|
|
|
|
|
|
|
local SUBMODULE_PATH=$(\
|
|
|
|
git config --file "$DOTWRYN_PATH/.gitmodules" --get-regexp "$NAME.path"\
|
|
|
|
| awk '{print $2;}'\
|
|
|
|
)
|
|
|
|
local MODULE="$(ls $DOTWRYN_PATH/$SUBMODULE_PATH/*.module.zsh)"
|
|
|
|
|
|
|
|
source $MODULE
|
|
|
|
}
|
|
|
|
|
2021-09-15 07:48:37 +00:00
|
|
|
INIT() {
|
2021-09-16 22:49:15 +00:00
|
|
|
git submodule update --init --remote --recursive >/dev/null 2>&1 || {
|
2021-09-16 17:23:40 +00:00
|
|
|
echo 'unable to initialize required submodules'
|
|
|
|
exit 1
|
|
|
|
}
|
2021-09-16 17:50:22 +00:00
|
|
|
SOURCE_ZSH_SUBMODULE 'color-zsh'
|
2021-09-15 07:48:37 +00:00
|
|
|
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"
|
2021-09-17 01:15:36 +00:00
|
|
|
"$HOME/.local"
|
|
|
|
"$HOME/.local/bin"
|
|
|
|
"$HOME/.packages"
|
2021-09-15 07:48:37 +00:00
|
|
|
"$HOME/.vim"
|
|
|
|
"$HOME/.vim/bundle"
|
2021-09-17 01:15:36 +00:00
|
|
|
"$HOME/.vim/colors"
|
2021-09-15 07:48:37 +00:00
|
|
|
)
|
|
|
|
FILES=(
|
|
|
|
"$HOME/.vimrc"
|
2021-09-17 01:15:36 +00:00
|
|
|
"$HOME/.zshrc"
|
2021-09-15 07:48:37 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
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"
|
2021-10-01 17:18:11 +00:00
|
|
|
source "$DOTWRYN_PATH/setup/config/setup.zsh"
|
2021-09-15 07:48:37 +00:00
|
|
|
source "$DOTWRYN_PATH/setup/zsh/setup.zsh"
|
|
|
|
source "$DOTWRYN_PATH/setup/vim/setup.zsh"
|
2021-10-01 17:18:11 +00:00
|
|
|
source "$DOTWRYN_PATH/setup/apps/setup.zsh"
|
2021-09-24 16:20:54 +00:00
|
|
|
source "$DOTWRYN_PATH/setup/aws/setup.zsh"
|
2021-09-15 07:48:37 +00:00
|
|
|
|
|
|
|
################################################################################
|
|
|
|
|
|
|
|
################################################################################
|
|
|
|
### Full Setup #################################################################
|
|
|
|
################################################################################
|
|
|
|
|
|
|
|
INIT
|
|
|
|
|
|
|
|
GET_SUDO_PASSWORD
|
2021-10-01 17:18:11 +00:00
|
|
|
SETUP__OS_DEPENDENCY || FATAL 'user abort'
|
2021-09-15 07:48:37 +00:00
|
|
|
MAKE_REQUIRED_DIRECTORY_STRUCTURE
|
|
|
|
|
2021-10-01 17:18:11 +00:00
|
|
|
SETUP__CONFIG || ERROR=1
|
2021-09-24 16:20:54 +00:00
|
|
|
|
2021-10-01 17:18:11 +00:00
|
|
|
SETUP__ZSH || ERROR=2
|
|
|
|
SETUP__VIM || ERROR=3
|
|
|
|
SETUP__APPS || ERROR=4
|
|
|
|
SETUP__AWS || ERROR=5
|
2021-09-15 07:48:37 +00:00
|
|
|
|
|
|
|
CLEANUP $ERROR
|
|
|
|
|
|
|
|
################################################################################
|
|
|
|
|
2021-09-17 01:15:36 +00:00
|
|
|
echo
|
|
|
|
echo
|
2021-09-15 07:48:37 +00:00
|
|
|
SUCCESS
|
|
|
|
SUCCESS '.wryn setup complete; have a nice day :)'
|
|
|
|
SUCCESS
|
|
|
|
echo
|
|
|
|
echo
|
|
|
|
|
|
|
|
exit 0
|