about summary refs log tree commit diff stats
path: root/Dockerfile
blob: 36ad0a95b7d8919128fc4b4e8d8fc366669d2b27 (plain) (blame)
1
2
3
4
5
6
7
8
# Usage instructions:
# 1. "docker build -t ranger/ranger:latest ."
# 2. "docker run -it ranger/ranger"

FROM debian

RUN apt-get update && apt-get install -y ranger
ENTRYPOINT ["ranger"]
kground-color: #fff0f0 } /* Literal.String.Char */ .highlight .dl { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Delimiter */ .highlight .sd { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Doc */ .highlight .s2 { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Double */ .highlight .se { color: #0044dd; background-color: #fff0f0 } /* Literal.String.Escape */ .highlight .sh { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Heredoc */ .highlight .si { color: #3333bb; background-color: #fff0f0 } /* Literal.String.Interpol */ .highlight .sx { color: #22bb22; background-color: #f0fff0 } /* Literal.String.Other */ .highlight .sr { color: #008800; background-color: #fff0ff } /* Literal.String.Regex */ .highlight .s1 { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Single */ .highlight .ss { color: #aa6600; background-color: #fff0f0 } /* Literal.String.Symbol */ .highlight .bp { color: #003388 } /* Name.Builtin.Pseudo */ .highlight .fm { color: #0066bb; font-weight: bold } /* Name.Function.Magic */ .highlight .vc { color: #336699 } /* Name.Variable.Class */ .highlight .vg { color: #dd7700 } /* Name.Variable.Global */ .highlight .vi { color: #3333bb } /* Name.Variable.Instance */ .highlight .vm { color: #336699 } /* Name.Variable.Magic */ .highlight .il { color: #0000DD; font-weight: bold } /* Literal.Number.Integer.Long */
#!/usr/local/bin/bash
# ---------------------------------------------------------------------------
# makeuser - tilde.institute new user creation
# Usage: makeuser [-h|--help] <username> <email> "<pubkey>"
# ben@gbmor.dev
# ---------------------------------------------------------------------------

PROGNAME=${0##*/}
VERSION="0.1"

error_exit() {
  echo -e "${PROGNAME}: ${1:-"Unknown Error"}" >&2
  exit 1
}

usage() {
  echo -e "usage: $PROGNAME [-h|--help] <username> <email> \"<pubkey>\""
}

[[ $(id -u) != 0 ]] && error_exit "you must be the superuser to run this script."

USERLIST=$(</etc/passwd cut -d ":" -f1)
if [[ $USERLIST == *$1* ]]; then
    error_exit "User already exists!"
fi

case $1 in
  -h | --help)
    usage; exit ;;
  -* | --*)
    usage; error_exit "unknown option $1" ;;
  *)
    [[ $# -ne 3 ]] && error_exit "not enough args"

# generate a random 20 digit password
# encrypt the password and pass it to
# useradd, set ksh as default shell
    echo "adding new user $1"
    newpw=$(pwgen -1B 20)
    pwcrypt=$(encrypt ${newpw})
    useradd -m -g 1001 -p $pwcrypt -s /bin/ksh -k /etc/skel $1

# make the public_html directory for the users
	mkdir /var/www/users/$1
	chown $1:tilde /var/www/users/$1
	ln -s /var/www/users/$1 /home/$1/public_html

# set up the httpd configuration for
# individual users. this config forces tls
# for all subdomains
    echo "server \"$1.tilde.institute\" {
        listen on \$ext_addr port 80 block return 301 \"https://\$SERVER_NAME\$REQUEST_URI\"
    }
    server \"$1.tilde.institute\" {
		listen on \$ext_addr tls port 443
		root \"/users/$1\"
        tls {
            key \"/etc/letsencrypt/live/tilde.institute-0001/privkey.pem\"
            certificate \"/etc/letsencrypt/live/tilde.institute-0001/fullchain.pem\"
        }
		directory index index.html
		directory auto index
		location \"/*.cgi\" {
			fastcgi
		}
		location \"/*.php\" {
			fastcgi socket \"/run/php-fpm.sock\"
		}
	}" > /etc/httpd/$1.conf

# add the user's vhost config to
# the main httpd config then gracefully
# reload the httpd config
	echo "include \"/etc/httpd/$1.conf\"" >> /etc/httpd-vusers.conf
    pkill -HUP httpd

# send welcome email
        sed -e "s/newusername/$1/g" /admin/misc/email.tmpl | doas -u admins mail -s "welcome to tilde.institute!" $2

# subscribe to mailing list
    echo " " | doas -u $1 mail -s "subscribe" institute-join@lists.tildeverse.org

# announce the new user's creation on mastodon
# then copy their ssh key to their home directory
    /admin/bin/toot.py "Welcome new user ~$1!"
    echo "$3" | tee /home/$1/.ssh/authorized_keys
esac