Update update-data.sh

This commit is contained in:
Case Duckworth 2021-11-21 14:01:01 -06:00
parent 3f2f9cebee
commit df1b10d7b5
1 changed files with 62 additions and 7 deletions

69
site/bin/update-data.sh Normal file → Executable file
View File

@ -7,13 +7,68 @@
# - comment a LOT!
main() {
# dispatcher function.
# this will run everything else.
# dispatcher function.
# this will run everything else.
# change when deploying
prefix=~/breadpunk/site/static
# jobs to run
# command | toml_output > file
update_shells > $prefix/shells.toml
update_users > $prefix/users.toml
}
# utilities
# toml utilities
toml_output() { # toml_output FILE ARRAY_ITEMS
# stupid toml outputter.
# outputs ARRAY_ITEMS as a toml array to FILE.
# adds warning comment and stuff.
toml_output() {
# stupid toml outputter.
# outputs lines of stdin as a toml array to stdout.
# adds warning comment and stuff.
toml_header
toml_array data
}
toml_array() { # toml_array ARRAY_NAME
# read lines from stdin, and write a toml array called ARRAY_NAME or
# 'data' if not provided.
cat << END
${1:-data} = [
$(while read item; do printf '"%s", ' "$item"; done)
]
END
}
toml_header() {
cat << END
# THIS FILE IS AUTOGENERATED BY $0
# DO NOT HAND-EDIT
END
}
# updaters
update_shells() {
# output a list of all the shells installed
awk < /etc/shells -F/ \
'/^#/{next}/tmux$/{next}/screen$/{next}
{if (!match(shs, $NF)) shs = (shs ? shs"\n" : shs) $NF}
END{print shs}' | toml_output
}
update_users() {
# output a list of all users with ~/public_html directories, sorting by
# newest.
toml_header
# list of all users is in all
find /home/*/public_html -maxdepth 0 -printf '%T@\t%p\n'|
sort -nr |
cut -f2- |
sed 's,/home/\(.*\)/public_html,\1,' |
toml_array all
# list of logged in users is in login
users | tr ' ' '\n'| sort -u | toml_array login
}
# run the thing - DON'T EDIT HERE
main "$@"