aboutsummaryrefslogtreecommitdiffstats
path: root/main/openrc/firstboot.initd
diff options
context:
space:
mode:
authorTuan M. Hoang <tmhoang@flatglobe.org>2018-05-21 17:54:30 +0000
committerCarlo Landmeter <clandmeter@alpinelinux.org>2018-05-23 12:42:39 +0000
commit6534855ffe9c130d907c3dd653ab698e2dc0572a (patch)
tree15140f1c05922fdb9f0d3cb459e600fa3f56dac7 /main/openrc/firstboot.initd
parent1e7862203c56fafaeed4354339bcf8fc22bf1366 (diff)
downloadaports-6534855ffe9c130d907c3dd653ab698e2dc0572a.tar.bz2
aports-6534855ffe9c130d907c3dd653ab698e2dc0572a.tar.xz
main/openrc: add firstboot service for installation through SSH
Currently this service serves the purpose of allowing Alpine installation through SSH.
Diffstat (limited to 'main/openrc/firstboot.initd')
-rw-r--r--main/openrc/firstboot.initd44
1 files changed, 44 insertions, 0 deletions
diff --git a/main/openrc/firstboot.initd b/main/openrc/firstboot.initd
new file mode 100644
index 0000000000..cc888b351f
--- /dev/null
+++ b/main/openrc/firstboot.initd
@@ -0,0 +1,44 @@
+#!/sbin/openrc-run
+
+# The first boot init service
+
+# read kernel options
+init_KOPT() {
+ for opt in $(cat /proc/cmdline 2>/dev/null); do
+ case "$opt" in
+ ssh_*=*)
+ eval "KOPT_${opt%%=*}='${opt#*=}'" ;;
+ esac
+ done
+}
+
+depend() {
+ keyword -vserver -lxc
+ init_KOPT
+ [ -n "$KOPT_ssh_key" ] && need sshd
+ [ -n "$KOPT_ssh_pass" ] && use sshd
+}
+
+
+start() {
+ init_KOPT
+ local rc=0
+ ebegin "Starting ${RC_SVCNAME}"
+ if [ -n "$KOPT_ssh_key" ] && [ ! -f "/root/.ssh/authorized_keys" ]; then
+ einfo "Fetching ssh keys"
+ mkdir -pm 700 /root/.ssh
+ case "$KOPT_ssh_key" in
+ http://*|https://*|ftp://*|ftps://*)
+ wget -q "$KOPT_ssh_key" -O /root/.ssh/authorized_keys
+ rc=$?;;
+ *) echo "$KOPT_ssh_key" > /root/.ssh/authorized_keys;;
+ esac
+ chmod 600 /root/.ssh/authorized_keys
+ fi
+ if [ -n "$KOPT_ssh_pass" ]; then
+ echo "root:$KOPT_ssh_pass" | /usr/sbin/chpasswd
+ command_args="-o PermitRootLogin=yes" rc-service sshd start --quiet
+ fi
+ eend $rc
+}
+