2024-04-30 07:40:24 -05:00
#!/usr/bin/env bash
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
# what: curae is latin an means to take care. this script takes care
# of the system (adjusted for arch linux).
# author: fk
# 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 "<< curae.sh >>"
2024-11-10 19:22:42 -05:00
base_url = https://gt.op.fo/fro/lnx-arch/raw/branch/master
2024-04-30 07:40:24 -05:00
scripts_url = ${ base_url } /scripts
2024-05-12 14:40:06 +00:00
home_dir = /usr/local/bin
2024-04-30 07:40:24 -05:00
this_file = curae.sh
2025-02-24 19:59:12 -05:00
# https://stackoverflow.com/questions/18215973/how-to-check-if-running-as-root-in-a-bash-script
#if [ "$EUID" -ne 0 ]
if [ $( id -u) -ne 0 ]
2024-04-30 07:40:24 -05:00
then echo "error: run as 'root'"
exit
fi
this_file_name = ` basename " $0 " `
if [ $# -lt 1 ] ; then
2024-05-08 07:36:49 -05:00
echo " usage: ' $this_file_name { dots | dots+ | uf / upd-full [host]? | sw / software {update/install/search/orphans/uninstall} [host]? | us / upd-self | yay }' "
2024-04-30 07:40:24 -05:00
exit 1
fi
operation = $1
parameter_1 = $2
parameter_2 = $3
shopt -s extglob
case $operation in
2024-05-19 17:00:13 -05:00
!( dots| dots+| uf| upd-full| services| sw| software| us| upd-self| yay) )
2024-04-30 07:40:24 -05:00
echo " error: unknown operation ' $operation ' "
exit
; ;
esac
shopt -u extglob
2024-04-30 22:02:09 -05:00
# ~ ~ ~ ~ ~ ~ ~ ~ ~ ~
2024-04-30 07:40:24 -05:00
# helper function
execute_script( ) {
file = $1
parameter_1 = $2
parameter_2 = $3
echo " execute: ${ file } ${ parameter_1 } ${ parameter_2 } "
2024-05-31 12:54:43 -05:00
resource_url = ${ scripts_url } /${ file }
2024-05-31 13:20:40 -05:00
if ! wget -q --method= HEAD ${ resource_url } ;
2024-05-31 12:54:43 -05:00
then
echo " error: unable to load ' ${ resource_url } ' "
echo ""
wget -v ${ resource_url }
2024-05-31 13:20:40 -05:00
echo ""
2024-05-31 16:26:31 -05:00
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."
2024-05-31 13:20:40 -05:00
read user_input
2024-05-31 16:26:31 -05:00
if [ [ ${ user_input } = = "" ] ] ; then
2024-05-31 13:20:40 -05:00
echo "ok. we will continue with wget's '--no-check-certificate' flag activated."
echo ""
else
echo "ok. we will stop here."
exit
fi
2024-05-31 12:54:43 -05:00
fi
2024-05-31 13:05:30 -05:00
wget --no-check-certificate -q ${ resource_url } -O /tmp/${ file }
2024-04-30 07:40:24 -05:00
chmod 755 /tmp/*.sh
/tmp/${ file } ${ parameter_1 } ${ parameter_2 }
}
2024-04-30 21:34:49 -05:00
# ~ ~ ~ ~ ~ ~ ~ ~ ~ ~
2024-04-30 07:40:24 -05:00
# update dot files
shopt -s extglob
if [ $operation = = "dots" ] ; then
2024-04-30 21:34:49 -05:00
execute_script 99_deploy.sh dots
2024-04-30 07:40:24 -05:00
fi
shopt -u extglob
2024-05-04 15:14:56 -05:00
# update dots+ (wallpapers, fonts, ++)
2024-05-04 14:36:12 -05:00
shopt -s extglob
2024-05-04 15:14:56 -05:00
if [ $operation = = "dots+" ] ; then
2024-05-04 14:36:12 -05:00
2024-05-04 15:17:19 -05:00
execute_script 99_deploy.sh dots+
2024-05-04 14:36:12 -05:00
fi
shopt -u extglob
2024-05-19 17:00:13 -05:00
# 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
2024-04-30 07:40:24 -05:00
# install software (update system)
shopt -s extglob
if [ $operation = = "sw" ] || [ $operation = = "software" ] ; then
2024-05-09 19:58:24 -05:00
if [ -z " ${ parameter_1 } " ] ; then
parameter_1 = update
fi
2024-05-01 10:56:28 -05:00
if [ $parameter_1 = = "update" ] ; then
if [ -z " ${ parameter_2 } " ] ; then
parameter_2 = $HOSTNAME
fi
2024-04-30 22:17:25 -05:00
fi
2024-05-01 10:51:27 -05:00
execute_script 99_software.sh " ${ parameter_1 } " " ${ parameter_2 } "
2024-04-30 07:40:24 -05:00
fi
shopt -u extglob
# self update, by re-downloading and overwriting itself
shopt -s extglob
if [ $operation = = "us" ] || [ $operation = = "upd-self" ] ; then
2024-05-31 13:05:30 -05:00
wget --no-check-certificate -v ${ base_url } /scripts/${ this_file } -O ${ home_dir } /${ this_file } .tmp
2024-04-30 07:40:24 -05:00
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
2024-05-01 14:10:06 -05:00
${ home_dir } /${ this_file } software update ${ parameter_1 }
2024-04-30 20:31:09 -05:00
${ home_dir } /${ this_file } dots
2024-04-30 07:40:24 -05:00
fi
shopt -u extglob
2024-05-01 16:14:53 -05:00
# install yay
shopt -s extglob
if [ $operation = = "yay" ] ; then
2024-05-01 16:41:36 -05:00
execute_script 99_yay.sh
2024-05-01 16:14:53 -05:00
fi
shopt -u extglob