consolidate storage validation logic

This commit is contained in:
Girish Ramakrishnan
2022-06-03 10:56:50 -07:00
parent 7dba294961
commit 7598cf2baf
4 changed files with 62 additions and 14 deletions

39
src/scripts/checkvolume.sh Executable file
View 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

View File

@@ -20,4 +20,3 @@ fi
volume_dir="$1"
mkdir -p "${volume_dir}"