Skip to content

Commit eb1a286

Browse files
authored
Merge pull request #55 from macmpi/dev
Version 1.5
2 parents 9872873 + 4b5f2b7 commit eb1a286

File tree

5 files changed

+43
-38
lines changed

5 files changed

+43
-38
lines changed

README.md

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,12 @@ As with Alpine Linux initial bring-up, `root` account has no password initially.
1919
From there, actual system install can be performed as usual with `setup-alpine` for instance (check Alpine [wiki](https://wiki.alpinelinux.org/wiki/Alpine_setup_scripts#setup-alpine) for details).
2020

2121
## Extra configuration:
22-
Extra files may be added next to `headless.apkovl.tar.gz` to customise boostrapping configuration (check sample files):
22+
Extra files may be added next to `headless.apkovl.tar.gz` to customise boostrapping configuration (check `sample_*` files):
2323
- `wpa_supplicant.conf`[^3] (*mandatory for wifi*): define wifi SSID, password and regulatory country [code](https://en.wikipedia.org/wiki/ISO_3166-1_alpha-2).
24-
- `unattended.sh`[^3] (*optional*): provide a deployment script to automate setup & customizations during initial bootstrap.
24+
- `unattended.sh`[^3] (*optional*): provide a deployment script to automate setup & customizations during initial bootstrap *(check users' contributed [samples](https://github.com/macmpi/alpine-linux-headless-bootstrap/discussions/categories/unattended-sh-samples) and share yours)*.
2525
- `interfaces`[^3] (*optional*): define network interfaces at will, if defaults DCHP-based are not suitable.
2626
- `authorized_keys` (*optional*): provide client's public SSH key to secure `root` ssh login.
27-
- `ssh_host_*_key*` (*optional*): provide server's custom ssh keys to be injected (may be stored), instead of using bundled ones[^4] (not stored). Providing an empty key file will trigger new keys generation (ssh server may take longer to start).
27+
- `ssh_host_*_key*` (*optional*): provide server's custom ssh keys to be injected (may be stored), instead of using temporarily bundled ones[^4] (not stored). Providing an empty key file will trigger new keys generation (ssh server may take longer to start).
2828
- `opt-out` (*optional*): dummy file to opt-out internet features (connection status, version check, auto-update) and related links usage anonymous [telemetry](https://is.gd/privacy.php).
2929
- `auto-updt` (*optional*): enable automatic `headless.apkovl.tar.gz` file update with latest from master branch. If it contains `reboot` keyword all in one line, system will reboot after succesful update (unless ssh session is active or `unattended.sh` script is available).
3030

@@ -36,25 +36,24 @@ Seamless USB-gadget mode on capable devices (*e.g. on PiZero*): serial console,
3636
(on supporting Pi devices, just add `dtoverlay=dwc2,dr_mode=peripheral` in `usercfg.txt` (or `config.txt`) to force both by software)
3737
- Plug USB cable into host Computer port before booting device.
3838
- serial terminal can then be connected-to from host Computer (e.g. `cu -l ttyACM0` on Linux. xon/xoff flow control).
39-
- alternatively, with host Computer ECM/RNDIS interface set-up as 10.42.0.1 (sharing internet or not), one can log into device from host with: `ssh [email protected]`.
39+
- alternatively, with host Computer ECM/RNDIS interface set-up as `10.42.0.1` (sharing internet or not), one can log into device from host with: `ssh [email protected]`.
4040
- volume containing `headless.apkovl.tar.gz` file may be accessed/mounted from host, and config files easily edited. Make sure to unmount properly before removing USB plug.
4141

4242
_Note:_ optionally, same USB-gadget feature may be easily enabled on final system by installing `xg_multi` Alpine [package](https://pkgs.alpinelinux.org/packages?name=xg_multi&branch=edge&repo=&arch=&origin=&flagged=&maintainer=) and service during system setup phase (refer to [`xg_multi`](https://github.com/macmpi/xg_multi/) project).
4343

44+
##
45+
[![ko-fi](https://www.ko-fi.com/img/githubbutton_sm.svg)](https://ko-fi.com/macmpi)
46+
4447
## Want to tweak more ?
4548
This repository may be forked/cloned/downloaded.\
4649
Main script file is [`headless_bootstrap`](https://github.com/macmpi/alpine-linux-headless-bootstrap/tree/main/overlay/tmp/.ALHB/headless_bootstrap).\
4750
Execute `./make_ALHB.sh` to rebuild `headless.apkovl.tar.gz` after changes.\
4851
(requires `busybox`; check `busybox` build options if not running from Alpine or Ubuntu)
4952

50-
5153
## Credits
5254
Thanks for the initial guides & scripts from @sodface and @davidmytton.
5355

5456
[^1]: Initial boot fully preserves system's original state (config files & installed packages): a fresh system will therefore come-up as unconfigured.
55-
5657
[^2]: Temporarily remove `root=*` statement from kernel command-line parameters list to disable disk-based boot mode.
57-
5858
[^3]: These files are linux text files: Windows/macOS users need to use text editors supporting linux text line-ending (such as [notepad++](https://notepad-plus-plus.org/), BBEdit or any similar).
59-
60-
[^4]: About bundled ssh keys: this overlay is meant to **quickly bootstrap** system in order to then proceed with proper install; therefore it purposely embeds [some ssh keys](https://github.com/macmpi/alpine-linux-headless-bootstrap/tree/main/overlay/tmp/.ALHB) so that bootstrapping is as fast as possible. Those temporary keys are moved in RAM /tmp: they will **not be stored/reused** once actual system install is performed (whether or not ssh server is installed in final setup).
59+
[^4]: About temporarily bundled ssh keys: this overlay is meant to **quickly bootstrap** system in order to then proceed with proper install; therefore it purposely embeds [some ssh keys](https://github.com/macmpi/alpine-linux-headless-bootstrap/tree/main/overlay/tmp/.ALHB) so that bootstrapping is as fast as possible. Those temporary keys are in RAM `/tmp`: they **are discarded** once actual system install is rebooted (whether or not ssh server is installed in final setup).

headless.apkovl.tar.gz

37 Bytes
Binary file not shown.

headless.apkovl.tar.gz.sha512

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
0e29b7d2488c97b144c39a76ca3c0793fbc96e18e6e1c1947896144c9ac38b16ace717208d639d23859d764703c2e7f6e41f7b269f78072b98ac8ce866f1c8a9 headless.apkovl.tar.gz
1+
3eb47a6f01bfe6ef6a26cd7a7494a8b673b6c745cc62c39633e140642ae32d906713a72c894dbe5290e0fd4f045512dd22811eb041e6d830b54ea40103532454 headless.apkovl.tar.gz

overlay/tmp/.ALHB/headless_bootstrap

Lines changed: 33 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
# SPDX-FileCopyrightText: Copyright 2022-2025, macmpi
44
# SPDX-License-Identifier: MIT
55

6-
ALHB_VERSION="1.4"
6+
ALHB_VERSION="1.5"
77

88
_apk() {
99
local cmd="$1"
@@ -70,21 +70,7 @@ cat <<-EOF >>/tmp/.ALHB/headless_cleanup
7070
rm -f /etc/runlevels/default/headless_bootstrap
7171
7272
# Run unattended script if available.
73-
if install -m755 ${ovlpath}/unattended.sh /tmp/headless_unattended >/dev/null 2>&1; then
74-
cat <<-EOF1 >/etc/init.d/headless_unattended
75-
#!/sbin/openrc-run
76-
77-
# SPDX-FileCopyrightText: Copyright 2022-2025, macmpi
78-
# SPDX-License-Identifier: MIT
79-
80-
description="Headless unattended setup script (optional)"
81-
name="Headless unattended"
82-
83-
command="/tmp/headless_unattended"
84-
command_background=true
85-
pidfile="/run/headless_unattended.pid"
86-
EOF1
87-
chmod +x /etc/init.d/headless_unattended
73+
if [ -f /tmp/headless_unattended ]; then
8874
_logger "Starting headless_unattended service"
8975
rc-service headless_unattended start
9076
fi
@@ -100,7 +86,6 @@ cat <<-EOF >>/tmp/.ALHB/headless_cleanup
10086
exit 0
10187
EOF
10288
chmod +x /tmp/.ALHB/headless_cleanup
103-
10489
cat <<-EOF >/etc/init.d/headless_cleanup
10590
#!/sbin/openrc-run
10691
@@ -115,6 +100,26 @@ cat <<-EOF >/etc/init.d/headless_cleanup
115100
pidfile="/run/headless_cleanup.pid"
116101
EOF
117102
chmod +x /etc/init.d/headless_cleanup
103+
104+
if install -m755 ${ovlpath}/unattended.sh /tmp/headless_unattended >/dev/null 2>&1; then
105+
cat <<-EOF >/etc/init.d/headless_unattended
106+
#!/sbin/openrc-run
107+
108+
# SPDX-FileCopyrightText: Copyright 2022-2025, macmpi
109+
# SPDX-License-Identifier: MIT
110+
111+
description="Headless unattended setup script (optional)"
112+
name="Headless unattended"
113+
114+
command="/tmp/headless_unattended"
115+
command_background=true
116+
pidfile="/run/headless_unattended.pid"
117+
EOF
118+
chmod +x /etc/init.d/headless_unattended
119+
fi
120+
121+
# force service dependency tree update
122+
rc-update --update
118123
}
119124

120125
_setup_sshd() {
@@ -190,9 +195,9 @@ _updt_apkovl() {
190195
# URL redirects to apkovl file on github master: is.gd shortener provides basic analytics.
191196
# Analytics are public and can be checked at https://is.gd/stats.php?url=apkovl_master
192197
# Privacy policy: https://is.gd/privacy.php
193-
local file_url="https://is.gd/apkovl_master"
194-
local sha_url="https://github.com/macmpi/alpine-linux-headless-bootstrap/raw/main/headless.apkovl.tar.gz.sha512"
195198
local updt_status="failed, keeping original version"
199+
local sha_url="https://github.com/macmpi/alpine-linux-headless-bootstrap/raw/main/headless.apkovl.tar.gz.sha512"
200+
local file_url="https://is.gd/apkovl_master"
196201

197202
# Ensure system date is correct to allow SSL transactions
198203
ntpd -N -p pool.ntp.org -n -q
@@ -216,7 +221,7 @@ else
216221
fi
217222
# Reboot if specified in auto-updt file (and no ssh session ongoing nor unattended.sh script available).
218223
! pgrep -a -P "$( cat /run/sshd.pid 2>/dev/null )" 2>/dev/null | grep -q "sshd: root@pts" && \
219-
! [ -f "${ovlpath}"/unattended.sh ] && \
224+
! [ -f /tmp/headless_unattended ] && \
220225
grep -q "^reboot$" "${ovlpath}"/auto-updt && \
221226
_logger "Will reboot in 3sec..." && sleep 3 && reboot
222227
exit 0
@@ -351,9 +356,6 @@ rc-service networking restart
351356
exec 1>/dev/console 2>&1
352357
_logger "Alpine Linux headless bootstrap v$ALHB_VERSION by macmpi"
353358

354-
# Help randomness for wpa_supplicant and sshd (urandom until 3.16).
355-
rc-service seedrng restart || rc-service urandom restart
356-
357359
# Determine ovl file location.
358360
# Grab used ovl filename from dmesg.
359361
ovl="$( dmesg | grep -o 'Loading user settings from .*:' | awk '{print $5}' | sed 's/:.*$//' )"
@@ -375,12 +377,17 @@ if [ -c /dev/ttyGS0 ]; then
375377
setconsole /dev/ttyGS0
376378
fi
377379

380+
_prep_cleanup
378381

379-
# Create banner file.
380-
warn=""
382+
# Help randomness for wpa_supplicant and sshd (urandom until 3.16).
383+
rc-service seedrng restart || rc-service urandom restart
384+
385+
# Detect apkovl volume ro/rw state
381386
grep -q "${ovlpath}.*[[:space:]]ro[[:space:],]" /proc/mounts; is_ro=$?
382387
_is_ro() { return "$is_ro"; }
383388

389+
# Create banner file.
390+
warn=""
384391
_is_ro && warn="(remount partition rw!)"
385392
cat <<-EOF >/tmp/.ALHB/banner
386393
@@ -400,10 +407,9 @@ _setup_networking
400407
[ -f "${ovlpath}"/opt-out ] || _tst_version &
401408

402409
# Setup sshd unless unattended.sh script prevents it.
403-
grep -q "^#NO_SSH$" "${ovlpath}"/unattended.sh >/dev/null 2>&1 \
410+
grep -q "^#NO_SSH$" /tmp/headless_unattended >/dev/null 2>&1 \
404411
|| _setup_sshd
405412

406-
_prep_cleanup
407413
_logger "Initial setup done, handing-over to clean-up"
408414
rc-service headless_cleanup start
409415
exit 0

0 commit comments

Comments
 (0)