2023-11-13 20:34:28 +00:00
|
|
|
#!/bin/sh
|
2022-07-09 12:34:58 +00:00
|
|
|
|
2023-11-13 20:34:28 +00:00
|
|
|
# SPDX-FileCopyrightText: Copyright 2022-2023, macmpi
|
2023-05-12 12:04:05 +00:00
|
|
|
# SPDX-License-Identifier: MIT
|
|
|
|
|
2023-05-11 17:51:45 +00:00
|
|
|
## collection of few code snippets as sample unnatteded actions some may find usefull
|
|
|
|
|
2023-11-13 20:34:28 +00:00
|
|
|
## will run encapusated within headless_unattended OpenRC service
|
2023-05-11 17:51:45 +00:00
|
|
|
|
2023-11-13 20:34:28 +00:00
|
|
|
# To prevent headless bootstrap script from starting sshd
|
|
|
|
# only keep a single starting # on the line below
|
|
|
|
##NO_SSH
|
|
|
|
|
|
|
|
# Uncomment to enable stdout and errors redirection to console (service won't show messages)
|
|
|
|
# exec 1>/dev/console 2>&1
|
2023-05-11 17:51:45 +00:00
|
|
|
|
2023-11-13 20:34:28 +00:00
|
|
|
# shellcheck disable=SC2142 # known special case
|
|
|
|
alias _logger='logger -st "${0##*/}"'
|
|
|
|
|
|
|
|
## Obvious one; reminder: is run as background service
|
|
|
|
_logger "hello world !!"
|
|
|
|
sleep 60
|
|
|
|
_logger "Finished script"
|
2023-05-11 17:51:45 +00:00
|
|
|
########################################################
|
|
|
|
|
|
|
|
|
|
|
|
## This snippet removes apkovl file on volume after initial boot
|
2023-09-20 08:54:22 +00:00
|
|
|
# grab used ovl filename from dmesg
|
2023-05-16 07:28:58 +00:00
|
|
|
ovl="$( dmesg | grep -o 'Loading user settings from .*:' | awk '{print $5}' | sed 's/:.*$//' )"
|
2023-11-13 20:34:28 +00:00
|
|
|
if [ -f "${ovl}" ]; then
|
|
|
|
ovlpath="$( dirname "$ovl" )"
|
|
|
|
else
|
|
|
|
# search path again as mountpoint have been changed later in the boot process...
|
|
|
|
ovl="$( basename "${ovl}" )"
|
|
|
|
ovlpath=$( find /media -maxdepth 2 -type d -path '*/.*' -prune -o -type f -name "${ovl}" -exec dirname {} \; | head -1 )
|
|
|
|
ovl="${ovlpath}/${ovl}"
|
|
|
|
fi
|
2023-05-11 17:51:45 +00:00
|
|
|
|
|
|
|
# also works in case volume is mounted read-only
|
2023-11-23 21:13:27 +00:00
|
|
|
grep -q "${ovlpath}.*[[:space:]]ro[[:space:],]" /proc/mounts; is_ro=$?
|
|
|
|
_is_ro() { return "$is_ro"; }
|
|
|
|
_is_ro && mount -o remount,rw "${ovlpath}"
|
2023-11-13 20:34:28 +00:00
|
|
|
rm -f "${ovl}"
|
2023-11-23 21:13:27 +00:00
|
|
|
_is_ro && mount -o remount,ro "${ovlpath}"
|
2023-05-11 17:51:45 +00:00
|
|
|
|
|
|
|
########################################################
|
|
|
|
|
|
|
|
|
|
|
|
## This snippet configures Minimal diskless environment
|
|
|
|
# note: with INTERFACESOPTS=none, no networking will be setup so it won't work after reboot!
|
|
|
|
# Change it or run setup-interfaces in interractive mode afterwards (and lbu commit -d thenafter)
|
|
|
|
|
2023-11-13 20:34:28 +00:00
|
|
|
_logger "Setting-up minimal environment"
|
2023-05-11 17:51:45 +00:00
|
|
|
|
|
|
|
cat <<-EOF > /tmp/ANSWERFILE
|
|
|
|
# base answer file for setup-alpine script
|
|
|
|
|
|
|
|
# Do not set keyboard layout
|
|
|
|
KEYMAPOPTS=none
|
|
|
|
|
|
|
|
# Keep hostname
|
|
|
|
HOSTNAMEOPTS="$(hostname)"
|
|
|
|
|
|
|
|
# Set device manager to mdev
|
|
|
|
DEVDOPTS=mdev
|
|
|
|
|
|
|
|
# Contents of /etc/network/interfaces
|
|
|
|
INTERFACESOPTS=none
|
|
|
|
|
|
|
|
# Set Public nameserver
|
|
|
|
DNSOPTS="-n 208.67.222.222"
|
|
|
|
|
|
|
|
# Set timezone to UTC
|
|
|
|
TIMEZONEOPTS="UTC"
|
|
|
|
|
|
|
|
# set http/ftp proxy
|
|
|
|
PROXYOPTS=none
|
|
|
|
|
|
|
|
# Add first mirror (CDN)
|
|
|
|
APKREPOSOPTS="-1"
|
|
|
|
|
|
|
|
# Do not create any user
|
|
|
|
USEROPTS=none
|
|
|
|
|
|
|
|
# No Openssh
|
|
|
|
SSHDOPTS=none
|
|
|
|
|
|
|
|
# Use openntpd
|
|
|
|
NTPOPTS="chrony"
|
|
|
|
|
|
|
|
# No disk install (diskless)
|
|
|
|
DISKOPTS=none
|
|
|
|
|
|
|
|
# Setup storage for diskless (find boot directory in /media/xxxx/apk/.boot_repository)
|
|
|
|
LBUOPTS="$( find /media -maxdepth 3 -type d -path '*/.*' -prune -o -type f -name '.boot_repository' -exec dirname {} \; | head -1 | xargs dirname )"
|
|
|
|
APKCACHEOPTS="\$LBUOPTS/cache"
|
|
|
|
|
|
|
|
EOF
|
|
|
|
|
|
|
|
# trick setup-alpine to pretend existing SSH connection
|
|
|
|
# and therefore keep (do not reset) network interfaces while running in background
|
2023-11-17 09:08:04 +00:00
|
|
|
# requires alpine-conf 3.15.1 and later, available from Alpine 3.17
|
2023-05-11 17:51:45 +00:00
|
|
|
SSH_CONNECTION="FAKE" setup-alpine -ef /tmp/ANSWERFILE
|
|
|
|
lbu commit -d
|
|
|
|
|
|
|
|
########################################################
|
|
|
|
|
|
|
|
|
2023-11-13 20:34:28 +00:00
|
|
|
_logger "Finished unattended script"
|
2022-07-09 12:34:58 +00:00
|
|
|
|