Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixes to User #174

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 9 additions & 4 deletions option/User/setup.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,30 +3,35 @@ PW=/usr/sbin/pw
CHOWN=/usr/sbin/chown
AWK=/usr/bin/awk
HOME_DIR=/usr/home
USER_SHELL=/bin/sh

pw_create_account ( ) {
echo "Adding user $1 with password $1"
echo "Adding user $1 with group $1 and password $1"
mkdir -p ${BOARD_FREEBSD_MOUNTPOINT}${HOME_DIR}/$1
$PW -V ${BOARD_FREEBSD_MOUNTPOINT}/etc/ useradd -n $1 -s /bin/csh -g wheel -w yes -d ${HOME_DIR}/$1
$PW -V ${BOARD_FREEBSD_MOUNTPOINT}/etc/ useradd -n $1 -s ${USER_SHELL} -w yes -d ${HOME_DIR}/$1

# Fetch the uid and gid from the target and use the numeric ids to set the ownership
UGID=`$PW -V ${BOARD_FREEBSD_MOUNTPOINT}/etc/ usershow $1 | $AWK -F: '{ print $3 ":" $4 }'`
$CHOWN $UGID ${BOARD_FREEBSD_MOUNTPOINT}${HOME_DIR}/$1
}

pw_add_user_to_group ( ) {
if ! $PW -V ${BOARD_FREEBSD_MOUNTPOINT}/etc/ groupshow $2 >/dev/null 2>&1; then
echo "Adding group $2"
$PW -V ${BOARD_FREEBSD_MOUNTPOINT}/etc/ groupadd $2 >/dev/null 2>&1
fi
echo "Adding user $1 to group $2"
$PW -V ${BOARD_FREEBSD_MOUNTPOINT}/etc/ groupmod $2 -m $1
}

# Add the specified account.
strategy_add $PHASE_FREEBSD_BOARD_INSTALL pw_create_account $1
strategy_add $PHASE_FREEBSD_OPTION_INSTALL pw_create_account $1

if [ $? > 2 ]; then
USER=$1
shift
for GROUP in $@; do
# Group can be added by pkg, ensure this happens after pkg install in "option Package".
PRIORITY=110 strategy_add $PHASE_FREEBSD_BOARD_INSTALL pw_add_user_to_group $USER $GROUP
PRIORITY=110 strategy_add $PHASE_FREEBSD_OPTION_INSTALL pw_add_user_to_group $USER $GROUP
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The strategy sort is stable, so you don't actually need different priorities here, as long as pw_create_account is added before pw_add_user_to_group.

done
fi