Skip to content

Commit

Permalink
Add NetBSD support to user admin scripts
Browse files Browse the repository at this point in the history
  • Loading branch information
outpaddling committed Jun 15, 2023
1 parent 83805e7 commit 3abe012
Show file tree
Hide file tree
Showing 10 changed files with 53 additions and 38 deletions.
6 changes: 3 additions & 3 deletions Sys-scripts/auto-add-group
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ usage()
# Main
##########################################################################

if [ $1 = -g ]; then
if [ 0$1 = 0-g ]; then
gid_flags="-g $2"
shift
shift
Expand All @@ -41,8 +41,8 @@ FreeBSD)
pw groupadd $group_name $gid_flags
;;

RHEL)
groupadd $group_flags $group_name
NetBSD|RHEL)
groupadd $gid_flags $group_name
;;

*)
Expand Down
4 changes: 4 additions & 0 deletions Sys-scripts/auto-add-to-group
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,10 @@ FreeBSD)
pw groupmod $group_name -m $user_name
;;

NetBSD)
usermod -G $group_name $user_name
;;

RHEL)
usermod -a -G $group_name $user_name
;;
Expand Down
21 changes: 15 additions & 6 deletions Sys-scripts/auto-adduser
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,12 @@ FreeBSD)
default_shell="/bin/tcsh"
;;

NetBSD)
ldap_conf=$(auto-pkgsrc-prefix)/etc/openldap/ldap.conf
ldap_flags='-x'
default_shell="/bin/ksh"
;;

RHEL)
ldap_conf=/etc/openldap/ldap.conf
ldap_flags='-x'
Expand Down Expand Up @@ -332,7 +338,7 @@ fi

# Some users may belong to multiple groups. If so, add them here.
case $(auto-ostype) in
FreeBSD)
FreeBSD|NetBSD)
printf "Add $user_name to operator group to allow shutdown, reboot, etc? y/[n] "
read add
if [ 0$add = 0y ]; then
Expand All @@ -345,12 +351,15 @@ FreeBSD)
add_group wheel
fi

printf "Add $user_name to video group for optimal graphics performance? [y]/n "
read add
if [ 0$add != 0n ]; then
add_group video
if [ $(auto-ostype) = FreeBSD ]; then
printf "Add $user_name to video group for optimal graphics performance? [y]/n "
read add
if [ 0$add != 0n ]; then
add_group video
fi
fi
esac

group='x'
while [ $group ]; do
printf "Enter another supplementary group or just press return to move on] "
Expand Down Expand Up @@ -406,4 +415,4 @@ printf "Adding user $user_name...\n"
# $agroup_flags -m $user_name

auto-useradd $useradd_flags \
$user_name $uid $primary_group "$gecos" $shell $agroup_flags
$user_name $uid $primary_group $gid "$gecos" $shell $agroup_flags
4 changes: 3 additions & 1 deletion Sys-scripts/auto-change-group-gid
Original file line number Diff line number Diff line change
Expand Up @@ -111,10 +111,11 @@ fi
ostype=`auto-ostype`
case $ostype in
FreeBSD)
# FIXME: Make sure /etc/passwd is being updated
pw groupmod $group_name -g $new_gid
;;

RHEL)
NetBSD|RHEL)
groupmod -g $new_gid $group_name
;;

Expand All @@ -139,6 +140,7 @@ done
if [ 0"$dirs" != 0 ]; then
# Can't use auto-change-group-ownership here because it requires
# a username as well as a group name. Should that be changed?
printf "Searching $dirs for files with old gid...\n"
find $dirs -fstype nfs -prune -o \
-group $old_gid -exec chgrp $verbose -h $group_name '{}' +
fi
2 changes: 1 addition & 1 deletion Sys-scripts/auto-change-primary-group
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ FreeBSD)
pw usermod $user_name -g $new_group
;;

RHEL)
NetBSD|RHEL)
usermod -g $new_group $user_name
;;

Expand Down
2 changes: 1 addition & 1 deletion Sys-scripts/auto-change-uid
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ FreeBSD)
pw usermod $user_name -u $new_uid
;;

RHEL)
NetBSD|RHEL)
usermod -u $new_uid $user_name
;;

Expand Down
4 changes: 4 additions & 0 deletions Sys-scripts/auto-lock-user
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,10 @@ FreeBSD)
pw lock $user_name
;;

NetBSD)
usermod -C yes $user_name
;;

RHEL)
# FIXME: Is there a way in Linux to lock an account and restore to
# exact config (shell and expiration date) later?
Expand Down
5 changes: 5 additions & 0 deletions Sys-scripts/auto-remove-from-group
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,11 @@ FreeBSD)
pw groupmod $group_name -d $user_name
;;

NetBSD)
printf "NetBSD lacks a commend for removing a user from a group.\n"
printf "Edit /etc/group manually.\n"
;;

RHEL)
# Cannot be done conveniently with usermod
gpasswd -d $user_name $group_name
Expand Down
4 changes: 4 additions & 0 deletions Sys-scripts/auto-unlock-user
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,10 @@ FreeBSD)
pw unlock $user_name
;;

NetBSD)
usermod -C no $user_name
;;

RHEL)
# FIXME: Is there a way in Linux to lock an account and restore to
# exact config (shell and expiration date) later?
Expand Down
39 changes: 13 additions & 26 deletions Sys-scripts/auto-useradd
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

usage()
{
printf "Usage: $0 username uid primary-group-name 'Comment' shell max-password-age additional useradd flags]\n"
printf "Usage: $0 username uid primary-group-name gid 'Comment' shell max-password-age additional useradd flags]\n"
exit 1
}

Expand All @@ -25,12 +25,12 @@ if [ `id -un` != root ]; then
exit 1
fi

if [ $1 = '--no-local-pw' ]; then
if [ 0$1 = 0'--no-local-pw' ]; then
no_local_pw=1
shift
fi

if [ $# -lt 5 ]; then
if [ $# -lt 6 ]; then
usage
fi

Expand All @@ -39,45 +39,32 @@ os_type=`auto-ostype`
user_name="$1"
user_id="$2"
group_name="$3"
gecos="$4"
shell="$5"
shift; shift; shift; shift; shift
gid="$4"
gecos="$5"
shell="$6"
shift; shift; shift; shift; shift; shift

# Create group if necessary
found_name=`awk -F : '$1 == "'$group_name'" { print $1 }' /etc/group`
if [ 0$found_name = 0$group_name ]; then
printf "$group_name already exists.\n"
else
printf "Creating $group_name\n"
case $os_type in
FreeBSD)
pw groupadd $group_name -g $user_id
;;

RHEL)
groupadd -g $user_id $group_name
;;

*)
auto-unsupported-os $0
exit 1
;;

esac
auto-add-group -g $gid $group_name
fi

# Create user
case $os_type in
RHEL)
useradd -c "$gecos" -g $group_name -m -s $shell -u $user_id $@ \
$user_name
;;

FreeBSD)
pw useradd $user_name -c "$gecos" -g $group_name -m \
-s $shell -u $user_id $@
;;

NetBSD|RHEL)
useradd -c "$gecos" -g $group_name -m -s $shell -u $user_id $@ \
$user_name
;;

*)
auto-unsupported-os $0
exit 1
Expand Down

0 comments on commit 3abe012

Please sign in to comment.