#!/bin/sh

# generate tilde.json
run_user=$(id -un)
if [ "$run_user" = "publish" ]; then
  userlist=$(voyagers | awk '{print "{\"username\":\"" $0 "\"}," }')
  printf '{"name": "cosmic.voyage", "url": "https://cosmic.voyage", "signup_url": "https://cosmic.voyage/join.html", "user_count": %s, "want_users": true, "admin_email": "james@tomasino.org", "description": "Cosmic Voyage is a public-access unix system and tilde community based around a collaborative science-fiction universe. Users write stories as the people aboard ships, colonies, and outposts, using the only remaining free, interconnected network that unites the dispersed peoples of the stars.", "users": [%s]}' "$(grep -E '1[0-9]{3}' "/etc/passwd" | grep -c 'home')" "${userlist%?}" > "/var/gopher/tilde.json"
else
  exec sudo -u publish "$0" "$@"
fi
