freedombone-image-customise 6.9KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229
  1. #!/bin/bash
  2. #
  3. # Based on bin/freedombox-customize from freedom-maker
  4. #
  5. # This program is free software: you can redistribute it and/or modify
  6. # it under the terms of the GNU General Public License as published by
  7. # the Free Software Foundation, either version 3 of the License, or
  8. # (at your option) any later version.
  9. #
  10. # This program is distributed in the hope that it will be useful,
  11. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. # GNU General Public License for more details.
  14. #
  15. # You should have received a copy of the GNU General Public License
  16. # along with this program. If not, see <http://www.gnu.org/licenses/>.
  17. set -e
  18. set -x
  19. MY_USERNAME='debian'
  20. MY_PASSWORD='freedombone'
  21. # IP address of the router (gateway)
  22. ROUTER_IP_ADDRESS="192.168.1.254"
  23. # The fixed IP address of the Beaglebone Black on your local network
  24. BOX_IP_ADDRESS="192.168.1.55"
  25. # DNS
  26. NAMESERVER1='213.73.91.35'
  27. NAMESERVER2='85.214.20.141'
  28. enable_eatmydata_override() {
  29. chroot $rootdir apt-get install --no-install-recommends -y eatmydata
  30. if [ -x $rootdir/usr/bin/eatmydata ] && \
  31. [ ! -f $rootdir/etc/apt/apt.conf.d/95debian-edu-install-dpkg-eatmydata ]; then
  32. echo "info: Adding apt config to call dpkg via eatmydata"
  33. printf "#!/bin/sh\nexec eatmydata dpkg \"\$@\"\n" \
  34. > $rootdir/var/tmp/dpkg-eatmydata
  35. chmod 755 $rootdir/var/tmp/dpkg-eatmydata
  36. cat > $rootdir/etc/apt/apt.conf.d/95debian-edu-install-dpkg-eatmydata <<EOF
  37. Dir::Bin::dpkg "/var/tmp/dpkg-eatmydata";
  38. EOF
  39. else
  40. echo "error: unable to find /usr/bin/eatmydata after installing the eatmydata package"
  41. fi
  42. }
  43. disable_eatmydata_override() {
  44. for override in \
  45. /etc/apt/apt.conf.d/95debian-edu-install-dpkg-eatmydata \
  46. /var/tmp/dpkg-eatmydata ; do
  47. echo "info: Removing apt config to call dpkg via eatmydata"
  48. if [ -f $rootdir$override ] ; then
  49. rm -f $rootdir$override
  50. else
  51. echo "warning: missing $rootdir$override"
  52. fi
  53. done
  54. sync # Flush file buffers before continuing
  55. }
  56. set_apt_sources() {
  57. NEW_MIRROR="$1"
  58. COMPONENTS="main"
  59. cat <<EOF > etc/apt/sources.list
  60. deb $NEW_MIRROR $SUITE $COMPONENTS
  61. deb-src $NEW_MIRROR $SUITE $COMPONENTS
  62. #deb http://security.debian.org/ $SUITE/updates main
  63. #deb-src http://security.debian.org/ $SUITE/updates main
  64. EOF
  65. }
  66. # Set to true/false to control if eatmydata is used during build
  67. use_eatmydata=true
  68. rootdir="$1"
  69. fmdir="$(pwd)"
  70. image="$fmdir"/"$2"
  71. cd "$rootdir"
  72. echo info: building $MACHINE for $ARCHITECTURE
  73. export DEBIAN_FRONTEND=noninteractive DEBCONF_NONINTERACTIVE_SEEN=true
  74. export LC_ALL=C LANGUAGE=C LANG=C
  75. # Override libpam-tmpdir setting during build, as the directories
  76. # are not created yet.
  77. export TMP=/tmp/ TMPDIR=/tmp/
  78. username=$MY_USERNAME
  79. echo "warning: creating initial user $username with well known password!"
  80. password=$MY_PASSWORD
  81. chroot $rootdir adduser --gecos $username --disabled-password $username
  82. echo $username:$password | chroot $rootdir /usr/sbin/chpasswd
  83. chroot $rootdir adduser $username sudo
  84. case "$MACHINE" in
  85. virtualbox)
  86. # hide irrelevant console keyboard messages.
  87. echo "echo \"4 4 1 7\" > /proc/sys/kernel/printk" \
  88. >> /etc/init.d/rc.local
  89. ;;
  90. esac
  91. set_apt_sources $BUILD_MIRROR
  92. chroot $rootdir apt-get update
  93. cat > $rootdir/usr/sbin/policy-rc.d <<EOF
  94. #!/bin/sh
  95. exit 101
  96. EOF
  97. chmod a+rx $rootdir/usr/sbin/policy-rc.d
  98. if $use_eatmydata ; then
  99. enable_eatmydata_override
  100. fi
  101. if [ -n "$CUSTOM_SETUP" ]; then
  102. cp "$CUSTOM_SETUP" "$rootdir"/tmp
  103. chroot "$rootdir" apt-get install -y gdebi-core
  104. chroot "$rootdir" gdebi -n /tmp/"$(basename $CUSTOM_SETUP)"
  105. fi
  106. chroot "$rootdir" apt-get install -y git dialog build-essential
  107. chroot "$rootdir" git clone https://github.com/bashrc/freedombone /root/freedombone
  108. chroot "$rootdir" cd /root/freedombone && make install
  109. chroot $rootdir freedombone-image-hardware-setup 2>&1 | \
  110. tee $rootdir/var/log/freedombone-image-hardware-setup.log
  111. rm $rootdir/usr/sbin/policy-rc.d
  112. chroot $rootdir /usr/lib/freedombone/setup 2>&1 | \
  113. tee $rootdir/var/log/freedombone-setup.log
  114. # Remove SSH keys from the image
  115. rm $rootdir/etc/ssh/ssh_host_* || true
  116. echo "# This file describes the network interfaces available on your system
  117. # and how to activate them. For more information, see interfaces(5).
  118. # The loopback network interface
  119. auto lo
  120. iface lo inet loopback
  121. # The primary network interface
  122. auto eth0
  123. iface eth0 inet static
  124. address $BOX_IP_ADDRESS
  125. netmask 255.255.255.0
  126. gateway $ROUTER_IP_ADDRESS
  127. dns-nameservers $NAMESERVER1 $NAMESERVER2
  128. # Example to keep MAC address between reboots
  129. #hwaddress ether B5:A2:BE:3F:1A:FE
  130. # The secondary network interface
  131. #auto eth1
  132. #iface eth1 inet dhcp
  133. # WiFi Example
  134. #auto wlan0
  135. #iface wlan0 inet dhcp
  136. # wpa-ssid \"essid\"
  137. # wpa-psk \"password\"
  138. # Ethernet/RNDIS gadget (g_ether)
  139. # ... or on host side, usbnet and random hwaddr
  140. # Note on some boards, usb0 is automaticly setup with an init script
  141. #iface usb0 inet static
  142. # address 192.168.7.2
  143. # netmask 255.255.255.0
  144. # network 192.168.7.0
  145. # gateway 192.168.7.1" > $rootdir/etc/network/interfaces
  146. hexarray=( 1 2 3 4 5 6 7 8 9 0 a b c d e f )
  147. a=${hexarray[$RANDOM%16]}${hexarray[$RANDOM%16]}
  148. b=${hexarray[$RANDOM%16]}${hexarray[$RANDOM%16]}
  149. c=${hexarray[$RANDOM%16]}${hexarray[$RANDOM%16]}
  150. d=${hexarray[$RANDOM%16]}${hexarray[$RANDOM%16]}
  151. e=${hexarray[$RANDOM%16]}${hexarray[$RANDOM%16]}
  152. sed -i "s|#hwaddress ether.*|hwaddress ether de:$a:$b:$c:$d:$e|g" $rootdir/etc/network/interfaces
  153. sed -i "s/nameserver.*/nameserver $NAMESERVER1/g" $rootdir/etc/resolv.conf
  154. sed -i "/nameserver $NAMESERVER1/a\nameserver $NAMESERVER2" $rootdir/etc/resolv.conf
  155. # change the motd to show further install instructions
  156. echo "
  157. To complete the installation run the following:
  158. sudo su
  159. freedombone menuconfig
  160. " > $rootdir/etc/init.d/motd
  161. # copy u-boot to beginning of image
  162. case "$MACHINE" in
  163. beaglebone)
  164. chroot $rootdir apt-get -y install rng-tools
  165. sed -i 's|#HRNGDEVICE=/dev/hwrng|HRNGDEVICE=/dev/hwrng|g' $rootdir/etc/default/rng-tools
  166. dd if=$rootdir/usr/lib/u-boot/am335x_boneblack/MLO of="$image" \
  167. count=1 seek=1 conv=notrunc bs=128k
  168. dd if=$rootdir/usr/lib/u-boot/am335x_boneblack/u-boot.img of="$image" \
  169. count=2 seek=1 conv=notrunc bs=384k
  170. ;;
  171. cubieboard2)
  172. chroot $rootdir apt-get -y install haveged
  173. dd if=$rootdir/usr/lib/u-boot/Cubieboard2/u-boot-sunxi-with-spl.bin of="$image" \
  174. seek=8 conv=notrunc bs=1k
  175. ;;
  176. esac
  177. if $use_eatmydata ; then
  178. disable_eatmydata_override
  179. fi
  180. set_apt_sources $MIRROR
  181. chroot $rootdir apt-get update
  182. cd /
  183. echo "info: killing leftover processes in chroot"
  184. # 2014-11-04 this killed /usr/lib/erlang/erts-6.2/bin/epmd, see
  185. # <URL: https://www.ejabberd.im/epmd?q=epmd > to learn more.
  186. fuser -mvk $rootdir/. || true