feat: Add Vaultwarden config and set PUID to 1044
This commit is contained in:
94
vaultwarden/create_vaultwarden_folders.sh
Normal file
94
vaultwarden/create_vaultwarden_folders.sh
Normal file
@@ -0,0 +1,94 @@
|
||||
#!/bin/bash
|
||||
# Default to dry-run mode
|
||||
DRY_RUN=true
|
||||
if [[ "$1" == "--run" || "$1" == "-r" ]]; then DRY_RUN=false; fi
|
||||
|
||||
if [ "$DRY_RUN" = "true" ]; then
|
||||
echo "--- DRY RUN MODE ---"
|
||||
echo "To apply changes, run: sudo bash $0 --run"
|
||||
echo "--------------------"
|
||||
fi
|
||||
|
||||
# Configuration
|
||||
BASE="/volume1/docker/vaultwarden"
|
||||
# Replace PUID/PGID with the ones from your environment or Synology DSM
|
||||
USER_ID="1044:65538" # svc-vaultwarden
|
||||
|
||||
# Helper functions
|
||||
run_mkdir() {
|
||||
local path=$1
|
||||
if [ -d "$path" ]; then
|
||||
echo "[OK] Folder exists, no changes will be made: $path"
|
||||
else
|
||||
if [ "$DRY_RUN" = "true" ]; then
|
||||
echo "[WILL CREATE] Folder: $path"
|
||||
else
|
||||
echo "[EXECUTE] Creating folder: $path"
|
||||
mkdir -p "$path"
|
||||
fi
|
||||
fi
|
||||
}
|
||||
|
||||
run_chown_recursive() {
|
||||
local owner=$1; local path=$2
|
||||
local uid=${owner%%:*}; local gid=${owner#*:}
|
||||
|
||||
# Check if folder exists first
|
||||
if [ ! -d "$path" ]; then
|
||||
if [ "$DRY_RUN" = "true" ]; then
|
||||
echo "[WILL SET] Owner to $owner upon creation: $path"
|
||||
else
|
||||
echo "[EXECUTE] Setting owner to $owner (recursive): $path"
|
||||
chown -R "$owner" "$path"
|
||||
fi
|
||||
return
|
||||
fi
|
||||
|
||||
# Check if any file/folder inside diverges from the target ownership
|
||||
if find "$path" \( ! -uid "$uid" -o ! -gid "$gid" \) | grep -q .; then
|
||||
if [ "$DRY_RUN" = "true" ]; then
|
||||
echo "[WILL CHANGE] Owner to $owner (recursive): $path"
|
||||
else
|
||||
echo "[EXECUTE] Setting owner to $owner (recursive): $path"
|
||||
chown -R "$owner" "$path"
|
||||
fi
|
||||
else
|
||||
echo "[OK] Owner is $owner, no changes will be made: $path"
|
||||
fi
|
||||
}
|
||||
|
||||
run_chmod_recursive() {
|
||||
local mode=$1; local path=$2
|
||||
|
||||
# Check if folder exists first
|
||||
if [ ! -d "$path" ]; then
|
||||
if [ "$DRY_RUN" = "true" ]; then
|
||||
echo "[WILL SET] Permissions to $mode upon creation: $path"
|
||||
else
|
||||
echo "[EXECUTE] Setting permissions to $mode (recursive): $path"
|
||||
chmod -R "$mode" "$path"
|
||||
fi
|
||||
return
|
||||
fi
|
||||
|
||||
# Check if any file/folder inside diverges from the target permissions
|
||||
if find "$path" ! -perm -"$mode" | grep -q .; then
|
||||
if [ "$DRY_RUN" = "true" ]; then
|
||||
echo "[WILL CHANGE] Permissions to $mode (recursive): $path"
|
||||
else
|
||||
echo "[EXECUTE] Setting permissions to $mode (recursive): $path"
|
||||
chmod -R "$mode" "$path"
|
||||
fi
|
||||
else
|
||||
echo "[OK] Permissions are $mode, no changes will be made: $path"
|
||||
fi
|
||||
}
|
||||
|
||||
# Run tasks
|
||||
run_mkdir "${BASE}/data"
|
||||
run_chown_recursive "$USER_ID" "${BASE}"
|
||||
run_chmod_recursive 750 "${BASE}"
|
||||
|
||||
if [ "$DRY_RUN" = "false" ]; then
|
||||
echo "Done."
|
||||
fi
|
||||
Reference in New Issue
Block a user