Skip to content

Commit df2da47

Browse files
authored
Merge pull request #69 from macmpi/dev
Version 1.8
2 parents f09d084 + 376d421 commit df2da47

10 files changed

Lines changed: 186 additions & 137 deletions

README.md

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ Extra files may be added next to `headless.apkovl.tar.gz` to customise boostrapp
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

31-
Main execution steps are logged: `cat /var/log/messages | grep headless`.\
31+
Main execution steps are logged: `grep headless /var/log/messages`.\
3232
For more details: `cat /tmp/alhb.log`.
3333

3434
## Seamless USB-gadget mode:
@@ -48,7 +48,6 @@ _Note:_ optionally, same USB-gadget feature may be easily enabled on final syste
4848
<a href='https://ko-fi.com/V7V81B2UF6' target='_blank'><img height='36' style='border:0px;height:36px;' src='https://storage.ko-fi.com/cdn/kofi5.png?v=6' border='0' alt='Buy Me a Coffee at ko-fi.com' /></a>
4949

5050
## Want to tweak more ?
51-
This repository may be forked/cloned/downloaded.\
5251
Main script file is [`headless_bootstrap`](https://github.com/macmpi/alpine-linux-headless-bootstrap/tree/main/overlay/tmp/.ALHB/headless_bootstrap).\
5352
Execute `./make_ALHB.sh` to rebuild `headless.apkovl.tar.gz` after changes.\
5453
(requires `busybox`; check `busybox` build options if not running from Alpine or Ubuntu)

contribs/unattended.sh

Lines changed: 0 additions & 108 deletions
This file was deleted.

contribs/unattended_diskless.sh

Lines changed: 97 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
1+
#!/bin/sh
2+
3+
# SPDX-FileCopyrightText: Copyright 2025-2026, macmpi
4+
# SPDX-License-Identifier: MIT
5+
6+
## Install minimal diskless Alpine with customizable install STEPS on media containing headless.apkovl file.
7+
8+
# HOW TO USE (Customize MY_xxxx values and STEPS to your needs. Defaults are ok for Pi)
9+
# - prepare install media (Alpine 3.23 and later) as per Alpine wiki for your target hardware
10+
# - add headless.apkovl.tar.gz, this file (as unattended.sh) and wpa_supplicant.conf (if wifi) onto media
11+
# - boot machine, and let unattended install proceed & reboot (may be observed via root ssh login)
12+
# - after reboot, log-in as admin user via ssh (WARNING change default password in MY_PASS)
13+
14+
## CUSTOMIZE values below to your needs
15+
MY_USER="alpine" # admin account user name
16+
MY_PASS="enipla" # password for that user
17+
MY_IFACE="wlan0" # network interface to be used; may be eth0, etc...(DHCP by default)
18+
MY_HOSTNAME="alpine-diskless"
19+
20+
# Uncomment to redirect stdout and errors to logfile as service won't show messages
21+
# exec 1>>/tmp/alhb.log 2>&1
22+
23+
# shellcheck disable=SC2142 # known special case
24+
alias _logger='logger -st "${0##*/}"'
25+
26+
# grab used ovl filename from dmesg
27+
ovl="$( dmesg | grep -o 'Loading user settings from .*:' | awk '{print $5}' | sed 's/:.*$//' )"
28+
if [ -f "${ovl}" ]; then
29+
ovlpath="$( dirname "$ovl" )"
30+
else
31+
# search path again as mountpoint have been changed later in the boot process...
32+
ovl="$( basename "${ovl}" )"
33+
ovlpath=$( find /media -maxdepth 2 -type d -path '*/.*' -prune -o -type f -name "${ovl}" -exec dirname {} \; | head -1 )
34+
ovl="${ovlpath}/${ovl}"
35+
fi
36+
37+
_logger "Starting base diskless installation"
38+
cat <<-EOF > /tmp/ANSWERFILE
39+
KEYMAPOPTS=none
40+
HOSTNAMEOPTS="$MY_HOSTNAME"
41+
DEVDOPTS=mdev
42+
INTERFACESOPTS="auto lo
43+
iface lo inet loopback
44+
45+
auto $MY_IFACE
46+
iface $MY_IFACE inet dhcp
47+
"
48+
DNSOPTS=""
49+
TIMEZONEOPTS=UTC
50+
PROXYOPTS=none
51+
APKREPOSOPTS="-1 -c"
52+
USEROPTS="-a -u $MY_USER"
53+
SSHDOPTS=openssh
54+
NTPOPTS=chrony
55+
56+
# No disk install (diskless)
57+
DISKOPTS=none
58+
59+
# Setup storage for diskless: use media where headless overlay is located
60+
LBUOPTS="$ovlpath"
61+
APKCACHEOPTS="\$LBUOPTS/cache"
62+
63+
EOF
64+
65+
SSH_CONNECTION="FAKE" setup-alpine -ef /tmp/ANSWERFILE
66+
67+
if install -m644 "${ovlpath}"/interfaces /etc/network/interfaces >/dev/null 2>&1; then
68+
_logger "Imported interfaces file"
69+
fi
70+
71+
# Setup wifi if available
72+
if [ -e "$ovlpath/wpa_supplicant.conf" ]; then
73+
apk add wpa_supplicant
74+
install -m644 "$ovlpath/wpa_supplicant.conf" /etc/wpa_supplicant/wpa_supplicant.conf
75+
rc-update add wpa_supplicant boot
76+
_logger "Wifi configured with imported wpa_supplicant.conf"
77+
fi
78+
79+
# Provision sshd authorized keys (host keys imported by default) if available
80+
if install -Dm600 "${ovlpath}"/authorized_keys /home/"$MY_USER"/.ssh/authorized_keys >/dev/null 2>&1; then
81+
_logger "Imported public key SSH for authentication."
82+
chown -R "$MY_USER" /home/"$MY_USER"/.ssh
83+
fi
84+
85+
## CUSTOMIZE following install STEPS
86+
_logger "Install customizations"
87+
echo "$MY_USER:$MY_PASS" | chpasswd
88+
passwd -l root
89+
90+
apk update
91+
apk upgrade --available
92+
93+
lbu commit -d
94+
sync
95+
_logger "Finished unattended script - rebooting system"
96+
reboot
97+

contribs/unattended_home-assistant.sh

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -57,14 +57,6 @@ else
5757
ovl="${ovlpath}/${ovl}"
5858
fi
5959

60-
# Setup wifi if available
61-
if [ -e "$ovlpath/wpa_supplicant.conf" ]; then
62-
apk add wpa_supplicant
63-
cp "$ovlpath/wpa_supplicant.conf" /etc/wpa_supplicant/wpa_supplicant.conf
64-
rc-update add wpa_supplicant boot
65-
_logger "Wifi configured"
66-
fi
67-
6860
_logger "Starting base sys-disk installation"
6961
cat <<-EOF > /tmp/ANSWERFILE
7062
KEYMAPOPTS=none
@@ -91,6 +83,24 @@ cat <<-EOF > /tmp/ANSWERFILE
9183

9284
SSH_CONNECTION="FAKE" setup-alpine -ef /tmp/ANSWERFILE
9385

86+
if install -m644 "${ovlpath}"/interfaces /etc/network/interfaces >/dev/null 2>&1; then
87+
_logger "Imported interfaces file"
88+
fi
89+
90+
# Setup wifi if available
91+
if [ -e "$ovlpath/wpa_supplicant.conf" ]; then
92+
apk add wpa_supplicant
93+
install -m644 "$ovlpath/wpa_supplicant.conf" /etc/wpa_supplicant/wpa_supplicant.conf
94+
rc-update add wpa_supplicant boot
95+
_logger "Wifi configured with imported wpa_supplicant.conf"
96+
fi
97+
98+
# Provision sshd authorized keys (host keys imported by default) if available
99+
if install -Dm600 "${ovlpath}"/authorized_keys /home/"$MY_USER"/.ssh/authorized_keys >/dev/null 2>&1; then
100+
_logger "Imported public key SSH for authentication."
101+
chown -R "$MY_USER" /home/"$MY_USER"/.ssh
102+
fi
103+
94104
# Prep install script for destination sys-based system
95105
_logger "Prepare sys-setup script"
96106
cat <<-EOF1 >/tmp/setup_homeassistant.sh
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
#!/bin/sh
2+
3+
# SPDX-FileCopyrightText: Copyright 2022-2026, macmpi
4+
# SPDX-License-Identifier: MIT
5+
6+
## collection of few code snippets as sample unnatteded actions some may find usefull
7+
8+
## will run encapusated within headless_unattended OpenRC service
9+
10+
# To prevent headless bootstrap script from starting sshd
11+
# only keep a single starting # on the line below
12+
##NO_SSH
13+
14+
# Uncomment to redirect stdout and errors to logfile as service won't show messages
15+
# exec 1>>/tmp/alhb.log 2>&1
16+
17+
# shellcheck disable=SC2142 # known special case
18+
alias _logger='logger -st "${0##*/}"'
19+
20+
21+
## This snippet removes apkovl file on volume after initial boot
22+
# grab used ovl filename from dmesg
23+
ovl="$( dmesg | grep -o 'Loading user settings from .*:' | awk '{print $5}' | sed 's/:.*$//' )"
24+
if [ -f "${ovl}" ]; then
25+
ovlpath="$( dirname "$ovl" )"
26+
else
27+
# search path again as mountpoint have been changed later in the boot process...
28+
ovl="$( basename "${ovl}" )"
29+
ovlpath=$( find /media -maxdepth 2 -type d -path '*/.*' -prune -o -type f -name "${ovl}" -exec dirname {} \; | head -1 )
30+
ovl="${ovlpath}/${ovl}"
31+
fi
32+
33+
# also works in case volume is mounted read-only
34+
grep -q "${ovlpath}.*[[:space:]]ro[[:space:],]" /proc/mounts; is_ro=$?
35+
_is_ro() { return "$is_ro"; }
36+
_is_ro && mount -o remount,rw "${ovlpath}"
37+
rm -f "${ovl}"
38+
_is_ro && mount -o remount,ro "${ovlpath}"
39+
40+
_logger "Finished unattended script"
41+

contribs/unattended_sysdisk.sh

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -38,14 +38,6 @@ else
3838
ovl="${ovlpath}/${ovl}"
3939
fi
4040

41-
# Setup wifi if available
42-
if [ -e "$ovlpath/wpa_supplicant.conf" ]; then
43-
apk add wpa_supplicant
44-
cp "$ovlpath/wpa_supplicant.conf" /etc/wpa_supplicant/wpa_supplicant.conf
45-
rc-update add wpa_supplicant boot
46-
_logger "Wifi configured"
47-
fi
48-
4941
_logger "Starting base sys-disk installation"
5042
cat <<-EOF > /tmp/ANSWERFILE
5143
KEYMAPOPTS=none
@@ -72,6 +64,24 @@ cat <<-EOF > /tmp/ANSWERFILE
7264

7365
SSH_CONNECTION="FAKE" setup-alpine -ef /tmp/ANSWERFILE
7466

67+
if install -m644 "${ovlpath}"/interfaces /etc/network/interfaces >/dev/null 2>&1; then
68+
_logger "Imported interfaces file"
69+
fi
70+
71+
# Setup wifi if available
72+
if [ -e "$ovlpath/wpa_supplicant.conf" ]; then
73+
apk add wpa_supplicant
74+
install -m644 "$ovlpath/wpa_supplicant.conf" /etc/wpa_supplicant/wpa_supplicant.conf
75+
rc-update add wpa_supplicant boot
76+
_logger "Wifi configured with imported wpa_supplicant.conf"
77+
fi
78+
79+
# Provision sshd authorized keys (host keys imported by default) if available
80+
if install -Dm600 "${ovlpath}"/authorized_keys /home/"$MY_USER"/.ssh/authorized_keys >/dev/null 2>&1; then
81+
_logger "Imported public key SSH for authentication."
82+
chown -R "$MY_USER" /home/"$MY_USER"/.ssh
83+
fi
84+
7585
# Prep install script for destination sys-based system
7686
_logger "Prepare sys-setup script"
7787
cat <<-EOF >/tmp/sys-setup.sh

headless.apkovl.tar.gz

49 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-
7f7e3a07ff731e56bcf710853575e5ae246be18040d7788f69f157ca0f9cd21ee803c03df481e535149904021f0db6aebd5a6107fe94f9944b146e5cf4e32202 headless.apkovl.tar.gz
1+
e45b869efe3ae1c2904691e1ec7a272a8dee61c1d1f6634beb4d8fa56e836bda9a89dbfd0b97de14c53a26ddc556635495c4e5446e8dea22aadd2d92e3e44d96 headless.apkovl.tar.gz

0 commit comments

Comments
 (0)