citadel-core/scripts/citadel-os/change-password

40 lines
933 B
Plaintext
Raw Normal View History

#!/usr/bin/env bash
2022-02-02 18:13:20 +00:00
# SPDX-FileCopyrightText: 2021-2022 Citadel and contributors
#
2022-01-21 20:37:48 +00:00
# SPDX-License-Identifier: GPL-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}"