Files
cloudron-box/src/scripts/addmount.sh
T

40 lines
999 B
Bash
Raw Normal View History

#!/bin/bash
set -eu -o pipefail
if [[ ${EUID} -ne 0 ]]; then
echo "This script should be run as root." > /dev/stderr
exit 1
fi
if [[ $# -eq 0 ]]; then
echo "No arguments supplied"
exit 1
fi
if [[ "$1" == "--check" ]]; then
echo "OK"
exit 0
fi
mount_file_contents="$1"
# mount units must be named after the mount point directories they control
where=$(echo "${mount_file_contents}" | grep "^Where=" | cut -d'=' -f 2)
mount_filename=$(systemd-escape -p --suffix=mount "$where")
2021-05-21 17:31:54 -07:00
mount_file="/etc/systemd/system/${mount_filename}"
2021-05-14 10:26:57 -07:00
systemctl stop "${mount_filename}" || true
2021-05-21 17:31:54 -07:00
echo "$mount_file_contents" > "${mount_file}"
systemctl daemon-reload
# systemd can automatically create the "where" dir but the backup logic relies on permissions
mkdir -p "${where}"
2021-06-18 23:48:39 -07:00
chown yellowtent:yellowtent "${where}" || true # this can fail with nfs+root_squash
2021-06-20 22:36:23 -07:00
chmod 777 "${where}" # this allows all users to read and write
systemctl enable --no-block --now "${mount_filename}" || true