Skip to content

Commit cbb9ab3

Browse files
chore: Update setup.sh and test.sh scripts to fix file ownership issue
1 parent c027513 commit cbb9ab3

3 files changed

Lines changed: 25 additions & 23 deletions

File tree

.github/workflows/pylint.yml

Lines changed: 0 additions & 23 deletions
This file was deleted.

setup.sh

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ get_user_home() {
2121

2222
# Set paths relative to the correct user's home directory
2323
USER_HOME=$(get_user_home)
24+
USER_NAME=$(echo $USER_HOME | awk -F'/' '{print $3}')
2425
DOWNLOAD_DIR="/tmp"
2526
EXTRACT_DIR="$USER_HOME/.systemguard/"
2627
LOG_DIR="$HOME/logs"
@@ -274,3 +275,8 @@ case $ACTION in
274275
load_test) load_test ;;
275276
*) echo "No action specified. Use --help for usage information." ;;
276277
esac
278+
279+
280+
# this script ran with sudo command so all the files have root permission
281+
# remove the root permission from the files to the user
282+
chown -R $USER_NAME:$USER_NAME $EXTRACT_DIR

test.sh

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
get_user_home() {
2+
if [ -n "$SUDO_USER" ]; then
3+
# When using sudo, SUDO_USER gives the original user who invoked sudo
4+
TARGET_USER="$SUDO_USER"
5+
else
6+
# If not using sudo, use LOGNAME to find the current user
7+
TARGET_USER="$LOGNAME"
8+
fi
9+
10+
# Get the home directory of the target user
11+
USER_HOME=$(eval echo ~$TARGET_USER)
12+
echo "$USER_HOME"
13+
}
14+
15+
USER_HOME=$(get_user_home)
16+
echo "USER_HOME: $USER_HOME"
17+
# get only user name
18+
USER_NAME=$(echo $USER_HOME | awk -F'/' '{print $3}')
19+
echo "USER_NAME: $USER_NAME"

0 commit comments

Comments
 (0)