#!/bin/sh # # Read configuration files from SD card. # . /opt/puzzlefw/lib/functions.sh # Copy root password from configuration partition. copy_passwd() { # Do nothing if there is no password on the configuration partition. [ -f ${CONFIG_DIR}/passwd.conf ] || return # Do nothing if there is no root password entry in the config file. grep "^root:" ${CONFIG_DIR}/passwd.conf > /etc/shadow.new || return grep -v "^root:" /etc/shadow >> /etc/shadow.new chmod 0600 /etc/shadow.new mv /etc/shadow.new /etc/shadow } # Copy SSH host key from configuration partition. copy_ssh_host_key() { # If host key exists, do nothing. [ -f /etc/dropbear/dropbear_ed25519_host_key ] && return # If /etc/dropbear is a symlink, delete it. [ -L /etc/dropbear ] && rm /etc/dropbear # Create directory /etc/dropbear if it does not exist. mkdir -p /etc/dropbear # Try to copy SSH host key from configuration files. if ! cp -p ${CONFIG_DIR}/dropbear_ed25519_host_key /etc/dropbear ; then echo "WARNING: Failed to load SSH host key from SD card" >&2 fi chmod 0600 /etc/dropbear/dropbear_ed25519_host_key || true } # Take NTP server from configuration partition. copy_ntp_server() { # If an NTP server is configured, copy it to Chrony configuration. if [ -s ${CONFIG_DIR}/ntp.sources ]; then mkdir -p /etc/chrony/sources.d cp -p ${CONFIG_DIR}/ntp.sources /etc/chrony/sources.d fi } case "$1" in start) echo "Reading configuration files from SD card ..." lock_config || exit 1 read_config || exit 1 copy_passwd copy_ssh_host_key copy_ntp_server ;; stop|restart|reload) true ;; *) echo "Usage: $0 start" exit 1 esac