#! /bin/bash # JConf, a JupyterHub user manager. Manages system users and links them with jupyterhub accounts. # Version 0.1 - 24th Nov, 2025 # MIT Licensed, by The Grammer Society # required options: # setup: must be run after downloaded. Will create a new venv in /opt, installs jupyterhub, lab and notebook. Checks if npm is installed, then installs configurable http server, installs itself to /usr/bin. Installs service file, enables and starts it. Adds root to admins. # adduser: creates a system user, asks for password, calls jupyterhub api to create a new user, adds penv to user, su user, penv init and penv creates a default environment. Also copy some instructions in readme file. # deluser: deletes jupyterhub user, deletes user home, deletes user profile from system. # start: starts the server, systemd call # stop: stops the server, systemd call title() { echo "JConf: JupyterHub Configuration Manager." } usage() { echo "Must run as root." echo "Usage: jconf " echo "" echo "User Management Commands:" echo " - adduser " echo " - deluser " echo " - listusers" echo "" echo "Server Management Commands:" echo " - start" echo " - stop" echo " - install" echo " - uninstall" } if [ "$#" -lt 1 ]; then title usage exit 1 fi cmd=$1 case "$cmd" in adduser) exist=$(awk -F: -v username="$2" '{if ($1 == username && $3 >= 1000 && $1 != "nobody") {print 1; found=1; exit}} END {if (!found) print 0}' /etc/passwd) if [ "$exist" -eq 1 ]; then echo "$2 user already exists" else while true; do read -rp "Do you want to create an user account $2 [Y/n]:" yn case $yn in [Yy]* ) useradd "$2"; echo "Enter the password for $2:"; passwd "$2" echo "$2 user account created successfully"; break;; [Nn]* ) exit 1;; * ) echo "Please answer Y or N.";; esac done fi exit 1 ;; deluser) exist=$(awk -F: -v username="$2" '{if ($1 == username && $3 >= 1000 && $1 != "nobody") {print 1; found=1; exit}} END {if (!found) print 0}' /etc/passwd) if [ "$exist" -eq 0 ]; then echo "$2 user doesn't exist" exit 1 else while true; do read -rp "Do you want to delete $2 user account? [Y/n]:" yn case $yn in [Yy]* ) userdel -rRZ "$2"; echo "$2 user account deleted successfully"; break;; [Nn]* ) exit 1;; * ) echo "Please answer yes or no.";; esac done fi exit 1 ;; listusers) husers=$(awk -F: '{ if ($3 >= 1000 && $1 != "nobody" ) {print $1}}' /etc/passwd) echo $husers ;; start) echo ;; stop) echo ;; install) echo ;; uninstall) echo ;; *) echo ;; esac