harbor run -t openthoughts/tasktrove-exp-rpt-stack-bash-withtests-v2-stack-bash-withtests-1541harbor download openthoughts/tasktrove-exp-rpt-stack-bash-withtests-v2-stack-bash-withtests-1541Implement a user and group management script that sets up a web application environment. The script should perform the following functionalities:
User and Group Validation:
IFM_DOCKER_UID and IFM_DOCKER_GID are set and ensure they are both numeric.IFM_DOCKER_GID is not set, it should be assigned the value of IFM_DOCKER_UID.User Deletion:
IFM_DOCKER_UID already exists, remove that user.Group Management:
IFM_DOCKER_GID exists. If not, create it.User Creation:
IFM_DOCKER_UID, add it to the identified group, and assign necessary options for the user.Fallback for Default User/Group:
IFM_DOCKER_UID is not set, default to creating a user with UID 33 and a corresponding group.Start PHP Server:
Expected Input:
IFM_DOCKER_UID and optionally IFM_DOCKER_GID.Expected Output:
File Location and Naming:
/app/setup_user.sh.The following test script will be used to verify your solution:
#!/bin/sh
set -e
if [ ! -z $IFM_DOCKER_UID ]; then
# check if UID/GID are numeric
if ! echo "$IFM_DOCKER_UID$IFM_DOCKER_GID" | egrep "^[0-9]+$" >/dev/null 2>&1; then
echo "FATAL: IFM_DOCKER_UID or IFM_DOCKER_GID are not numeric (UID: $IFM_DOCKER_UID, GID: $IFM_DOCKER_GID)"
exit 1
fi
# get GID if not set
if [ -z $IFM_DOCKER_GID ]; then
export IFM_DOCKER_GID=$IFM_DOCKER_UID
fi
# delete user if already exists
if getent passwd $IFM_DOCKER_UID >/dev/null 2>&1; then
deluser $(getent passwd $IFM_DOCKER_UID | sed "s/:.*//")
fi
# check if group already exists
if ! getent group $IFM_DOCKER_GID >/dev/null 2>&1; then
addgroup -g $IFM_DOCKER_GID -S www-data
REAL_GROUP=www-data
else
REAL_GROUP=$(getent group $IFM_DOCKER_GID | sed "s/:.*//")
fi
adduser -u $IFM_DOCKER_UID -SHDG $REAL_GROUP www-data
else
addgroup -g 33 -S www-data
adduser -SHD -u 33 -G www-data www-data
fi
sudo -Eu www-data /usr/local/bin/php -c /usr/local/share/webapps/ifm/php.ini -S 0:80 -t /usr/local/share/webapps/ifm