|
| 1 | +#!/bin/sh |
| 2 | +# This has been tested on a Milkv duo s. |
| 3 | +# See https://milkv.io/duo-s |
| 4 | +# This is a single user image, so you'll need to |
| 5 | +# put the pub key in /etc/cpud/. |
| 6 | +# |
| 7 | +# Starts cpud sshd. |
| 8 | +# |
| 9 | + |
| 10 | +# Allow a few customizations from a config file |
| 11 | +test -r /etc/default/cpud && . /etc/default/cpud |
| 12 | + |
| 13 | +start() { |
| 14 | + CPUD_ARGS="$CPUD_ARGS -pk /etc/cpud/cpu_rsa.pub" |
| 15 | + |
| 16 | + # If /etc/cpud is a symlink to /var/run/cpud, and |
| 17 | + # - the filesystem is RO (i.e. we can not rm the symlink), |
| 18 | + # create the directory pointed to by the symlink. |
| 19 | + # - the filesystem is RW (i.e. we can rm the symlink), |
| 20 | + # replace the symlink with an actual directory |
| 21 | + if [ -L /etc/cpud \ |
| 22 | + -a "$(readlink /etc/cpud)" = "/var/run/cpud" ] |
| 23 | + then |
| 24 | + if rm -f /etc/cpud >/dev/null 2>&1; then |
| 25 | + mkdir -p /etc/cpud |
| 26 | + else |
| 27 | + echo "No persistent location to store SSH host keys. New keys will be" |
| 28 | + echo "generated at each boot. Are you sure this is what you want to do?" |
| 29 | + mkdir -p "$(readlink /etc/cpud)" |
| 30 | + fi |
| 31 | + fi |
| 32 | + |
| 33 | + printf "Starting cpud: " |
| 34 | + umask 077 |
| 35 | + |
| 36 | + start-stop-daemon -S -q -p /var/run/cpud.pid \ |
| 37 | + --exec /usr/sbin/cpud -- $CPUD_ARGS & |
| 38 | + [ $? = 0 ] && echo "OK" || echo "FAIL" |
| 39 | +} |
| 40 | +stop() { |
| 41 | + printf "Stopping cpud: " |
| 42 | + start-stop-daemon -K -q -p /var/run/cpud.pid |
| 43 | + [ $? = 0 ] && echo "OK" || echo "FAIL" |
| 44 | +} |
| 45 | +restart() { |
| 46 | + stop |
| 47 | + start |
| 48 | +} |
| 49 | + |
| 50 | +case "$1" in |
| 51 | + start) |
| 52 | + start |
| 53 | + ;; |
| 54 | + stop) |
| 55 | + stop |
| 56 | + ;; |
| 57 | + restart|reload) |
| 58 | + restart |
| 59 | + ;; |
| 60 | + *) |
| 61 | + echo "Usage: $0 {start|stop|restart}" |
| 62 | + exit 1 |
| 63 | +esac |
| 64 | + |
| 65 | +exit $? |
0 commit comments