Browse Source

init script in systemd style

Émile Morel 9 years ago
parent
commit
e5141d4dac
4 changed files with 58 additions and 98 deletions
  1. 7 3
      olinux/create_arm_debootstrap.sh
  2. 1 1
      olinux/create_device.sh
  3. 38 58
      olinux/script/firstrun
  4. 12 36
      olinux/script/secondrun

+ 7 - 3
olinux/create_arm_debootstrap.sh

@@ -206,9 +206,13 @@ echo $DEB_HOSTNAME > $TARGET_DIR/etc/hostname
 sed -i "1i127.0.1.1\t${DEB_HOSTNAME}" $TARGET_DIR/etc/hosts
 
 # Add firstrun and secondrun init script
-install -m 755 -o root -g root ${REP}/script/secondrun $TARGET_DIR/etc/init.d/
-install -m 755 -o root -g root ${REP}/script/firstrun $TARGET_DIR/etc/init.d/
-chroot_deb $TARGET_DIR "insserv firstrun >> /dev/null"
+install -m 755 -o root -g root ${REP}/script/secondrun $TARGET_DIR/usr/local/bin/
+install -m 755 -o root -g root ${REP}/script/firstrun $TARGET_DIR/usr/local/bin/
+install -m 755 -o root -g root ${REP}/script/firstrun $TARGET_DIR/usr/local/bin/
+install -m 544 -o root -g root ${REP}/script/firstrun.service $TARGET_DIR/etc/systemd/system/
+install -m 544 -o root -g root ${REP}/script/secondrun.service $TARGET_DIR/etc/systemd/system/
+chroot_deb $TARGET_DIR "/bin/systemctl daemon-reload >> /dev/null"
+chroot_deb $TARGET_DIR "/bin/systemctl enable firstrun >> /dev/null"
 
 if [ $INSTALL_YUNOHOST ] ; then
   chroot_deb $TARGET_DIR "$APT git"

+ 1 - 1
olinux/create_device.sh

@@ -171,7 +171,7 @@ else
     umount $MNT1
     cryptsetup luksClose olinux 
   fi
-  if [ `file ${DEB_DIR} | grep 'DOS/MBR'` ] ; then
+  if $(file ${DEB_DIR} | grep 'DOS/MBR') ; then
     umount $MNT2
     losetup -d $DEVICE1
   fi	  

+ 38 - 58
olinux/script/firstrun

@@ -1,62 +1,42 @@
 #!/bin/bash
 
-### BEGIN INIT INFO
-# Provides:          firstrun
-# Required-Start:    $all
-# Required-Stop:
-# Should-Start:
-# Default-Start:     2 3 4 5
-# Default-Stop:      0 1 6
-# Short-Description: Script to run when first starting
-# Description:       Something needs to be done when  is
-#                    starting at first time.
-#                    regenerate ssh host key
-#                    expanding root partition 
-#                    run depmod 
-### END INIT INFO
-
-# script from https://github.com/igorpecovnik/lib
-# modified by https://github.com/bleuchtang/sunxi-debian
-
-N=/etc/init.d/firstrun
-
-case "$1" in
-  start)
-    echo ""
-    echo "##########################################"
-    echo "##         FIRSTRUN INIT SCRIPT         ##"
-    echo "## WAIT SOME MINUTES FOR CONFIGURATIONS ##"
-    echo "##########################################"
-    echo ""
-    echo "######################"
-    echo "# ssh key generation #"
-    echo "######################"
-    echo ""
-    rm -f /etc/ssh/ssh_host*
-    dpkg-reconfigure openssh-server 
-    # do not resize partition if root is crypted 
-    /sbin/insserv -r firstrun
-    if [ ! -e /etc/crypttab ]; then
-      echo ""
-      echo "############################"
-      echo "# Expanding root partition #"
-      echo "############################"
-      (echo d; echo n; echo p; echo 1; echo ; echo; echo w) | fdisk /dev/mmcblk0
-      /sbin/insserv secondrun
-      echo ""
-      echo "##################"
-      echo "#     Reboot     #"
-      echo "##################"
-      echo ""
-      /sbin/reboot
-    else
-      update-initramfs -u -k all
-    fi
-    ;;
-  *)
-    echo "Usage: $N {start}" >&2
-    exit 1
-    ;;
-esac
+echo ""
+echo "##########################################"
+echo "##         FIRSTRUN INIT SCRIPT         ##"
+echo "## WAIT SOME MINUTES FOR CONFIGURATIONS ##"
+echo "##########################################"
+echo ""
+echo "######################"
+echo "# ssh key generation #"
+echo "######################"
+echo ""
+rm -f /etc/ssh/ssh_host*
+dpkg-reconfigure openssh-server 
+/bin/systemctl disable firstrun
+if [ ! -e /etc/crypttab ]; then
+  echo ""
+  echo "############################"
+  echo "# Expanding root partition #"
+  echo "############################"
+  (echo d; echo n; echo p; echo 1; echo ; echo; echo w) | fdisk /dev/mmcblk0
+  /bin/systemctl enable secondrun
+  echo ""
+  echo "##################"
+  echo "#     reboot     #"
+  echo "##################"
+  echo ""
+  /sbin/reboot
+else
+  echo ""
+  echo "####################"
+  echo "# update initramfs #"
+  echo "####################"
+  echo ""
+  rm /etc/initramfs-tools/stunnel.{csr,key,pem}
+  echo > /etc/initramfs-tools/root/.ssh/authorized_keys
+  rm /etc/initramfs-tools/root/.ssh/id_*
+  rm /etc/initramfs-tools/etc/dropbear/dropbear_*
+  /usr/sbin/update-initramfs -u -k all
+fi
 
 exit 0

+ 12 - 36
olinux/script/secondrun

@@ -1,40 +1,16 @@
 #!/bin/bash
 
-### BEGIN INIT INFO
-# Provides:          secondrun
-# Required-Start:    $all
-# Required-Stop:
-# Should-Start:
-# Default-Start:     2 3 4 5
-# Default-Stop:      0 1 6
-# Short-Description: Script to run when second starting
-# Description:	     Expanding rottfs
-### END INIT INFO
-
-# script from https://github.com/igorpecovnik/lib
-# modified by https://github.com/bleuchtang/sunxi-debian
-
-N=/etc/init.d/secondrun
-
-case "$1" in
-  start)
-    echo ""
-    echo "##########################################"
-    echo "##         SECONDRUN INIT SCRIPT        ##"
-    echo "## WAIT SOME MINUTES FOR CONFIGURATIONS ##"
-    echo "##########################################"
-    echo ""
-    echo "##############################"
-    echo "# Expanding rootfs partition #"
-    echo "##############################"
-    echo ""
-    /sbin/resize2fs /dev/mmcblk0p1
-    /sbin/insserv -r secondrun
-    ;;
-  *)
-    echo "Usage: $N {start}" >&2
-    exit 1
-    ;;
-esac
+echo ""
+echo "##########################################"
+echo "##         SECONDRUN INIT SCRIPT        ##"
+echo "## WAIT SOME MINUTES FOR CONFIGURATIONS ##"
+echo "##########################################"
+echo ""
+echo "##############################"
+echo "# Expanding rootfs partition #"
+echo "##############################"
+echo ""
+/sbin/resize2fs /dev/mmcblk0p1
+/usr/sbin/systemctl disable secondrun
 
 exit 0