|
@@ -10,6 +10,7 @@ GID: GID to change permissions to
|
|
|
{{- $type := .type | default "install" -}}
|
|
|
{{- $containerName := .containerName | default "permissions" -}}
|
|
|
{{- $mode := .mode | default "always" -}}
|
|
|
+ {{- $chmod := .chmod | default "" -}}
|
|
|
{{- $UID := .UID -}}
|
|
|
{{- $GID := .GID -}}
|
|
|
|
|
@@ -47,6 +48,9 @@ GID: GID to change permissions to
|
|
|
capabilities:
|
|
|
add:
|
|
|
- CHOWN
|
|
|
+ {{- if $chmod }}
|
|
|
+ - FOWNER
|
|
|
+ {{- end }}
|
|
|
command: bash
|
|
|
args:
|
|
|
- -c
|
|
@@ -57,30 +61,51 @@ GID: GID to change permissions to
|
|
|
continue
|
|
|
fi
|
|
|
|
|
|
- echo "Current Permissions on ["$dir"]:"
|
|
|
- stat -c "%u %g" "$dir"
|
|
|
+ echo "Current Ownership and Permissions on ["$dir"]:"
|
|
|
+ echo "chown: $(stat -c "%u %g" "$dir")"
|
|
|
+ echo "chmod: $(stat -c "%a" "$dir")"
|
|
|
|
|
|
{{- if eq $mode "check" }} {{/* If mode is check, check parent dir */}}
|
|
|
if [ $(stat -c %u "$dir") -eq {{ $UID }} ] && [ $(stat -c %g "$dir") -eq {{ $GID }} ]; then
|
|
|
- echo "Permissions are correct. Skipping..."
|
|
|
- fix_perms="false"
|
|
|
+ echo "Ownership is correct. Skipping..."
|
|
|
+ fix_owner="false"
|
|
|
else
|
|
|
- echo "Permissions are incorrect. Fixing..."
|
|
|
- fix_perms="true"
|
|
|
+ echo "Ownership is incorrect. Fixing..."
|
|
|
+ fix_owner="true"
|
|
|
fi
|
|
|
|
|
|
- {{- else if eq $mode "always" }} {{/* If mode is always, always fix perms */}}
|
|
|
+ {{- if $chmod }} {{/* Only if chmod value is given */}}
|
|
|
+ if [ $(stat -c %a "$dir") -eq {{ $chmod }} ]; then
|
|
|
+ echo "Permissions are correct. Skipping..."
|
|
|
+ fix_perms="false"
|
|
|
+ else
|
|
|
+ echo "Permissions are incorrect. Fixing..."
|
|
|
+ fix_perms="true"
|
|
|
+ fi
|
|
|
+ {{- end }}
|
|
|
|
|
|
+ {{- else if eq $mode "always" }} {{/* If mode is always, always fix perms */}}
|
|
|
+ fix_owner="true"
|
|
|
fix_perms="true"
|
|
|
-
|
|
|
{{- end }}
|
|
|
|
|
|
- if [ "$fix_perms" = "true" ]; then
|
|
|
+ {{/* Apply changes */}}
|
|
|
+ if [ "$fix_owner" = "true" ]; then
|
|
|
echo "Changing ownership to {{ $UID }}:{{ $GID }} on: ["$dir"]"
|
|
|
chown -R {{ $UID }}:{{ $GID }} "$dir"
|
|
|
echo "Finished changing ownership"
|
|
|
- echo "Permissions after changing ownership:"
|
|
|
+ echo "Ownership after changes:"
|
|
|
stat -c "%u %g" "$dir"
|
|
|
fi
|
|
|
+
|
|
|
+ {{- if $chmod }} {{/* Only if chmod value is given */}}
|
|
|
+ if [ "$fix_perms" = "true" ]; then
|
|
|
+ echo "Changing permissions to {{ $chmod }} on: ["$dir"]"
|
|
|
+ chmod -R {{ $chmod }} "$dir"
|
|
|
+ echo "Finished changing permissions"
|
|
|
+ echo "Permissions after changes:"
|
|
|
+ stat -c "%a" "$dir"
|
|
|
+ fi
|
|
|
+ {{- end }}
|
|
|
done
|
|
|
{{- end -}}
|