personal-linux-config/deploy.sh

105 lines
2.3 KiB
Bash
Raw Permalink Normal View History

#!/usr/bin/env bash
2022-02-10 15:08:13 +00:00
THIS="$(dirname "$(readlink -fm "$0")")"
2023-12-14 14:02:45 +00:00
FANCYFY="client"
CURRENT_FANCYFY=""
2022-02-10 15:02:35 +00:00
DELETE=false
MOVE=false
2023-12-14 14:02:45 +00:00
PRESENT=false
_bashrc_present() {
if [ ! -z "$(grep "#REF:bashrc_overrides:REF" ~/.bashrc)" ]; then
2023-12-14 14:02:45 +00:00
echo true
exit
fi
echo false
}
_arguments() {
2023-12-14 14:02:45 +00:00
if [ "$(_bashrc_present)" = true ]; then
PRESENT=true
CURRENT_FANCYFY="$(grep TERMINAL_FANCYFY ~/.bashrc | sed 's/.*=//')"
2023-12-14 14:02:45 +00:00
fi
for PARM in "$@"; do
if [ "${PARM}" = "--server" ]; then
2023-12-14 14:02:45 +00:00
FANCYFY="server"
2022-02-10 15:02:35 +00:00
elif [ "${PARM}" = "--delete" ]; then
DELETE=true
elif [ "${PARM}" = "--move" ]; then
MOVE=true
elif [ "${PARM}" = "-h" ] || [ "${PARM}" = "--help" ]; then
_help
exit 0
fi
done
}
_help() {
echo "Usage: $(readlink -fm "$0") [-h | --help] [--cleanup]"
echo
echo "Options:"
echo " -h | --help"
echo " Prints this help message and quits"
echo " --force"
echo " Force the reinstallation of the files"
2022-02-10 15:02:35 +00:00
echo " --delete"
echo " Delete the reference in ${BASHRC}"
2022-02-10 15:02:35 +00:00
echo " --move"
echo " Create a new reference if the location of this folder has been changed"
echo " --server"
echo " Customizes the terminal feel for a server installation"
echo
}
2022-02-10 15:02:35 +00:00
_delete() {
sed -i '/REF:bashrc_overrides:REF/{N;N;d}' ~/.bashrc
2022-02-10 15:02:35 +00:00
}
_bashrc_ref() {
echo "#REF:bashrc_overrides:REF" >> ~/.bashrc
echo "export TERMINAL_FANCYFY=${1}" >> ~/.bashrc
echo ". ${THIS}/bashrc_overrides/_all" >> ~/.bashrc
}
2022-02-10 15:02:35 +00:00
_move() {
_delete
2023-12-14 14:07:11 +00:00
_bashrc_ref "${FANCYFY}"
2022-02-10 15:02:35 +00:00
}
_main() {
_arguments "$@"
2022-02-10 15:02:35 +00:00
if [ "${DELETE}" = true ]; then
_delete
2023-12-14 14:02:45 +00:00
echo "removed custom configs"
2022-02-10 15:02:35 +00:00
elif [ "${MOVE}" = true ]; then
2023-12-14 14:07:11 +00:00
if [ "${PRESENT}" = false ]; then
_bashrc_ref "${FANCYFY}"
echo "unable to move to current directory"
echo "bash overrides not previously present"
echo "adding bash overrides..."
echo
else
_move
echo "moved custom config directory to ${THIS}"
echo
fi
2023-12-14 14:02:45 +00:00
elif [ "${PRESENT}" = true ]; then
if [ "${CURRENT_FANCYFY}" != "${FANCYFY}" ]; then
sed -i "s/TERMINAL_FANCYFY=${CURRENT_FANCYFY}/TERMINAL_FANCYFY=${FANCYFY}/" ~/.bashrc
2023-12-14 14:02:45 +00:00
echo "customized fancyfying"
echo
else
echo "bash overrides already in place"
echo "skipping..."
echo
fi
else
2023-12-14 14:02:45 +00:00
_bashrc_ref "${FANCYFY}"
echo "bash overrides added"
echo
fi
}
_main "$@"