dotwryn/setup/linux

157 lines
3.8 KiB
Bash
Executable File

#!/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)"
cd $DOTWRYN_PATH
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
}
INIT() {
printf 'initializing required submodules...'
git submodule update --init --remote --recursive >/dev/null 2>&1 || {
echo 'failed!'
echo 'unable to initialize required submodules'
exit 1
}
SOURCE_ZSH_SUBMODULE 'color-zsh'
echo 'done!'
source "$DOTWRYN_PATH/zsh/utils"
clear
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/wryn"
"$HOME/.local/bin"
"$HOME/.packages"
"$HOME/.vim/bundle"
"$HOME/.vim/colors"
)
FILES=(
"$HOME/.vimrc"
"$HOME/.zshrc"
)
for D in $DIRECTORIES; do [ ! -d $D ] && mkdir -p $D; done
for F in $FILES; do [ ! -f $F ] && touch $F; done
}
################################################################################
source "$DOTWRYN_PATH/setup/os.setup.zsh"
source "$DOTWRYN_PATH/setup/config.setup.zsh"
source "$DOTWRYN_PATH/setup/zsh.setup.zsh"
source "$DOTWRYN_PATH/setup/vim.setup.zsh"
source "$DOTWRYN_PATH/setup/apps.setup.zsh"
source "$DOTWRYN_PATH/setup/aws.setup.zsh"
################################################################################
################################################################################
### Full Setup #################################################################
################################################################################
INIT
GET_SUDO_PASSWORD
SETUP__OS_DEPENDENCY || FATAL 'user abort'
MAKE_REQUIRED_DIRECTORY_STRUCTURE
SETUP__CONFIG || ERROR=1
SETUP__ZSH || ERROR=2
SETUP__VIM || ERROR=3
SETUP__APPS || ERROR=4
SETUP__AWS || ERROR=5
CLEANUP $ERROR
################################################################################
echo
echo
SUCCESS
SUCCESS '.wryn setup complete; have a nice day :)'
SUCCESS
echo
echo
exit 0