From d9c18b3fcb9b036b6cdf69397828b59ab4c53091 Mon Sep 17 00:00:00 2001 From: Cullum Smith Date: Mon, 5 Aug 2024 14:59:15 -0400 Subject: cleanup add_user function --- files/etc/devd/usb-tether.conf.roadwarrior_laptop | 6 +++ files/etc/devd/usb-tether.conf.roadwarrior_latpop | 6 --- lib/40-os | 55 -------------------- lib/40-user | 63 +++++++++++++++++++++++ scripts/hostname/rlaptop1 | 3 +- 5 files changed, 71 insertions(+), 62 deletions(-) create mode 100644 files/etc/devd/usb-tether.conf.roadwarrior_laptop delete mode 100644 files/etc/devd/usb-tether.conf.roadwarrior_latpop diff --git a/files/etc/devd/usb-tether.conf.roadwarrior_laptop b/files/etc/devd/usb-tether.conf.roadwarrior_laptop new file mode 100644 index 0000000..5183ed2 --- /dev/null +++ b/files/etc/devd/usb-tether.conf.roadwarrior_laptop @@ -0,0 +1,6 @@ +notify 100 { + match "system" "IFNET"; + match "subsystem" "ue0"; + match "type" "ATTACH"; + action "/sbin/ifconfig ue0 up"; +}; diff --git a/files/etc/devd/usb-tether.conf.roadwarrior_latpop b/files/etc/devd/usb-tether.conf.roadwarrior_latpop deleted file mode 100644 index 5183ed2..0000000 --- a/files/etc/devd/usb-tether.conf.roadwarrior_latpop +++ /dev/null @@ -1,6 +0,0 @@ -notify 100 { - match "system" "IFNET"; - match "subsystem" "ue0"; - match "type" "ATTACH"; - action "/sbin/ifconfig ue0 up"; -}; diff --git a/lib/40-os b/lib/40-os index 3adcadc..eee7392 100644 --- a/lib/40-os +++ b/lib/40-os @@ -62,58 +62,3 @@ load_kernel_module(){ ;; esac } - -add_local_user(){ - _bcalu_homedir_mode=700 - _bcalu_create_homedir= - _bcalu_homedir= - _bcalu_comment= - _bcalu_shell=/sbin/nologin - _bcalu_pgroup= - _bcalu_grouplist= - _bcalu_uid= - - # Add a local user if it doesn't exist. - while getopts c:d:G:g:mM:s:u: _bcalu_opt; do - case $_bcalu_opt in - c) _bcalu_comment=$OPTARG ;; - d) _bcalu_homedir=$OPTARG ;; - G) _bcalu_grouplist=$OPTARG ;; - g) _bcalu_pgroup=$OPTARG ;; - M) _bcalu_homedir_mode=$OPTARG ;; - m) _bcalu_create_homedir=true ;; - s) _bcalu_shell=$OPTARG ;; - u) _bcalu_uid=$OPTARG ;; - esac - done - shift $((OPTIND - 1)) - - _bcalu_username=$1 - : ${_bcalu_homedir:="/home/${_bcalu_username}"} - : ${_bcalu_comment:="${_bcalu_username} user"} - - case $BOXCONF_OS in - freebsd) - if pw usershow "$_bcalu_username" > /dev/null 2>&1; then - log "local user ${_bcalu_username} already exists" - return 0 - fi - - pw useradd \ - -n "$_bcalu_username" \ - -c "$_bcalu_comment" \ - -s "$_bcalu_shell" \ - -M "$_bcalu_homedir_mode" \ - -d "$_bcalu_homedir" \ - ${_bcalu_create_homedir:+-m} \ - ${_bcalu_grouplist:+-G ${_bcalu_grouplist}} \ - ${_bcalu_pgroup:+-g ${_bcalu_pgroup}} \ - ${_bcalu_uid:+-u ${_bcalu_uid}} - - log "added local user ${_bcalu_username}" - ;; - *) - die "add_local_user unimplemented for ${BOXCONF_OS}" - ;; - esac -} diff --git a/lib/40-user b/lib/40-user index 42bbb82..305fab6 100644 --- a/lib/40-user +++ b/lib/40-user @@ -24,3 +24,66 @@ set_password(){ # $2 = password printf '%s\n%s\n' "$2" "$2" | passwd "$1" > /dev/null } + +add_user(){ + # Add a local user if it doesn't exist. + # options: mostly same as `pw useradd` + # $1 = username + _bcalu_homedir_mode=700 + _bcalu_create_homedir= + _bcalu_homedir= + _bcalu_comment= + _bcalu_shell=/sbin/nologin + _bcalu_pgroup= + _bcalu_grouplist= + _bcalu_uid= + _bcalu_password= + + while getopts c:d:G:g:mM:p:s:u: _bcalu_opt; do + case $_bcalu_opt in + c) _bcalu_comment=$OPTARG ;; + d) _bcalu_homedir=$OPTARG ;; + G) _bcalu_grouplist=$OPTARG ;; + g) _bcalu_pgroup=$OPTARG ;; + M) _bcalu_homedir_mode=$OPTARG ;; + m) _bcalu_create_homedir=true ;; + p) _bcalu_password=$OPTARG ;; + s) _bcalu_shell=$OPTARG ;; + u) _bcalu_uid=$OPTARG ;; + esac + done + shift $((OPTIND - 1)) + + _bcalu_username=$1 + : ${_bcalu_homedir:="/home/${_bcalu_username}"} + : ${_bcalu_comment:="${_bcalu_username} user"} + + case $BOXCONF_OS in + freebsd) + if pw usershow "$_bcalu_username" > /dev/null 2>&1; then + log "local user ${_bcalu_username} already exists" + return 0 + fi + + pw useradd \ + -n "$_bcalu_username" \ + -c "$_bcalu_comment" \ + -s "$_bcalu_shell" \ + -M "$_bcalu_homedir_mode" \ + -d "$_bcalu_homedir" \ + ${_bcalu_create_homedir:+-m} \ + ${_bcalu_grouplist:+-G ${_bcalu_grouplist}} \ + ${_bcalu_pgroup:+-g ${_bcalu_pgroup}} \ + ${_bcalu_uid:+-u ${_bcalu_uid}} + + log "added local user ${_bcalu_username}" + ;; + *) + die "add_local_user unimplemented for ${BOXCONF_OS}" + ;; + esac + + if [ -n "${_bcalu_password}" ]; then + set_password "$_bcalu_user" "$_bcalu_password" + fi +} diff --git a/scripts/hostname/rlaptop1 b/scripts/hostname/rlaptop1 index b1c9865..f346965 100644 --- a/scripts/hostname/rlaptop1 +++ b/scripts/hostname/rlaptop1 @@ -1,8 +1,9 @@ #!/bin/sh -add_local_user \ +add_user \ -c "Cullum Smith" \ -G wheel,operator,video \ -s /bin/sh \ -m \ + -p changeme \ cullum -- cgit v1.2.3