citadel-core/scripts/citadel-os/change-password
2021-10-22 16:56:27 +01:00

40 lines
937 B
Bash
Executable File

#!/usr/bin/env bash
# SPDX-FileCopyrightText: 2021 Aaron Dewes <aaron.dewes@web.de>
#
# SPDX-License-Identifier: AGPL-3.0-or-later
set -euo pipefail
CITADEL_ROOT="$(readlink -f $(dirname "${BASH_SOURCE[0]}")/../..)"
PASSWORD_FILE="${CITADEL_ROOT}/statuses/password"
check_root () {
if [[ $UID != 0 ]]; then
echo "This script must be run as root"
exit 1
fi
}
check_citadel_os () {
[[ -f "/etc/default/citadel" ]] && source "/etc/default/citadel"
if [[ -z "${CITADEL_OS:-}" ]]; then
echo "This script must only be run on Citadel OS"
exit 1
fi
}
password="$(cat ${PASSWORD_FILE})"
echo "false" > "${PASSWORD_FILE}"
check_root
check_citadel_os
if [[ "${password}" == "" ]] || [[ "${password}" == "false" ]] || [[ "${password}" == "true" ]]; then
echo "Password not set in status file: \"${PASSWORD_FILE}\""
exit 1
fi
echo -e "${password}\n${password}" | passwd citadel
echo "true" > "${PASSWORD_FILE}"