aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCullum Smith <cullum@sacredheartsc.com>2024-08-05 14:59:15 -0400
committerCullum Smith <cullum@sacredheartsc.com>2024-08-05 14:59:15 -0400
commitd9c18b3fcb9b036b6cdf69397828b59ab4c53091 (patch)
tree783725ce085d962440c30c25f0fad9e79fee0f19
parentd4be5bbc3682bb9d7f74db5592988ec0838b6138 (diff)
downloadinfrastructure-d9c18b3fcb9b036b6cdf69397828b59ab4c53091.tar.gz
cleanup add_user function
-rw-r--r--files/etc/devd/usb-tether.conf.roadwarrior_laptop (renamed from files/etc/devd/usb-tether.conf.roadwarrior_latpop)0
-rw-r--r--lib/40-os55
-rw-r--r--lib/40-user63
-rw-r--r--scripts/hostname/rlaptop13
4 files changed, 65 insertions, 56 deletions
diff --git a/files/etc/devd/usb-tether.conf.roadwarrior_latpop b/files/etc/devd/usb-tether.conf.roadwarrior_laptop
index 5183ed2..5183ed2 100644
--- a/files/etc/devd/usb-tether.conf.roadwarrior_latpop
+++ b/files/etc/devd/usb-tether.conf.roadwarrior_laptop
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