2022-08-17 00:42:57 +00:00
|
|
|
function SETUP__CONFIG() {
|
2023-06-28 00:30:02 +00:00
|
|
|
STATUS 'starting application configuration'
|
2022-08-17 00:42:57 +00:00
|
|
|
|
2023-06-28 00:30:02 +00:00
|
|
|
SCWRYPTS system/config/update || return 1
|
2022-08-17 00:42:57 +00:00
|
|
|
|
|
|
|
CONFIG__ZSH || return 2
|
|
|
|
CONFIG__VIM || return 3
|
|
|
|
|
2023-06-28 00:30:02 +00:00
|
|
|
SUCCESS 'finished application configuration'
|
2022-08-17 00:42:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#####################################################################
|
|
|
|
|
|
|
|
CONFIG__ZSH() {
|
|
|
|
CONFIG__ENV zsh || return 1
|
|
|
|
CONFIG__RC zsh || return 2
|
|
|
|
CONFIG__SET_DEFAULT_SHELL || return 3
|
|
|
|
}
|
|
|
|
|
|
|
|
CONFIG__SET_DEFAULT_SHELL() {
|
|
|
|
local DEFAULT_SHELL=$(awk -F: -v user="$USER" '$1 == user {print $NF}' /etc/passwd)
|
|
|
|
[[ $DEFAULT_SHELL =~ zsh ]] && return 0
|
|
|
|
|
2022-08-19 02:41:14 +00:00
|
|
|
[ $FORCE_ROOT ] && return 0
|
|
|
|
|
2023-06-28 00:30:02 +00:00
|
|
|
STATUS 'setting zsh as default shell'
|
2022-08-17 00:42:57 +00:00
|
|
|
sudo chsh -s $(which zsh) $(whoami) 2>&1 \
|
2023-06-28 00:30:02 +00:00
|
|
|
&& SUCCESS "set zsh as default shell for '$USER'" \
|
|
|
|
|| FAIL 1 'failed to set zsh as default shell' \
|
2022-08-17 00:42:57 +00:00
|
|
|
;
|
|
|
|
}
|
|
|
|
|
|
|
|
#####################################################################
|
|
|
|
|
|
|
|
CONFIG__VIM() {
|
|
|
|
CONFIG__ENV vim || return 1
|
|
|
|
CONFIG__RC vim || return 2
|
|
|
|
|
2022-08-19 01:55:18 +00:00
|
|
|
[ $NO_COMPILE_VIM ] && return 0
|
|
|
|
|
2023-06-28 00:30:02 +00:00
|
|
|
STATUS 'starting vim setup'
|
2022-08-17 00:42:57 +00:00
|
|
|
"$DOTWRYN_PATH/vim/update" \
|
2023-06-28 00:30:02 +00:00
|
|
|
&& SUCCESS 'completed vim setup' \
|
|
|
|
|| FAIL 1 'error detected in vim setup (see above)' \
|
2022-08-17 00:42:57 +00:00
|
|
|
;
|
|
|
|
}
|
|
|
|
|
|
|
|
#####################################################################
|
|
|
|
|
|
|
|
CONFIG__ENV() {
|
|
|
|
local DEFAULT_CONFIG="$DOTWRYN_PATH/config/dotwryn.env.$1"
|
|
|
|
local LOCAL_CONFIG="$HOME/.config/wryn/env.$1"
|
|
|
|
|
|
|
|
[ -f $LOCAL_CONFIG ] && {
|
2023-06-28 00:30:02 +00:00
|
|
|
WARNING "local $1 configuration exists ($LOCAL_CONFIG)"
|
|
|
|
yN 'overwrite this configuration?' || return 0
|
2022-08-17 00:42:57 +00:00
|
|
|
|
|
|
|
mv "$LOCAL_CONFIG" "$LOCAL_CONFIG.bak" >/dev/null 2>&1 \
|
2023-06-28 00:30:02 +00:00
|
|
|
&& INFO "created backup of local configuration ($LOCAL_CONFIG.bak)"
|
2022-08-17 00:42:57 +00:00
|
|
|
}
|
|
|
|
|
2023-06-28 00:30:02 +00:00
|
|
|
STATUS "setting up $1 configuration ($LOCAL_CONFIG)"
|
2022-08-17 00:42:57 +00:00
|
|
|
|
|
|
|
case $1 in
|
|
|
|
vim ) COMMENT='"' ;;
|
|
|
|
zsh ) COMMENT='#' ;;
|
|
|
|
esac
|
|
|
|
|
|
|
|
{
|
|
|
|
echo "source $DEFAULT_CONFIG"
|
|
|
|
echo -e "\\n$COMMENT\n$COMMENT .wryn configuration overrides\n$COMMENT\n"
|
|
|
|
sed "s/^[^$COMMENT].*/$COMMENT&/" $DEFAULT_CONFIG
|
|
|
|
} > $LOCAL_CONFIG \
|
2023-06-28 00:30:02 +00:00
|
|
|
&& SUCCESS "created $1 configuration" \
|
|
|
|
|| FAIL 1 "unable to create $1 configuration" \
|
2022-08-17 00:42:57 +00:00
|
|
|
;
|
|
|
|
|
2023-06-28 00:30:02 +00:00
|
|
|
EDIT "$LOCAL_CONFIG"
|
2022-08-17 00:42:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
CONFIG__RC() {
|
|
|
|
local TYPE="$1"
|
|
|
|
local RC="$HOME/.${TYPE}rc";
|
|
|
|
|
|
|
|
local SOURCE_LINE
|
|
|
|
case $TYPE in
|
|
|
|
zsh ) SOURCE_LINE="source $DOTWRYN_PATH/zsh/rc" ;;
|
|
|
|
vim ) SOURCE_LINE="source $DOTWRYN_PATH/vim/rc.vim" ;;
|
|
|
|
esac
|
|
|
|
|
|
|
|
grep -q "^$SOURCE_LINE$" "$RC" \
|
|
|
|
|| echo "$SOURCE_LINE" >> $RC
|
|
|
|
|
|
|
|
grep -q "^$SOURCE_LINE$" "$RC" \
|
2023-06-28 00:30:02 +00:00
|
|
|
&& SUCCESS "${TYPE}rc is configured correctly" \
|
|
|
|
|| FAIL 1 "failed to configure ${TYPE}rc" \
|
2022-08-17 00:42:57 +00:00
|
|
|
;
|
|
|
|
}
|
|
|
|
|