#!/bin/bash # $1 - get / enable / disable # $2 - optional username ru=$USER if [ "$EUID" != 0 ]; then # Only for running user if [ "$2" != "$USER" ]; then echo "Cannot run for user other than yourself without superuser privileges." exit 0 fi else # Run for specified user if [ "$2" != "" ]; then ru=$2 else ru="root" fi fi hd="$(eval echo ~$ru)/public_gemini" if [ "$1" == "get" ]; then if [ -d "$hd" ]; then # gemini dir exists if [ -r "$hd/.serve_ok" ]; then echo "enabled" else echo "disabled" fi else echo "no_exist" fi elif [ "$1" == "enable" ]; then if [ -d "$hd" ]; then if [ -r "$hd/.serve_ok" ]; then echo "done" else touch "$hd/.serve_ok" chown "$ru" "$hd/.serve_ok" echo "done" fi else mkdir "$hd" touch "$hd/.serve_ok" chown "$ru" -R "$hd" echo "done" fi elif [ "$1" == "disable" ]; then if [ -d "$hd" ]; then if [ -w "$hd/.serve_ok" ]; then rm "$hd/.serve_ok" echo "done" else if [ -r "$hd/.serve_ok" ]; then echo "no_perm" else echo "done" fi fi else echo "no_dir" fi else # TODO: display command help guide echo "TODO" fi