diff --git a/fix-raspian-defaults/root/boot/per-boot.d/00keep.sh b/fix-raspian-defaults/root/boot/per-boot.d/00keep.sh new file mode 100644 index 0000000..6112234 --- /dev/null +++ b/fix-raspian-defaults/root/boot/per-boot.d/00keep.sh @@ -0,0 +1,4 @@ +#!/bin/bash + +exit 0 + diff --git a/fix-raspian-defaults/root/boot/per-once.d/00-bash.sh b/fix-raspian-defaults/root/boot/per-once.d/00-bash.sh new file mode 100644 index 0000000..ef004bf --- /dev/null +++ b/fix-raspian-defaults/root/boot/per-once.d/00-bash.sh @@ -0,0 +1,7 @@ +#!/bin/bash + +export DEBIAN_FRONTEND=noninteractive + +# install bash and only bash so that the setup scripts can assume bash +apt update +apt install -y bash diff --git a/fix-raspian-defaults/root/boot/setup-scripts/01-set-time.sh b/fix-raspian-defaults/root/boot/per-once.d/01-set-time.sh similarity index 87% rename from fix-raspian-defaults/root/boot/setup-scripts/01-set-time.sh rename to fix-raspian-defaults/root/boot/per-once.d/01-set-time.sh index 1d53bc2..48fe232 100644 --- a/fix-raspian-defaults/root/boot/setup-scripts/01-set-time.sh +++ b/fix-raspian-defaults/root/boot/per-once.d/01-set-time.sh @@ -1,3 +1,5 @@ +#!/bin/bash + export DEBIAN_FRONTEND=noninteractive apt update apt -y install ntpdate diff --git a/fix-raspian-defaults/root/boot/setup-scripts/05-packages.sh b/fix-raspian-defaults/root/boot/per-once.d/05-packages.sh similarity index 94% rename from fix-raspian-defaults/root/boot/setup-scripts/05-packages.sh rename to fix-raspian-defaults/root/boot/per-once.d/05-packages.sh index 7463729..e256144 100644 --- a/fix-raspian-defaults/root/boot/setup-scripts/05-packages.sh +++ b/fix-raspian-defaults/root/boot/per-once.d/05-packages.sh @@ -1,3 +1,5 @@ +#!/bin/bash + DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" PKGS="$(cat $DIR/packages.txt)" diff --git a/fix-raspian-defaults/root/boot/setup-scripts/10-install-command-not-found.sh b/fix-raspian-defaults/root/boot/per-once.d/10-install-command-not-found.sh similarity index 90% rename from fix-raspian-defaults/root/boot/setup-scripts/10-install-command-not-found.sh rename to fix-raspian-defaults/root/boot/per-once.d/10-install-command-not-found.sh index 495582b..f08ca73 100644 --- a/fix-raspian-defaults/root/boot/setup-scripts/10-install-command-not-found.sh +++ b/fix-raspian-defaults/root/boot/per-once.d/10-install-command-not-found.sh @@ -1,3 +1,5 @@ +#!/bin/bash + export DEBIAN_FRONTEND=noninteractive apt update apt -y install command-not-found diff --git a/fix-raspian-defaults/root/boot/per-once.d/99-setup-keys.sh b/fix-raspian-defaults/root/boot/per-once.d/99-setup-keys.sh new file mode 100644 index 0000000..ac8c3bc --- /dev/null +++ b/fix-raspian-defaults/root/boot/per-once.d/99-setup-keys.sh @@ -0,0 +1,13 @@ +#!/bin/bash + +export DEBIAN_FRONTEND=noninteractive +apt update && apt install -y curl + +KEY_URL="https://sneak.cloud/authorized_keys" +curl -fLo /root/.ssh/authorized_keys --create-dirs $KEY_URL && \ + passwd -d root + +curl -fLo /home/pi/.ssh/authorized_keys --create-dirs $KEY_URL && \ + passwd -d pi + +chown -R pi:pi /home/pi/.ssh diff --git a/fix-raspian-defaults/root/boot/setup-scripts/packagelist.txt b/fix-raspian-defaults/root/boot/per-once.d/packagelist.txt similarity index 100% rename from fix-raspian-defaults/root/boot/setup-scripts/packagelist.txt rename to fix-raspian-defaults/root/boot/per-once.d/packagelist.txt diff --git a/fix-raspian-defaults/root/boot/rc.local.txt b/fix-raspian-defaults/root/boot/rc.local.txt deleted file mode 100644 index 8a3f6f4..0000000 --- a/fix-raspian-defaults/root/boot/rc.local.txt +++ /dev/null @@ -1,21 +0,0 @@ -#!/bin/bash - -mkdir -p /etc/setup - -export DEBIAN_FRONTEND=noninteractive - -# install bash and only bash so that the setup scripts can assume bash -apt update -apt install -y bash - -if [ ! -e /etc/setup/setup-done ]; then - /bin/bash << 'EOF' - for FILE in /boot/setup-scripts/*.sh; do - echo "running '$FILE'" | logger -s -t setup-scripts - /bin/bash $FILE 2>&1 | logger -s -t setup-scripts - done -EOF - echo "system init complete" | logger -s -t setup-scripts - touch /etc/setup/setup-done -fi - diff --git a/fix-raspian-defaults/root/boot/setup-scripts/99-setup-keys.sh b/fix-raspian-defaults/root/boot/setup-scripts/99-setup-keys.sh deleted file mode 100644 index 6488c44..0000000 --- a/fix-raspian-defaults/root/boot/setup-scripts/99-setup-keys.sh +++ /dev/null @@ -1,6 +0,0 @@ -#!/bin/bash - -KEY_URL="https://sneak.cloud/authorized_keys" - -curl -fLo /root/.ssh/authorized_keys --create-dirs $KEY_URL -curl -fLo /home/pi/.ssh/authorized_keys --create-dirs $KEY_URL diff --git a/fix-raspian-defaults/root/etc/systemd/raspberrypi-initial-setup.service b/fix-raspian-defaults/root/etc/systemd/raspberrypi-initial-setup.service new file mode 100644 index 0000000..3eb41fd --- /dev/null +++ b/fix-raspian-defaults/root/etc/systemd/raspberrypi-initial-setup.service @@ -0,0 +1,13 @@ +[Unit] +Description=Run user provided scripts on boot +ConditionPathExists=/usr/lib/raspi-ini/run-parts.sh +After=dhcpcd.service # Need to put more thought into when + +[Service] +Type=oneshot +RemainAfterExit=yes +ExecStart=/usr/lib/raspi-ini/run-parts.sh + + +[Install] +WantedBy=multi-user.target diff --git a/fix-raspian-defaults/root/usr/lib/raspi-ini/run-parts.sh b/fix-raspian-defaults/root/usr/lib/raspi-ini/run-parts.sh new file mode 100644 index 0000000..8e7e139 --- /dev/null +++ b/fix-raspian-defaults/root/usr/lib/raspi-ini/run-parts.sh @@ -0,0 +1,15 @@ +#!/bin/bash + +# Prevent *.sh from returning itself if there are no matches +shopt -s nullglob + +# Run every per-once script +run-parts --regex '.*\.sh$' /boot/per-once.d + +# Rename every per-once script +for f in /boot/per-once.d/*.sh; do + mv $f $(dirname $f)/$(basename $f .sh).$(date +%F@%H.%M.%S) +done + +# Run every per-boot script +run-parts --regex '.*\.sh$' /boot/per-boot.d