75 lines
1.7 KiB
Bash
Executable File
75 lines
1.7 KiB
Bash
Executable File
#!/bin/sh
|
|
# update-data.sh - update "dynamic" data for zola
|
|
# adding functions:
|
|
# - write a function that outputs the data you want as toml to
|
|
# /bread/site/static/.
|
|
# - add that function to the main() function below.
|
|
# - comment a LOT!
|
|
|
|
main() {
|
|
# dispatcher function.
|
|
# this will run everything else.
|
|
|
|
# change when deploying
|
|
prefix="${BREADSITE_DATA_DIR:-~/breadpunk/site/static}"
|
|
|
|
# jobs to run
|
|
# command | toml_output > file
|
|
update_shells > $prefix/shells.toml
|
|
update_users > $prefix/users.toml
|
|
}
|
|
|
|
# toml utilities
|
|
|
|
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 "$@"
|