From 7ff51403c3f15a5d233bdfb27b3f7c380bcd0392 Mon Sep 17 00:00:00 2001
From: Christian Heller <c.heller@plomlompom.de>
Date: Fri, 25 Oct 2024 01:00:51 +0200
Subject: [PATCH] Update Raspi setup.

---
 constants.sh                                | 19 +++++++++--
 many_releases/home/{minimal => all}/.bashrc |  0
 testing/scripts/constants.sh                |  3 --
 testing/scripts/setup_raspi.sh              | 36 ++++++++++++---------
 4 files changed, 37 insertions(+), 21 deletions(-)
 rename many_releases/home/{minimal => all}/.bashrc (100%)
 delete mode 100755 testing/scripts/constants.sh

diff --git a/constants.sh b/constants.sh
index be2789a..015b654 100755
--- a/constants.sh
+++ b/constants.sh
@@ -1,6 +1,19 @@
 #!/bin/sh
-PATH_REPO="${HOME}/config"
+set -e
+PATH_REL_ETC="/etc"
+PATH_REL_APTMARK="/aptmark"
+PATH_REL_REPO="/config"
+PATH_REPO="${HOME}${PATH_REL_REPO}"
 PATH_MANY="${PATH_REPO}/many_releases"
 PATH_MANY_MISC="${PATH_MANY}/scripts/_misc.sh"
-NAME_ETC_DIR="etc"
-NAME_APTMARK_DIR="aptmark"
+
+USERNAME="plom"
+PATH_USER_HOME="/home/${USERNAME}"
+
+FILENAME_PUBLIC_KEY='id_rsa.pub'
+URL_PUBLIC_KEY="https://dump.plomlompom.com/dump/${FILENAME_PUBLIC_KEY}"
+PATH_REL_LOCAL_SSH="/.ssh"
+PATH_REL_AUTHORIZED_KEYS="${PATH_REL_LOCAL_SSH}/authorized_keys"
+PATH_AUTHORIZED_KEYS="${HOME}${PATH_REL_AUTHORIZED_KEYS}"
+PATH_USER_SSH="${PATH_USER_HOME}${PATH_REL_LOCAL_SSH}"
+
diff --git a/many_releases/home/minimal/.bashrc b/many_releases/home/all/.bashrc
similarity index 100%
rename from many_releases/home/minimal/.bashrc
rename to many_releases/home/all/.bashrc
diff --git a/testing/scripts/constants.sh b/testing/scripts/constants.sh
deleted file mode 100755
index 3aa951c..0000000
--- a/testing/scripts/constants.sh
+++ /dev/null
@@ -1,3 +0,0 @@
-#!/bin/sh
-set -e
-. ../../constants.sh
diff --git a/testing/scripts/setup_raspi.sh b/testing/scripts/setup_raspi.sh
index e0966c6..75c625f 100755
--- a/testing/scripts/setup_raspi.sh
+++ b/testing/scripts/setup_raspi.sh
@@ -1,45 +1,51 @@
 #!/bin/sh 
 set -e
-. ./constants.sh
+. ./../constants.sh
 . "${PATH_MANY_MISC}"
 
 # ensure we can log in
-FILENAME_PUBLIC_KEY='id_rsa.pub'
-URL_PUBLIC_KEY="https://dump.plomlompom.com/dump/${FILENAME_PUBLIC_KEY}"
+# (alternatively, or preceding this to reduce non-remote typing, TEMPORARILY
+# (!) set password login:)
+# passwd
+# echo 'PermitRootLogin yes' >> /etc/ssh/sshd_config
 apt update
 apt -y install wget
 wget "${URL_PUBLIC_KEY}"
-cat "${FILENAME_PUBLIC_KEY}" >> ~/.ssh/authorized_keys
+cat "${FILENAME_PUBLIC_KEY}" >> "${PATH_AUTHORIZED_KEYS}"
 rm "${FILENAME_PUBLIC_KEY}" 
-# service sshd restart
 
 upgrade_from_older_release
 
 # properly apt system
 for root in "${PATH_MANY}" '..'; do
-    copy_dirtree "${root}/${NAME_ETC_DIR}" "" all raspi
+    copy_dirtree "${root}${PATH_REL_ETC}" "" all raspi
 done
 apt update
 mark_nonrequireds_auto
 for root in "${PATH_MANY}" '..'; do
-    install_for_modules "${root}/${NAME_APTMARK_DIR}" all raspi
+    install_for_modules "${root}${PATH_REL_APTMARK}" all raspi
 done
 apt -y --purge autoremove
 
 # TODO test if isc-dhcp-client necessary (ifupdown certainly is)
 
 # Ensure our desired locale is available.
-# locale-gen
+locale-gen
 
 # Set Berlin localtime.
-# ln -sf /usr/share/zoneinfo/Europe/Berlin /etc/localtime
+ln -sf /usr/share/zoneinfo/Europe/Berlin /etc/localtime
 
 # Set up users and their environments.
 for root in "${PATH_MANY}" '..'; do
-    copy_dirtree "${root}/${NAME_HOME_DIR}" '/root' minimal root
+    copy_dirtree "${root}/${NAME_HOME_DIR}" '/root' all root
 done
-adduser --disabled-password --gecos "" plom
-usermod -a -G sudo plom
-passwd plom
-cp -a ~/config /home/plom
-chown -R plom:plom /home/plom/config
+adduser --disabled-password --gecos "" "${USERNAME}" 
+usermod -a -G sudo "${USERNAME}" 
+cp -a "${PATH_REPO}" "${PATH_USER_HOME}" 
+mkdir "${PATH_USER_SSH}"
+cp "${PATH_AUTHORIZED_KEYS}" "${PATH_USER_SSH}"
+for path in "${PATH_USER_HOME}${PATH_REL_REPO}" "${PATH_USER_SSH}"; do
+    chown -R "${USERNAME}:${USERNAME}" "${path}"
+done
+passwd "${USERNAME}" 
+rm "${PATH_AUTHORIZED_KEYS}"
-- 
2.30.2