create_arm_debootstrap.sh 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182
  1. #/bin/bash
  2. ######################
  3. # Debootstrap #
  4. ######################
  5. set -e
  6. show_usage() {
  7. cat <<EOF
  8. # NAME
  9. $(basename $0) -- Script to create a minimal deboostrap
  10. # OPTIONS
  11. -d debian release (wheezy, jessie) (default: wheezy)
  12. -b olinux board (see config_board.sh) (default: a20lime)
  13. -a add packages to deboostrap
  14. -n hostname (default: olinux)
  15. -t target directory for debootstrap (default: /olinux/debootstrap)
  16. -i install sunxi kernel files; you should have build them before.
  17. -y install yunohost (under development)
  18. EOF
  19. exit 1
  20. }
  21. DEBIAN_RELEASE=wheezy
  22. TARGET_DIR=/olinux/debootstrap
  23. DEB_HOSTNAME=olinux
  24. while getopts ":a:b:d:n:t:iy" opt; do
  25. case $opt in
  26. d)
  27. DEBIAN_RELEASE=$OPTARG
  28. ;;
  29. b)
  30. BOARD=$OPTARG
  31. ;;
  32. a)
  33. PACKAGES=$OPTARG
  34. ;;
  35. n)
  36. DEB_HOSTNAME=$OPTARG
  37. ;;
  38. t)
  39. TARGET_DIR=$OPTARG
  40. ;;
  41. i)
  42. INSTALL_KERNEL=yes
  43. ;;
  44. y)
  45. INSTALL_YUNOHOST=yes
  46. ;;
  47. \?)
  48. show_usage
  49. ;;
  50. esac
  51. done
  52. source /olinux/config_board.sh
  53. rm -rf $TARGET_DIR && mkdir -p $TARGET_DIR
  54. chroot_deb (){
  55. LC_ALL=C LANGUAGE=C LANG=C chroot $1 /bin/bash -c "$2"
  56. }
  57. # install packages for debootstap
  58. apt-get install --force-yes -y debootstrap dpkg-dev qemu binfmt-support qemu-user-static dpkg-cross
  59. # Debootstrap
  60. mount binfmt_misc -t binfmt_misc /proc/sys/fs/binfmt_misc
  61. bash /olinux/script/binfmt-misc-arm.sh unregister
  62. bash /olinux/script/binfmt-misc-arm.sh
  63. debootstrap --arch=armhf --foreign $DEBIAN_RELEASE $TARGET_DIR
  64. cp /usr/bin/qemu-arm-static $TARGET_DIR/usr/bin/
  65. cp /etc/resolv.conf $TARGET_DIR/etc
  66. chroot_deb $TARGET_DIR '/debootstrap/debootstrap --second-stage'
  67. # mount proc, sys and dev
  68. mount -t proc chproc $TARGET_DIR/proc
  69. mount -t sysfs chsys $TARGET_DIR/sys
  70. mount -t devtmpfs chdev $TARGET_DIR/dev || mount --bind /dev $TARGET_DIR/dev
  71. mount -t devpts chpts $TARGET_DIR/dev/pts || mount --bind /dev/pts $TARGET_DIR/dev/pts
  72. # Configure debian apt repository
  73. cat <<EOT > $TARGET_DIR/etc/apt/sources.list
  74. deb http://ftp.fr.debian.org/debian $DEBIAN_RELEASE main contrib non-free
  75. deb http://security.debian.org/ $DEBIAN_RELEASE/updates main contrib non-free
  76. EOT
  77. cat <<EOT > $TARGET_DIR/etc/apt/apt.conf.d/71-no-recommends
  78. APT::Install-Recommends "0";
  79. APT::Install-Suggests "0";
  80. EOT
  81. chroot_deb $TARGET_DIR 'apt-get update'
  82. # Add ssh server and ntp client
  83. chroot_deb $TARGET_DIR "apt-get install -y --force-yes openssh-server ntp parted locales $PACKAGES"
  84. # Use dhcp on boot
  85. cat <<EOT > $TARGET_DIR/etc/network/interfaces
  86. auto lo
  87. iface lo inet loopback
  88. allow-hotplug eth0
  89. iface eth0 inet dhcp
  90. EOT
  91. # Debootstrap optimisations from igorpecovnik
  92. # change default I/O scheduler, noop for flash media, deadline for SSD, cfq for mechanical drive
  93. cat <<EOT >> $TARGET_DIR/etc/sysfs.conf
  94. block/mmcblk0/queue/scheduler = noop
  95. #block/sda/queue/scheduler = cfq
  96. EOT
  97. # flash media tunning
  98. if [ -f "$TARGET_DIR/etc/default/tmpfs" ]; then
  99. sed -e 's/#RAMTMP=no/RAMTMP=yes/g' -i $TARGET_DIR/etc/default/tmpfs
  100. sed -e 's/#RUN_SIZE=10%/RUN_SIZE=128M/g' -i $TARGET_DIR/etc/default/tmpfs
  101. sed -e 's/#LOCK_SIZE=/LOCK_SIZE=/g' -i $TARGET_DIR/etc/default/tmpfs
  102. sed -e 's/#SHM_SIZE=/SHM_SIZE=128M/g' -i $TARGET_DIR/etc/default/tmpfs
  103. sed -e 's/#TMP_SIZE=/TMP_SIZE=1G/g' -i $TARGET_DIR/etc/default/tmpfs
  104. fi
  105. # Generate locales
  106. sed -i "s/^# fr_FR.UTF-8 UTF-8/fr_FR.UTF-8 UTF-8/" $TARGET_DIR/etc/locale.gen
  107. sed -i "s/^# en_US.UTF-8 UTF-8/en_US.UTF-8 UTF-8/" $TARGET_DIR/etc/locale.gen
  108. chroot_deb $TARGET_DIR "locale-gen en_US.UTF-8"
  109. # Update timezone
  110. echo 'Europe/Paris' > $TARGET_DIR/etc/timezone
  111. chroot_deb $TARGET_DIR "dpkg-reconfigure -f noninteractive tzdata"
  112. # Configure tty
  113. echo T0:2345:respawn:/sbin/getty -L ttyS0 115200 vt100 >> $TARGET_DIR/etc/inittab
  114. # Good right on some directories
  115. chroot_deb $TARGET_DIR 'chmod 1777 /tmp/'
  116. chroot_deb $TARGET_DIR 'chgrp mail /var/mail/'
  117. chroot_deb $TARGET_DIR 'chmod g+w /var/mail/'
  118. chroot_deb $TARGET_DIR 'chmod g+s /var/mail/'
  119. # Set hostname
  120. echo $DEB_HOSTNAME > $TARGET_DIR/etc/hostname
  121. # Add firstrun and secondrun init script
  122. install -m 755 -o root -g root /olinux/script/secondrun $TARGET_DIR/etc/init.d/
  123. install -m 755 -o root -g root /olinux/script/firstrun $TARGET_DIR/etc/init.d/
  124. chroot_deb $TARGET_DIR "insserv firstrun >> /dev/null"
  125. if [ $INSTALL_KERNEL ] ; then
  126. cp /olinux/sunxi/*.deb $TARGET_DIR/tmp/
  127. chroot_deb $TARGET_DIR 'dpkg -i /tmp/*.deb'
  128. rm $TARGET_DIR/tmp/*
  129. cp /olinux/sunxi/boot.scr $TARGET_DIR/boot/
  130. chroot_deb $TARGET_DIR "ln -s /boot/dtb/$DTB /boot/board.dtb"
  131. fi
  132. if [ $INSTALL_YUNOHOST ] ; then
  133. chroot_deb $TARGET_DIR "apt-get install -y --force-yes git"
  134. chroot_deb $TARGET_DIR "git clone https://github.com/YunoHost/install_script /tmp/install_script"
  135. chroot_deb $TARGET_DIR "cd /tmp/install_script && ./autoinstall_yunohostv2 test"
  136. fi
  137. # Add 'olinux' for root password and force to change it at first login
  138. chroot_deb $TARGET_DIR '(echo olinux;echo olinux;) | passwd root'
  139. chroot_deb $TARGET_DIR 'chage -d 0 root'
  140. # Remove useless files
  141. chroot_deb $TARGET_DIR 'apt-get clean'
  142. rm $TARGET_DIR/etc/resolv.conf
  143. rm $TARGET_DIR/usr/bin/qemu-arm-static
  144. # Umount proc, sys, and dev
  145. umount -l $TARGET_DIR/dev/pts
  146. umount -l $TARGET_DIR/dev
  147. umount -l $TARGET_DIR/proc
  148. umount -l $TARGET_DIR/sys