From b2089961688d7f93ae4f1eeb29195806758b5a32 Mon Sep 17 00:00:00 2001 From: root Date: Sun, 25 Dec 2022 03:30:41 +0000 Subject: [PATCH] Several changes --- pubnixvm/mktuser | 6 ++-- pubnixvm/poll-votes | 82 +++++++++++++++++++++++++++++++++++++++++++++ tilserv/clearvotes | 3 ++ tilserv/countvotes | 2 +- tilserv/delbackup | 1 + tilserv/dobackup | 2 +- tilserv/mkpost | 10 ++++++ tilserv/remind | 2 +- 8 files changed, 102 insertions(+), 6 deletions(-) create mode 100755 pubnixvm/poll-votes create mode 100755 tilserv/clearvotes create mode 100755 tilserv/mkpost diff --git a/pubnixvm/mktuser b/pubnixvm/mktuser index 791e638..d438407 100755 --- a/pubnixvm/mktuser +++ b/pubnixvm/mktuser @@ -1,7 +1,4 @@ #!/usr/bin/env -S bash -e - - - [[ -z "$2" ]] && { printf 'Usage: %s username password [user|admin] [shell] <<< pubkey\n' "$0" exit 1 @@ -24,6 +21,9 @@ chmod 755 "$_HOME/public_gopher" chmod 755 "$_HOME/public_gcdn" systemctl restart gemini sed -i "s/USER/${1}/g" "$_HOME"/.config/nixpkgs/home.nix +sed -i "s/replaceme/${1}/g" "$_HOME"/.config/aerc/accounts.conf sudo -u $1 nix-shell '' -A install printf "%s\n%s\n" "$2" "$2" | passwd "$1" zfs set userquota@"${1}"=20G pool1/home +sudo -u postgres psql -c "create role ${1};" +sudo -u postgres createdb -O ${1} ${1} diff --git a/pubnixvm/poll-votes b/pubnixvm/poll-votes new file mode 100755 index 0000000..b2de716 --- /dev/null +++ b/pubnixvm/poll-votes @@ -0,0 +1,82 @@ +#!/usr/bin/env bash +set -x +# Config +home_dir="/home/" +voting_questions_file="/var/voting_prompts" + + +# setup +set -e +home_dir=${home_dir%/} + + +# read active prompts +declare -A active_prompts +while IFS=, read q_id q_prompt +do + active_prompts[$q_id]=$q_prompt +done < "$voting_questions_file" + +# intialize vote counter +declare -A vote_counter +declare -A vote_counter_total +for q_id in ${!active_prompts[@]} +do + declare -i vote_counter[$q_id]=0 + declare -i vote_counter_total[$q_id]=0 +done < "$voting_questions_file" + + +# intialize voter missing list +declare -A voter_missing + + +parse_user_votes() { + local user_home=$1 + local user_voting_file=$user_home/.vote + local user_name=${user_home##*/} + + local -A user_votes + + if ! [[ -f "$user_voting_file" ]]; then + echo "WARNING: user "${user_name}" doesn't have a ~/.vote" >& 2 + return + fi + while IFS=, read q_id q_bool + do + user_votes[$q_id]=$q_bool + done < "$user_voting_file" + + + for q_id in ${!active_prompts[@]} + do + user_vote=${user_votes[$q_id]} + + case $user_vote in + 1) + vote_counter[$q_id]+=1 + vote_counter_total[$q_id]+=1 + ;; + 0) + vote_counter_total[$q_id]+=1 + ;; + *) + voter_missing[$q_id]+="${user_name}," + ;; + esac + + done + +} + + +for user_home in "$home_dir"/* +do + parse_user_votes "$user_home" +done + + +for q_id in $(printf '%s\n' "${!active_prompts[@]}" | tac | tr '\n' ' ') +do + echo "${q_id}|${active_prompts[$q_id]}|${vote_counter[$q_id]}|${vote_counter_total[$q_id]}|${voter_missing[$q_id]%,}" +done diff --git a/tilserv/clearvotes b/tilserv/clearvotes new file mode 100755 index 0000000..7988418 --- /dev/null +++ b/tilserv/clearvotes @@ -0,0 +1,3 @@ +#!/usr/bin/env -S bash + +for i in /vm/*; do rm -v "$i"/.vote 2>/dev/null; done diff --git a/tilserv/countvotes b/tilserv/countvotes index d98242e..2c152f8 100755 --- a/tilserv/countvotes +++ b/tilserv/countvotes @@ -1,4 +1,4 @@ -#!/usr/bin/env -S bash -e +#!/usr/bin/env -S bash if [ $# -eq 0 ]; then printf 'Usage: %s text\n' "$0" diff --git a/tilserv/delbackup b/tilserv/delbackup index a0567fc..051f0f5 100755 --- a/tilserv/delbackup +++ b/tilserv/delbackup @@ -2,5 +2,6 @@ for i in $(zfs list -H -o name -t snapshot | grep 'bighdd\/backup\/.*@2.*'); do if (( date - ${i##bighdd*@} >= 7 )); then echo "$i is to be deleted since the snapshot is 7 days or older" + zfs destroy ${i} fi done diff --git a/tilserv/dobackup b/tilserv/dobackup index 7282cfe..189b092 100755 --- a/tilserv/dobackup +++ b/tilserv/dobackup @@ -8,7 +8,7 @@ backupscript() { if [ "bighdd/backup/$newsnap" != "$latestsnap" ]; then set -x zfs snapshot -r nvme/$newsnap - zfs send -RI $incbackup nvme/$newsnap | pv | zfs recv -Fu ${targetpool}/${1} + zfs send -cpI $incbackup nvme/$newsnap | pv | zfs recv -u ${targetpool}/${1} zfs destroy nvme/$newsnap set +x else diff --git a/tilserv/mkpost b/tilserv/mkpost new file mode 100755 index 0000000..46d4ca9 --- /dev/null +++ b/tilserv/mkpost @@ -0,0 +1,10 @@ +#!/usr/bin/env bash +[[ -z "$1" ]] && { + printf "Usage: %s message [description]\n" "$0" + exit 1 +} + +mkwpost "$1" "$2" +mkfpost "$1" "$2" +mkmpost "$1" "$2" +mkxpost "$1" "$2" diff --git a/tilserv/remind b/tilserv/remind index 5476802..e30dec5 100755 --- a/tilserv/remind +++ b/tilserv/remind @@ -1,4 +1,4 @@ -#!/usr/bin/env -S bash -e +#!/usr/bin/env -S bash [[ -z "$@" ]] && set -- $(tty)