Skip to content

Commit 0624248

Browse files
author
yiiman-dev
committed
improve logic for install-service.sh
1 parent 1bc438e commit 0624248

File tree

1 file changed

+23
-0
lines changed

1 file changed

+23
-0
lines changed

install-service.sh

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,12 +24,35 @@ if ! command -v node &> /dev/null; then
2424
apt-get install -y nodejs
2525
fi
2626

27+
28+
29+
30+
31+
# Create the new user
32+
echo "Creating user $SERVICE_USER..."
33+
2734
# Create service user if not exists
2835
if ! id "$SERVICE_USER" &>/dev/null; then
2936
useradd -r -s /bin/false $SERVICE_USER
3037
fi
3138

3239

40+
# Add the user to the sudo group
41+
echo "Adding $SERVICE_USER to the sudo group..."
42+
usermod -aG sudo "$SERVICE_USER"
43+
44+
# Verify the user belongs to the sudo group
45+
echo "Verifying sudo access for $SERVICE_USER..."
46+
groups "$SERVICE_USER" | grep -q "sudo" && echo "$SERVICE_USER has been added to the sudo group." || echo "Failed to add $SERVICE_USER to the sudo group."
47+
48+
# Test sudo access (optional)
49+
echo "Testing sudo access for $SERVICE_USER..."
50+
su - "$SERVICE_USER" -c "sudo whoami"
51+
52+
echo "User $SERVICE_USER has been created and granted sudo privileges."
53+
54+
55+
3356
chown -R $SERVICE_USER:$SERVICE_USER $PROJECT_DIR
3457

3558
# Install dependencies

0 commit comments

Comments
 (0)