Created
February 27, 2024 11:34
-
-
Save Elyasnz/c34dab816e518de7ef87a9e15d8a1f86 to your computer and use it in GitHub Desktop.
create project with related file in docker
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# setup <project> <username> | |
if [ "$1" ]; then | |
PROJECT="$1" | |
else | |
echo "Usage: setup <project> <username>" | |
exit 1 | |
fi | |
if [ "$2" ]; then | |
USERNAME="$2" | |
else | |
echo "Usage: setup <project> <username>" | |
exit 1 | |
fi | |
echo "PROJECT: $PROJECT" | |
echo "USERNAME: $USERNAME" | |
PATH_SCRIPT="$( | |
cd -- "$(dirname "$0")" >/dev/null 2>&1 | |
pwd -P | |
)" | |
echo "creating group: developer, "$USERNAME"_run" | |
groupadd developer &>/dev/null || true | |
groupadd "$USERNAME"_run &>/dev/null || true | |
echo "creating user: $USERNAME" | |
useradd -M -s /bin/bash -G developer,"$USERNAME"_run,root,adm "$USERNAME" &>/dev/null || true | |
echo "creating project files" | |
mkdir -p "$PATH_SCRIPT/$PROJECT/Project" | |
mkdir -p "$PATH_SCRIPT/$PROJECT/.run" | |
echo "setting project files ownership and permissions" | |
chown -R "$USERNAME":developer "$PATH_SCRIPT/$PROJECT" | |
chmod -R u+rw,g+rw,o+r "$PATH_SCRIPT/$PROJECT" | |
find "$PATH_SCRIPT/$PROJECT" -type d -exec chmod u+x,g+xs,o+x {} + | |
setfacl -R -m d:u::rwx,d:g::rwx,d:o::rx "$PATH_SCRIPT/$PROJECT" | |
echo "setting project run files ownership and permissions" | |
chown -R "$USERNAME":"$USERNAME"_run "$PATH_SCRIPT/$PROJECT/.run" | |
chmod -R u+rw,g+rw,o+r "$PATH_SCRIPT/$PROJECT/.run" | |
find "$PATH_SCRIPT/$PROJECT/.run" -type d -exec chmod u+x,g+xs,o+x {} + | |
setfacl -R -m d:u::rwx,d:g::rwx,d:o::rx "$PATH_SCRIPT/$PROJECT/.run" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment