diff --git a/helperbot b/helperbot index 5aea975..ed0c42b 100755 --- a/helperbot +++ b/helperbot @@ -33,9 +33,9 @@ if [ -n "$1" ]; then synth_args_exist=1 fi -# check that everything we need is installed +# check that all required utils are installed function check_applications { - local all_required_applications=("bash" "docker" "backblaze-b2") + local all_required_applications=("bash" "wget" "tar" "zstd" "backblaze-b2") for application in "${all_required_applications[@]}"; do if [ ! -x "$(command -v $application)" ]; then @@ -76,7 +76,7 @@ if [[ -t 1 ]]; then gray=$(tput setaf 8); bold=$(tput bold) underline=$(tput smul) - normal=$( tput sgr 0); + normal=$(tput sgr 0); fi # ============================================================================= @@ -306,6 +306,7 @@ function b2_upload { # ╭─────────────╮ # │ backup step │ # ╰─────────────╯ +# TODO: it's probably possible to throw some of these steps into an array in loop or something, if that's even a good idea function system_backup { echo "${blue}backup:${normal} Running full system backup for ${green}${synth_current_system}${normal}." if [ "$synth_current_system" = "phosphorus" ]; then # phosphorus @@ -518,14 +519,6 @@ function system_backup { echo "${green}System backup finished! beep!~${normal}" } -# backup - create folder and copy -# step that combines the process of making folders and copying files for backup -# backup_create_copy ["source files"] [subpath/to/folder] [$backup_working_directory] -function backup_create_copy { - mkdir -p $3/$2 - cp -r $1 $3/$2 -} - # ╭─────────────╮ # │ vacuum step │ # ╰─────────────╯ @@ -602,6 +595,99 @@ function update_certificates { fi } +# ╭───────────────────╮ +# │ fediverse related │ +# ╰───────────────────╯ + +# sync blocklists from sharkey to iceshrimp +function fedi_sync_blocklists { + local sharkey_instance=localhost:60628 + local iceshrimp_instance=localhost:24042 + + # this command will only work on phosphorus, where the instances are directly being run from + # (it doesn't *have* to, but it's much faster to do it over localhost than domain) + if [[ "$synth_current_system" != "phosphorus" ]]; then + echo "${red}sync-blocklists:${normal} Sorry, this command will only work on phosphorus." + return 1 + fi + + echo "${blue}sync-blocklists:${normal} Syncing blocks from Sharkey to Iceshrimp..." + if [[ ${UID} == 0 ]]; then + echo + echo "${yellow}${bold}Notice:${normal} This command has been ran as root! For the sake of safety and Security™ reasons, please run this command as your standard user." + echo "If not already configured for yourself, please put a file under ${bold}\$XDG_DATA_HOME/fedi-tokens.env${normal} (directly) which should include the following, replacing the information as needed:" + echo "${gray}──────────────────────────────────────────────${normal}" + echo "MK_TOKEN=your_admin_misskey_token_here" + echo "SHRIMP_TOKEN=your_admin_iceshrimp_token_here" + return 1 + else + if [ -f "$XDG_DATA_HOME/fedi-tokens.env" ]; then + # load keys + export $(grep -v '^#' $XDG_DATA_HOME/fedi-tokens.env | xargs) + # grab the instance data from sharkey + json_data=$(curl -s "http://"$sharkey_instance"/api/admin/meta" -H "Content-Type: application/json" -X POST -d "{\"i\": \"$MK_TOKEN\"}") + # throw into a loop to block all instances on iceshrimp + echo "$json_data" | jq -r -c '.blockedHosts[]' | while read -r host; do + curl -w "HTTP %{response_code} " "http://"$iceshrimp_instance"/api/iceshrimp/admin/instances/$host/block?imported=true&reason=Synced%20from%20booping.synth.download" -H "Host: beeping.synth.download" -H "Authorization: Bearer $SHRIMP_TOKEN" -X POST + echo Blocked host: $host + done + # unset keys + unset $(grep -v '^#' /etc/secrets/fedi-tokens.env | sed -E 's/(.*)=.*/\1/' | xargs) + # done + echo "${green}Done syncing blocks.${normal}" + else + echo "${red}sync-blocklists:${normal} $XDG_DATA_HOME/fedi-tokens.env doesn't exist." + return 1 + fi + fi +} + +# update standalone frontends +function fedi_update_frontends { + local mastodon_fe_url=https://github.com/sneexy-boi/synth.download/releases/latest/download/masto-fe.zip + local akkoma_fe_url=https://github.com/sneexy-boi/synth.download/releases/latest/download/akkoma-fe.zip + local phanpy_url=https://github.com/cheeaun/phanpy/releases/latest/download/phanpy-dist.zip + local pl_fe_url=https://pl.mkljczk.pl/pl-fe.zip + local frontend_folder=/var/www/fedi-frontends + + # frontends are on neptunium so it's less hassle to forward with caddy + if [[ "$synth_current_system" != "neptunium" ]]; then + echo "${red}sync-blocklists:${normal} Sorry, this command will only work on neptunium." + return 1 + fi + + # _repeat_process [$frontend_fe_url] [file_name] [folder_name] + function _repeat_process { + wget "$1" -O /tmp/"$2".zip + unzip -o /tmp/"$2" -d $frontend_folder/"$3" + rm /tmp/"$2" + } + + # TODO: it's probably possible to turn this into an array loop of some sort + echo "${blue}update-frontends:${normal} Updating standalone frontends..." + if [ -f "$frontend_folder" ]; then + # update mastodon + echo "${blue}Updating Mastodon...${normal}" + _repeat_process $mastodon_fe_url masto-fe chuckya-fe + echo "${green}Okay.${normal}" + # update akkoma + echo "${blue}Updating Akkoma...${normal}" + _repeat_process $akkoma_fe_url akkoma-fe akkoma-fe + echo "${green}Okay.${normal}" + # update phanpy + echo "${blue}Updating Phanpy...${normal}" + _repeat_process $phanpy_url phanpy phanpy + echo "${green}Okay.${normal}" + # update pl-fe + echo "${blue}Updating pl-fe...${normal}" + _repeat_process $pl_fe_url pl-fe pl-fe + echo "${green}Okay.${normal}" + else + echo "${red}update-frontends:${normal} $frontend_folder doesn't exist." + return 1 + fi +} + # ╭────────────────────────────────────╮ # │ functions and variables - end here │ # ╰────────────────────────────────────╯ @@ -654,6 +740,17 @@ while [ -n "$1" ]; do detect_system fi update_certificates;; + --sync-blocklists) # fediverse: sync sharkey -> iceshrimp blocklists + if [ ! -v synth_current_system ]; then + detect_system + fi + fedi_sync_blocklists;; + --update-frontends) # fediverse: update standalone frontends + root_check + if [ ! -v synth_current_system ]; then + detect_system + fi + fedi_update_frontends;; *) # invalid option was given invalid_command $1 exit 1;;