tildeblack-ops/webroot.sh

32 lines
760 B
Bash
Raw Permalink Normal View History

2019-08-01 12:04:13 +00:00
#!/bin/sh
all_users=$(grep /home < /etc/passwd | awk -F: '{print $1}' | sort)
current_dir=$(dirname "$(readlink -f "$0")")
2019-08-01 12:41:01 +00:00
template_dir="${current_dir}/templates/web"
2019-08-02 17:05:28 +00:00
if [ -z "$1" ]; then
output_dir="/var/www/htdocs"
else
output_dir="$1"
fi
2019-08-02 17:05:28 +00:00
{
2019-08-02 18:46:35 +00:00
cat "${template_dir}/head.partial.html"
2019-08-02 20:13:48 +00:00
# User pages section
printf "<section id=\"users\">\\n"
printf "<h3>User pages</h3>\\n"
2019-08-02 17:05:28 +00:00
printf "<ul>\\n"
printf "%s" "$all_users" | while read -r n; do
if [ -f "/var/www/htdocs/users/${n}/index.html" ]; then
printf "<li><a href='/users/%s'>~%s</a></li>\\n" "$n" "$n"
fi
done
printf "</ul>\\n"
2019-08-02 20:13:48 +00:00
printf "</section>\\n"
2019-08-02 18:46:35 +00:00
cat "${template_dir}/foot.partial.html"
} > "$output_dir/index.html"
cp -R "${template_dir}/assets/" "${output_dir}"