#!/bin/sh
# user.sh
# 2021-02-15
# by Gernot WALZL
# User management for OpenWrt
set -e
HOME_BASE_DIR="/mnt/ssd/home"
if [ ! -d "$HOME_BASE_DIR" ]; then
exit 1
fi
print_usage () {
echo "Usage: $0 {install|add|del|list} [LOGIN]"
}
install_pkgs () {
opkg update
opkg install shadow-useradd shadow-userdel
}
add_user () {
local LOGIN="$1"
if [ -z "$LOGIN" ]; then
return 1
fi
useradd -b "$HOME_BASE_DIR" -g users -m -s /bin/ash "$LOGIN"
passwd "$LOGIN"
}
del_user () {
local LOGIN="$1"
if [ -z "$LOGIN" ]; then
return 1
fi
userdel "$LOGIN"
}
list_users () {
grep ':x:[0-9]*:100:' /etc/passwd
}
case "$1" in
'install')
install_pkgs
;;
'add')
add_user "$2"
;;
'del')
del_user "$2"
;;
'list')
list_users
;;
*)
print_usage
;;
esac