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
|
|
|
|
2024-08-15 01:11:52 +00:00
|
|
|
GENERATE_INITIAL_LOCAL_CONFIG
|
|
|
|
|
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
|
|
|
|
|
2024-08-13 18:46:20 +00:00
|
|
|
CONFIG__SYSTEM || return 4
|
|
|
|
|
|
|
|
SCWRYPTS generate i3 config || return 5
|
2024-05-09 05:33:06 +00:00
|
|
|
|
2023-06-28 00:30:02 +00:00
|
|
|
SUCCESS 'finished application configuration'
|
2022-08-17 00:42:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#####################################################################
|
|
|
|
|
2024-08-15 01:11:52 +00:00
|
|
|
GENERATE_INITIAL_LOCAL_CONFIG() {
|
|
|
|
local HOSTNAME="$(hostnamectl --static)"
|
2024-08-16 15:41:26 +00:00
|
|
|
[ ${HOSTNAME} ] || return 0
|
2024-08-15 01:11:52 +00:00
|
|
|
|
2024-08-16 15:41:26 +00:00
|
|
|
mkdir -p "${DOTWRYN_PATH}/bin/${HOSTNAME}"
|
2024-08-15 01:11:52 +00:00
|
|
|
|
2024-08-16 15:41:26 +00:00
|
|
|
local ENV_DIR="${DOTWRYN_PATH}/config/scwrypts/environments"
|
2024-08-15 01:11:52 +00:00
|
|
|
local GROUP
|
2024-08-16 15:41:26 +00:00
|
|
|
for GROUP in $(find "${ENV_DIR}" -type f -name \*env.yaml | sed -n 's|.*/local\.\([^.]*\)\.env\.yaml|\1|p')
|
2024-08-15 01:11:52 +00:00
|
|
|
do
|
2024-08-16 15:41:26 +00:00
|
|
|
[ -f "${ENV_DIR}/local.${HOSTNAME}.${GROUP}.env.yaml" ] \
|
|
|
|
|| cp "${ENV_DIR}/local.altaria.${GROUP}.env.yaml" "${ENV_DIR}/local.${HOSTNAME}.${GROUP}.env.yaml"
|
2024-08-15 01:11:52 +00:00
|
|
|
done
|
|
|
|
}
|
|
|
|
|
|
|
|
#####################################################################
|
|
|
|
|
2022-08-17 00:42:57 +00:00
|
|
|
CONFIG__ZSH() {
|
2024-08-13 18:46:20 +00:00
|
|
|
#CONFIG__ENV zsh || return 1
|
|
|
|
#CONFIG__RC zsh || return 2
|
2022-08-17 00:42:57 +00:00
|
|
|
CONFIG__SET_DEFAULT_SHELL || return 3
|
|
|
|
}
|
|
|
|
|
|
|
|
CONFIG__SET_DEFAULT_SHELL() {
|
2024-08-16 15:41:26 +00:00
|
|
|
local DEFAULT_SHELL=$(awk -F: -v user="${USER}" '$1 == user {print $NF}' /etc/passwd)
|
|
|
|
[[ ${DEFAULT_SHELL} =~ zsh ]] && return 0
|
2022-08-17 00:42:57 +00:00
|
|
|
|
2024-08-16 15:41:26 +00:00
|
|
|
[ ${FORCE_ROOT} ] && return 0
|
2022-08-19 02:41:14 +00:00
|
|
|
|
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 \
|
2024-08-16 15:41:26 +00:00
|
|
|
&& SUCCESS "set zsh as default shell for '${USER}'" \
|
2023-06-28 00:30:02 +00:00
|
|
|
|| FAIL 1 'failed to set zsh as default shell' \
|
2022-08-17 00:42:57 +00:00
|
|
|
;
|
|
|
|
}
|
|
|
|
|
|
|
|
#####################################################################
|
|
|
|
|
|
|
|
CONFIG__VIM() {
|
2024-05-07 22:38:40 +00:00
|
|
|
CONFIG__RC vim || return 1
|
2022-08-17 00:42:57 +00:00
|
|
|
|
2023-06-28 00:30:02 +00:00
|
|
|
STATUS 'starting vim setup'
|
2024-08-15 01:11:52 +00:00
|
|
|
SCWRYPTS --name system/vim/vundle/install --group scwrypts --type zsh || return 2
|
|
|
|
|
|
|
|
CONFIG__VIM__LINK_SUPERUSER_RC
|
|
|
|
|
|
|
|
return 0
|
|
|
|
}
|
|
|
|
|
|
|
|
CONFIG__VIM__LINK_SUPERUSER_RC() {
|
|
|
|
sudo [ /root/.vimrc ] && return 0
|
|
|
|
|
2024-08-16 15:41:26 +00:00
|
|
|
echo "let ${DOTWRYN}=\"${DOTWRYN_PATH}\"\nsource \"${DOTWRYN_PATH}/vim/rc.vim\"" \
|
2024-08-15 01:11:52 +00:00
|
|
|
| sudo tee /root/.vimrc >/dev/null
|
|
|
|
|
|
|
|
sudo mkdir -p /root/.vim
|
|
|
|
sudo ln -s /home/w0ryn/.vim/bundle /root/.vim/bundle
|
2022-08-17 00:42:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#####################################################################
|
|
|
|
|
2024-08-13 18:46:20 +00:00
|
|
|
CONFIG__SYSTEM() {
|
2024-08-15 01:11:52 +00:00
|
|
|
SCWRYPTS dotwryn system setup
|
2024-08-13 18:46:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#####################################################################
|
|
|
|
|
2022-08-17 00:42:57 +00:00
|
|
|
CONFIG__ENV() {
|
2024-08-16 15:41:26 +00:00
|
|
|
local DEFAULT_CONFIG="${DOTWRYN_PATH}/config/dotwryn.env.$1"
|
|
|
|
local LOCAL_CONFIG="${HOME}/.config/wryn/env.$1"
|
2022-08-17 00:42:57 +00:00
|
|
|
|
2024-08-16 15:41:26 +00:00
|
|
|
[ -f ${LOCAL_CONFIG} ] && {
|
|
|
|
case ${OVERWRITE_EXISTING} in
|
2023-11-19 19:00:51 +00:00
|
|
|
0 ) return 0 ;;
|
|
|
|
1 )
|
2024-08-16 15:41:26 +00:00
|
|
|
WARNING "local $1 configuration exists (${LOCAL_CONFIG})"
|
2023-11-19 19:00:51 +00:00
|
|
|
yN 'overwrite this configuration?' || return 0
|
|
|
|
|
2024-08-16 15:41:26 +00:00
|
|
|
mv "${LOCAL_CONFIG}" "${LOCAL_CONFIG}.bak" >/dev/null 2>&1 \
|
|
|
|
&& INFO "created backup of local configuration (${LOCAL_CONFIG}.bak)"
|
2023-11-19 19:00:51 +00:00
|
|
|
esac
|
2022-08-17 00:42:57 +00:00
|
|
|
}
|
|
|
|
|
2024-08-16 15:41:26 +00:00
|
|
|
STATUS "setting up $1 configuration (${LOCAL_CONFIG})"
|
2022-08-17 00:42:57 +00:00
|
|
|
|
|
|
|
case $1 in
|
|
|
|
zsh ) COMMENT='#' ;;
|
|
|
|
esac
|
|
|
|
|
|
|
|
{
|
2024-08-16 15:41:26 +00:00
|
|
|
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
|
|
|
;
|
|
|
|
|
2024-08-16 15:41:26 +00:00
|
|
|
EDITOR=vim VISUAL=vim EDIT "${LOCAL_CONFIG}"
|
2022-08-17 00:42:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
CONFIG__RC() {
|
|
|
|
local TYPE="$1"
|
2024-08-16 15:41:26 +00:00
|
|
|
local RC
|
|
|
|
case ${TYPE} in
|
|
|
|
vim )
|
|
|
|
RC="${XDG_CONFIG_HOME:-${HOME}/.config}/vim/vimrc"
|
|
|
|
mkdir -p -- "$(dirname -- "${RC}")"
|
|
|
|
[ -f "${HOME}/.vimrc" ] \
|
|
|
|
&& cat "${HOME}/.vimrc" >> "${XDG_CONFIG_HOME:-${HOME}/.config}/vim/vimrc" \
|
|
|
|
&& rm "${HOME}/.vimrc" \
|
|
|
|
;
|
|
|
|
;;
|
|
|
|
* ) RC="${HOME}/.${TYPE}rc";
|
|
|
|
;;
|
|
|
|
esac
|
2022-08-17 00:42:57 +00:00
|
|
|
|
|
|
|
local SOURCE_LINE
|
2024-08-16 15:41:26 +00:00
|
|
|
case ${TYPE} in
|
|
|
|
zsh ) SOURCE_LINE="source ${DOTWRYN_PATH}/zsh/rc" ;;
|
|
|
|
vim ) SOURCE_LINE="source ${DOTWRYN_PATH}/vim/rc.vim" ;;
|
2022-08-17 00:42:57 +00:00
|
|
|
esac
|
|
|
|
|
|
|
|
|
2024-08-16 15:41:26 +00:00
|
|
|
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
|
|
|
;
|
|
|
|
}
|