This repository has been archived by the owner on Nov 9, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathupdate-work-PI.sh
executable file
·52 lines (41 loc) · 1.69 KB
/
update-work-PI.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
#!/bin/bash
source config.sh
pi_groups=$(ldapsearch -LLL -H ${LDAP_SERVER} -x -b "${LDAP_PISEARCHBASE}" -s sub "(objectClass=posixGroup)" cn | sed -n 's/^[ \t]*cn:[ \t]*\(.*\)/\1/p')
pi_groups=$(echo $pi_groups | sed -e 's/\s\+/,/g')
existing_quotas=$(curl -u ${VAST_USER}:${VAST_PASS} --insecure -s -X GET "https://${VAST_IP}/api/quotas/" -H "accept: application/json" | jq -r '.[].name')
echo $pi_groups | tr "," "\n" | while read LINE
do
if [ "$LINE" == "" ]; then
continue
fi
if echo $existing_quotas | grep -q -w -P "work-${LINE}"; then
echo "Quota for ${LINE} already exists, skipping..."
else
echo "Creating quota/directory for ${LINE}..."
curl -u ${VAST_USER}:${VAST_PASS} --insecure -s -X POST "https://${VAST_IP}/api/quotas/" -H "accept: application/json" -H "Content-Type: application/json" -d "{ \"name\": \"work-${LINE}\", \"path\": \"${QUOTA_WORK_PATH}/${LINE}\", \"hard_limit\": ${QUOTA_WORK_AMOUNT}, \"create_dir\": \"True\" }" > /dev/null
if [ $? -eq 0 ]; then
echo "OK"
else
echo "FAIL"
fi
owner=${LINE#"pi_"}
echo $owner
echo "Settings perms on ${LINE}..."
install -d -m 2770 -o $owner -g ${LINE} ${WORK_MOUNT_PATH}/${LINE}
#echo "Setting ownership on ${LINE}..."
#chown $owner:$LINE ${WORK_MOUNT_PATH}/${LINE}
#if [ $? -eq 0 ]; then
# echo "OK"
#else
# echo "FAIL"
#fi
#echo "Setting permissions on ${LINE}..."
#chmod 770 ${WORK_MOUNT_PATH}/${LINE}
#chmod g+s ${WORK_MOUNT_PATH}/${LINE}
#if [ $? -eq 0 ]; then
# echo "OK"
#else
# echo "FAIL"
#fi
fi
done