180 lines
4.4 KiB
Bash
Executable File
180 lines
4.4 KiB
Bash
Executable File
#!/usr/bin/env bash
|
|
|
|
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
|
# what: ct :: the caretaker
|
|
# author: frode klevstul
|
|
# started: may 2024
|
|
#
|
|
# nifty: https://github.com/dylanaraps/pure-bash-bible
|
|
#
|
|
# requires: tree, wget
|
|
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
|
|
|
#############################################################################
|
|
#
|
|
# WARNING: EXAMINE THE CONTENT BEFORE EXECUTION. RUN AT YOUR OWN RISK.
|
|
#
|
|
#############################################################################
|
|
echo "<< ct.sh >>"
|
|
|
|
base_url=https://gt.op.fo/fro/lnx-arch/raw/branch/master
|
|
scripts_url=${base_url}/scripts
|
|
home_dir=/usr/local/bin
|
|
this_file=ct.sh
|
|
|
|
|
|
# https://stackoverflow.com/questions/18215973/how-to-check-if-running-as-root-in-a-bash-script
|
|
if [ $(id -u) -ne 0 ]
|
|
then echo "error: run as 'root'"
|
|
exit
|
|
fi
|
|
|
|
this_file_name=`basename "$0"`
|
|
if [ $# -lt 1 ]; then
|
|
echo "usage: '$this_file_name { d/dots | d+/dots+ | uf / upd-full [host]? | services | s/sw/software {update/install/search/orphans/uninstall} [host]? | us / upd-self | yay }'"
|
|
exit 1
|
|
fi
|
|
|
|
operation=$1
|
|
parameter_1=$2
|
|
parameter_2=$3
|
|
|
|
shopt -s extglob
|
|
case $operation in
|
|
!(d|dots|d+|dots+|uf|upd-full|services|s|sw|software|us|upd-self|yay))
|
|
echo "error: unknown operation '$operation'"
|
|
exit
|
|
;;
|
|
esac
|
|
shopt -u extglob
|
|
|
|
# ~ ~ ~ ~ ~ ~ ~ ~ ~ ~
|
|
|
|
# helper function
|
|
execute_script() {
|
|
file=$1
|
|
parameter_1=$2
|
|
parameter_2=$3
|
|
echo "execute: ${file} ${parameter_1} ${parameter_2}"
|
|
resource_url=${scripts_url}/${file}
|
|
|
|
if ! wget -q --method=HEAD ${resource_url};
|
|
then
|
|
echo "error: unable to load '${resource_url}'"
|
|
echo ""
|
|
wget -v ${resource_url}
|
|
echo ""
|
|
echo "if the error is caused by an untrusted certificate, you can continue ignoring the untrusted cert. press enter to continue or type any character to stop."
|
|
read user_input
|
|
if [[ ${user_input} == "" ]]; then
|
|
echo "ok. we will continue with wget's '--no-check-certificate' flag activated."
|
|
echo ""
|
|
else
|
|
echo "ok. we will stop here."
|
|
exit
|
|
fi
|
|
fi
|
|
|
|
wget --no-check-certificate -q ${resource_url} -O /tmp/${file}
|
|
chmod 755 /tmp/*.sh
|
|
/tmp/${file} ${parameter_1} ${parameter_2}
|
|
}
|
|
|
|
# ~ ~ ~ ~ ~ ~ ~ ~ ~ ~
|
|
|
|
# update dot files
|
|
shopt -s extglob
|
|
if [ $operation == "d" ] || [ $operation == "dots" ] ; then
|
|
|
|
execute_script 99_deploy.sh dots
|
|
|
|
fi
|
|
shopt -u extglob
|
|
|
|
# update dots+ (wallpapers, fonts, ++)
|
|
shopt -s extglob
|
|
if [ $operation == "d+" ] || [ $operation == "dots+" ] ; then
|
|
|
|
execute_script 99_deploy.sh dots+
|
|
|
|
fi
|
|
shopt -u extglob
|
|
|
|
# enable services
|
|
shopt -s extglob
|
|
if [ $operation == "services" ] ; then
|
|
|
|
if [ -z "${parameter_1}" ]; then
|
|
parameter_1=services
|
|
fi
|
|
|
|
if [ $parameter_1 == "services" ] ; then
|
|
if [ -z "${parameter_2}" ]; then
|
|
parameter_2=$HOSTNAME
|
|
fi
|
|
fi
|
|
|
|
execute_script 99_software.sh "${parameter_1}" "${parameter_2}"
|
|
|
|
fi
|
|
shopt -u extglob
|
|
|
|
# install software (update system)
|
|
shopt -s extglob
|
|
if [ $operation == "s" ] || [ $operation == "sw" ] || [ $operation == "software" ] ; then
|
|
|
|
if [ -z "${parameter_1}" ]; then
|
|
parameter_1=update
|
|
fi
|
|
|
|
if [ $parameter_1 == "update" ] ; then
|
|
if [ -z "${parameter_2}" ]; then
|
|
parameter_2=$HOSTNAME
|
|
fi
|
|
fi
|
|
|
|
execute_script 99_software.sh "${parameter_1}" "${parameter_2}"
|
|
|
|
fi
|
|
shopt -u extglob
|
|
|
|
# self update, by re-downloading and overwriting itself
|
|
shopt -s extglob
|
|
if [ $operation == "us" ] || [ $operation == "upd-self" ] ; then
|
|
|
|
wget --no-check-certificate -v ${base_url}/scripts/${this_file} -O ${home_dir}/${this_file}.tmp
|
|
cp ${home_dir}/${this_file}.tmp ${home_dir}/${this_file}
|
|
rm ${home_dir}/${this_file}.tmp
|
|
chmod 755 ${home_dir}/*.sh
|
|
|
|
fi
|
|
shopt -u extglob
|
|
|
|
# full update: install software and update dots
|
|
shopt -s extglob
|
|
if [ $operation == "uf" ] || [ $operation == "upd-full" ] ; then
|
|
|
|
if [ -z "${parameter_1}" ]; then
|
|
parameter_1=$HOSTNAME
|
|
fi
|
|
|
|
if [ -z "${parameter_1}" ]; then
|
|
echo "error: missing host name"
|
|
exit 1
|
|
fi
|
|
|
|
${home_dir}/${this_file} software update ${parameter_1}
|
|
${home_dir}/${this_file} dots
|
|
|
|
fi
|
|
shopt -u extglob
|
|
|
|
# install yay
|
|
shopt -s extglob
|
|
if [ $operation == "yay" ] ; then
|
|
|
|
execute_script 99_yay.sh
|
|
|
|
fi
|
|
shopt -u extglob
|