Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

feat: add "check" command #44

Merged
merged 5 commits into from
Dec 18, 2024
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
75 changes: 75 additions & 0 deletions bin/quipucords-installer
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ usage() {
echo " uninstall Uninstall Quipucords"
echo " create-server-password Create a Quipucords server password"
echo " create-app-secret Create a Quipucords application secret"
echo " check Check Quipucords setup and configurations"
exit 1
}

Expand Down Expand Up @@ -74,6 +75,7 @@ set_default_vars() {
# Do not allow a user's custom PATH environment to interfere.
export PATH="${INSTALLER_BIN_DIR}:/usr/bin:/bin:/usr/sbin:/sbin"

QUIPUCORDS_CONFIG_DIR="${XDG_CONFIG_HOME:-$HOME/.config}/quipucords"
QUIPUCORDS_ENV_DIR="${XDG_CONFIG_HOME:-$HOME/.config}/quipucords/env"
QUIPUCORDS_DATA_DIR="${XDG_DATA_HOME:-$HOME/.local/share}/quipucords"
SYSTEMD_CONFIG_DIR="${XDG_CONFIG_HOME:-$HOME/.config}/containers/systemd"
Expand Down Expand Up @@ -157,6 +159,10 @@ EOFDOC
uninstall)
uninstall
;;
check)
check
exit $?
;;
create-server-password)
create-server-password
exit $?
Expand Down Expand Up @@ -409,6 +415,75 @@ upgrade() {
return $?
}

check_directory_status() {
if [ -d "${1}" ]; then
if [ -O "${1}" ]; then
return 0 # OK
else
return 1 # Not owned by you
fi
fi
return 2 # Missing
}

check_file_status() {
if [ -f "${1}" ]; then
if [ -O "${1}" ]; then
return 0 # OK
else
return 1 # Not owned by you
fi
fi
return 2 # Missing
}

check_and_print_status() {
if [ "${1}" == "d" ]; then
check_directory_status "${2}"
else
check_file_status "${2}"
fi
local status=$?
if [ $status -eq 0 ]; then
echo "${2}: OK"
return 0
fi
if [ $status -eq 1 ]; then
echo "${2}: ERROR: Not owned by you"
return 1
fi
echo "${2}: ERROR: Missing"
return 2
}

check() {
echo "Checking Quipucords setup and configurations..."
local result=0
check_and_print_status d "${QUIPUCORDS_DATA_DIR}" || result=$((result + 1))
for name in certs data db log sshkeys; do
local subdirectory="${QUIPUCORDS_DATA_DIR}/$name"
check_and_print_status d "$subdirectory" || result=$((result + 1))
done
check_and_print_status f "${QUIPUCORDS_DATA_DIR}/certs/server.key" || result=$((result + 1))
check_and_print_status f "${QUIPUCORDS_DATA_DIR}/certs/server.crt" || result=$((result + 1))
check_and_print_status f "${QUIPUCORDS_DATA_DIR}/data/secret.txt" || result=$((result + 1))
check_and_print_status d "${QUIPUCORDS_DATA_DIR}/db/userdata" || result=$((result + 1))
check_and_print_status d "${QUIPUCORDS_CONFIG_DIR}" || result=$((result + 1))
check_and_print_status d "${QUIPUCORDS_ENV_DIR}" || result=$((result + 1))
for name in ansible app celery-worker db redis server; do
local env_file="$QUIPUCORDS_ENV_DIR/env-${name}.env"
check_and_print_status f "${env_file}" || result=$((result + 1))
done
check_and_print_status d "${SYSTEMD_CONFIG_DIR}" || result=$((result + 1))
for name in app celery-worker db redis server; do
local container_file="${SYSTEMD_CONFIG_DIR}/quipucords-${name}.container"
check_and_print_status f "${container_file}" || result=$((result + 1))
done
local network_file="${SYSTEMD_CONFIG_DIR}/quipucords.network"
check_and_print_status f "${network_file}" || result=$((result + 1))
return $result
}

stop_containers() {
echo "Stopping Quipucords ..."
systemctl --user stop quipucords-app || true
Expand Down
Loading