Browse Source

create_arm - split in two scripts

Émile Morel 10 years ago
parent
commit
0ec8246485
3 changed files with 80 additions and 42 deletions
  1. 2 1
      olinux/create_arm_debootstrap.sh
  2. 38 41
      olinux/script/firstrun
  3. 40 0
      olinux/script/secondrun

+ 2 - 1
olinux/create_arm_debootstrap.sh

@@ -147,7 +147,8 @@ chroot_deb $TARGET_DIR 'chmod g+s /var/mail/'
 # Set hostname
 # Set hostname
 echo $DEB_HOSTNAME > $TARGET_DIR/etc/hostname
 echo $DEB_HOSTNAME > $TARGET_DIR/etc/hostname
 
 
-# Add firstrun init script
+# Add firstrun and secondrun init script
+install -m 755 -o root -g root /olinux/script/secondrun $TARGET_DIR/etc/init.d/
 install -m 755 -o root -g root /olinux/script/firstrun $TARGET_DIR/etc/init.d/
 install -m 755 -o root -g root /olinux/script/firstrun $TARGET_DIR/etc/init.d/
 chroot_deb $TARGET_DIR "insserv firstrun >> /dev/null"
 chroot_deb $TARGET_DIR "insserv firstrun >> /dev/null"
 
 

+ 38 - 41
olinux/script/firstrun

@@ -11,6 +11,7 @@
 # Description:       Something needs to be done when  is
 # Description:       Something needs to be done when  is
 #                    starting at first time.
 #                    starting at first time.
 #                    regenerate ssh host key
 #                    regenerate ssh host key
+#                    expanding root partition 
 #                    run depmod 
 #                    run depmod 
 ### END INIT INFO
 ### END INIT INFO
 
 
@@ -19,50 +20,46 @@
 
 
 N=/etc/init.d/firstrun
 N=/etc/init.d/firstrun
 
 
-set -e
-
-echo ""
-echo "##########################################"
-echo "##           FIRSTRUN SCRIPT            ##"
-echo "## WAIT SOME MINUTES FOR CONFIGURATIONS ##"
-echo "##########################################"
-echo ""
-
 case "$1" in
 case "$1" in
   start)
   start)
-            reboot=false
-                echo ""
-                echo "######################"
-                echo "# ssh key generation #"
-                echo "######################"
-                echo ""
-                rm -f /etc/ssh/ssh_host*
-                dpkg-reconfigure openssh-server 
-                set +e
-                echo ""
-                echo "####################"
-                echo "# Expanding rootfs #"
-                echo "####################"
-                echo ""
-		device="/dev/mmcblk0"
-		((echo d; echo n; echo p; echo 1; echo ; echo; echo w;) | fdisk $device)
-                if [ $? -eq 0 ] ;then
-                        echo "Expanding rootfs success, rebooting automatically." 
-			/sbin/resize2fs /dev/mmcblk0p1 2>/dev/null
-                        reboot=true
-                else
-                        echo "Expanding rootfs has failed, see log files." 
-                fi
-		depmod -a
-                /sbin/insserv -r firstrun
-		if $reboot;then
-			/sbin/reboot
-		fi
-        ;;
+    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 
+    echo ""
+    echo "############################"
+    echo "# Expanding root partition #"
+    echo "############################"
+    echo ""
+    (echo d; echo n; echo p; echo 1; echo ; echo; echo w) | fdisk /dev/mmcblk0
+    /sbin/insserv secondrun 
+    echo ""
+    echo "##################"
+    echo "# Running depmod #"
+    echo "##################"
+    echo ""
+    /sbin/depmod -a
+    echo ""
+    echo "##################"
+    echo "#     Reboot     #"
+    echo "##################"
+    echo ""
+    /sbin/insserv -r firstrun
+    /sbin/insserv secondrun
+    /sbin/reboot
+    ;;
   *)
   *)
-        echo "Usage: $N {start}" >&2
-        exit 1
-        ;;
+    echo "Usage: $N {start}" >&2
+    exit 1
+    ;;
 esac
 esac
 
 
 exit 0
 exit 0

+ 40 - 0
olinux/script/secondrun

@@ -0,0 +1,40 @@
+#!/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
+
+exit 0