40 lines
726 B
Bash
40 lines
726 B
Bash
|
|
#!/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
|
||
|
|
|
||
|
|
volume_dir="$1"
|
||
|
|
|
||
|
|
readonly test_file="${volume_dir}/.chown-test"
|
||
|
|
|
||
|
|
mkdir -p "${volume_dir}"
|
||
|
|
rm -f "${test_file}" # clean up any from previous run
|
||
|
|
|
||
|
|
if [[ -n "$(ls -A \"${volume_dir}\")" ]]; then
|
||
|
|
echo "volume dir is not empty"
|
||
|
|
exit 2
|
||
|
|
fi
|
||
|
|
|
||
|
|
touch "${test_file}"
|
||
|
|
if ! chown yellowtent:yellowtent "${test_file}"; then
|
||
|
|
echo "chown does not work"
|
||
|
|
exit 3
|
||
|
|
fi
|
||
|
|
rm -f "${test_file}"
|
||
|
|
rm -r "${volume_dir}" # will get recreated by the local storage addon
|
||
|
|
|