Several changes

This commit is contained in:
root 2022-12-25 03:30:41 +00:00
parent a12c756c8c
commit b208996168
8 changed files with 102 additions and 6 deletions

View File

@ -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 '<home-manager>' -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}

82
pubnixvm/poll-votes Executable file
View File

@ -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

3
tilserv/clearvotes Executable file
View File

@ -0,0 +1,3 @@
#!/usr/bin/env -S bash
for i in /vm/*; do rm -v "$i"/.vote 2>/dev/null; done

View File

@ -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"

View File

@ -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

View File

@ -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

10
tilserv/mkpost Executable file
View File

@ -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"

View File

@ -1,4 +1,4 @@
#!/usr/bin/env -S bash -e
#!/usr/bin/env -S bash
[[ -z "$@" ]] && set -- $(tty)