From 920e63a21f4c9f347742bb8a4d4a747a95cb2a0e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B6rg=20Deckert?= Date: Tue, 16 Mar 2021 19:20:27 +0100 Subject: [PATCH] default appliance: restore some config and users from theDATA volume --- appliances/default/Makefile | 2 +- appliances/default/default/01firstboot.start | 42 ++++++++++++++++++++ 2 files changed, 43 insertions(+), 1 deletion(-) diff --git a/appliances/default/Makefile b/appliances/default/Makefile index fe97ef4..154897b 100644 --- a/appliances/default/Makefile +++ b/appliances/default/Makefile @@ -39,7 +39,7 @@ $(PAM_SSH_AGENT_AUTH): touch $(PAM_SSH_AGENT_AUTH) $(ADMINUSER): - RUN useradd -m -G users,wheel -s /bin/bash --comment="virtual appliance admin" --uid 2000 admin + -RUN useradd -m -G users,wheel -s /bin/bash --comment="virtual appliance admin" --uid 2000 admin RUN passwd -d admin; $(inroot) passwd -e admin touch $(ADMINUSER) diff --git a/appliances/default/default/01firstboot.start b/appliances/default/default/01firstboot.start index c9d7ea7..eaf152e 100755 --- a/appliances/default/default/01firstboot.start +++ b/appliances/default/default/01firstboot.start @@ -33,4 +33,46 @@ if ! mount | grep /$LABEL > /dev/null; then exit 1 fi +if [ -d "/$LABEL/home" ]; then + cd "/$LABEL/home" + for user in *; do + if [ -d "$user" ]; then + if ! id -u "$user" >/dev/null 2>&1; then + useradd -m -G users,wheel -s /bin/bash --uid $(stat -c '%u' $user) --user-group $user + fi + rm -rf "/home/$user" + ln -nsf "/$LABEL/home/$user" "/home/$user" + fi + done +fi + +if [ -d "/$LABEL/etc/ssh" ]; then + rm -rf /etc/ssh + ln -nsf "/$LABEL/etc/ssh" /etc/ssh + systemctl restart sshd +else + mkdir -p "/$LABEL/etc" + mv /etc/ssh "/$LABEL/etc/" + ln -nsf "/$LABEL/etc/ssh" /etc/ssh +fi + +if [ -f "/$LABEL/etc/hosts" ]; then + rm -f /etc/hosts + ln -nsf "/$LABEL/etc/hosts" /etc/hosts +else + mkdir -p "/$LABEL/etc" + mv -f /etc/hosts "/$LABEL/etc/hosts" + cp -f "/$LABEL/etc/hosts" "/$LABEL/etc/hosts.orig" + ln -nsf "/$LABEL/etc/hosts" /etc/hosts +fi + +if [ -f "/$LABEL/etc/fstab" ]; then + cp -f "/$LABEL/etc/fstab" /etc/fstab +fi + +if [ -d "/$LABEL/etc/systemd" ]; then + cp -a "/$LABEL/etc/systemd" /etc/ + systemctl daemon-reload +fi + rm /01firstboot