#!/bin/sh PATH=/sbin:/bin:/usr/sbin:/usr/bin DAEMON=/usr/sbin/lighttpd DAEMONNAME="lighttpd" NAME=commission DESC="MT lighttpd Commissioning Server" OPTS="-f /etc/lighttpd-commission.conf" PIDFILE=/var/run/lighttpd-commission.pid CONF_DIR=/var/config ENABLED=yes STINV="/sys/class/leds/led-status/invert" INIT=$(ps --no-header -o comm -p 1) if [[ $INIT == systemd ]] ; then OPTS="-D ${OPTS}" fi PASSWORDS=$(passwd -Sa | egrep '^[^[:space:]]+[[:space:]]P[[:space:]]' | wc -l) if (($PASSWORDS == 0)) ; then # Block wwan0 from commissioning /usr/libexec/commission/nfon.sh # No password, so indicate commissioning mode # php-fpm-commision will be turned on as well rm -f "/run/mt-commission" echo 'ENABLED="yes"' >"/run/mt-commission" # Invert the blink to show commissioning mode echo "Invert the blink, I am $(id)" t1=(1 1 1 1 1 1 1 1 1 1 1 1 4 16 64) i=0 while ! echo "1" >"$STINV" ; do if ((i < 15)) ; then t0=${t1[$i]} else t0=60 fi echo "LED is not ready, so sleep for $t0" sleep $t0 ((t0=(t0+1)*(t0+1))) if((t0 > 64)) ; then t0=64 fi done 2>/dev/null else ENABLED="no" echo 'ENABLED="no"' >"/run/mt-commission" echo "Clear the blink" echo "0" >"$STINV" fi [ -f "/etc/default/no-${NAME}" ] && . "/etc/default/no-${NAME}" if [ ! -f $CONF_DIR/server.pem ]; then echo "Generating server cert" openssl req \ -x509 -nodes -days 3650 \ -subj '/C=US/ST=Minnesota/L=Minneapolis/CN=mlinux.example.com' \ -newkey rsa:2048 -keyout $CONF_DIR/server.pem -out $CONF_DIR/server.pem fi if [ "$ENABLED" != "yes" ]; then echo "Some user has a password" if [ "$VERBOSE" = very ] ; then passwd -Sa | egrep '^[^[:space:]]+[[:space:]]P[[:space:]]' | logger -s -p daemon.notice echo "user count with passwords: $PASSWORDS" fi exit fi echo -n "Starting $DESC: " echo -n "Starting $DESC: " >/dev/console exec "$DAEMON" $OPTS