2022-03-09 02:07:12 +00:00
|
|
|
#!/bin/bash
|
2023-10-23 22:44:47 +00:00
|
|
|
# SPDX-License-Identifier: GPL-2.0
|
2023-10-24 16:00:57 +00:00
|
|
|
# Copyright (C) 2023 JELOS (https://github.com/JustEnoughLinuxOS)
|
2022-03-09 02:07:12 +00:00
|
|
|
|
|
|
|
. /etc/profile
|
|
|
|
|
|
|
|
ROOTPASS="$1"
|
|
|
|
|
2022-03-12 11:14:04 +00:00
|
|
|
LPC=$(awk -F: '/^root/{print $3}' /storage/.cache/shadow)
|
|
|
|
CURRENT=$(awk -F: '/^root/{print $2}' /storage/.cache/shadow)
|
|
|
|
|
2022-03-09 02:07:12 +00:00
|
|
|
# Turn it into a usable hash
|
|
|
|
NEW=$(cryptpw -m sha512 "${ROOTPASS}" 2>/dev/null)
|
|
|
|
|
|
|
|
# Set the root password.
|
|
|
|
sed -i "s#root:${CURRENT}:${LPC}::::::#root:${NEW}:${LPC}::::::#g" /storage/.cache/shadow 2>/dev/null
|
|
|
|
|
|
|
|
# Create a root user and set the password.
|
|
|
|
echo -ne "${ROOTPASS}\n${ROOTPASS}\n" | smbpasswd -sa root 2>/dev/null
|
|
|
|
|
2023-02-10 00:17:29 +00:00
|
|
|
# Set the root user and password for SyncThing
|
2023-05-07 22:01:43 +00:00
|
|
|
syncthing generate --gui-user "root" --gui-password "${ROOTPASS}" >/dev/null 2>&1
|
2023-02-10 00:17:29 +00:00
|
|
|
|
2022-03-09 02:07:12 +00:00
|
|
|
# Save the password so we can display it in ES
|
|
|
|
set_setting root.password "${ROOTPASS}"
|
2023-05-07 22:01:43 +00:00
|
|
|
|
|
|
|
# Restart syncthing if it was enabled.
|
|
|
|
SYNCSTATUS=$(get_setting syncthing.enabled)
|
2023-07-23 13:47:19 +00:00
|
|
|
SYNCACTIVE=$(systemctl status syncthing | awk '/active/ {print $2}')
|
|
|
|
if [ "${SYNCSTATUS}" = "1" ] &&
|
|
|
|
[ "${SYNCACTIVE}" = "active" ]
|
2023-05-07 22:01:43 +00:00
|
|
|
then
|
|
|
|
systemctl restart syncthing >/dev/null 2>&1
|
|
|
|
fi
|