consolidate storage validation logic
This commit is contained in:
39
src/scripts/checkvolume.sh
Executable file
39
src/scripts/checkvolume.sh
Executable file
@@ -0,0 +1,39 @@
|
||||
#!/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
|
||||
|
||||
@@ -20,4 +20,3 @@ fi
|
||||
volume_dir="$1"
|
||||
|
||||
mkdir -p "${volume_dir}"
|
||||
|
||||
|
||||
Reference in New Issue
Block a user