freedombone-image-customise 18KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506
  1. #!/bin/bash
  2. #
  3. # .---. . .
  4. # | | |
  5. # |--- .--. .-. .-. .-.| .-. .--.--. |.-. .-. .--. .-.
  6. # | | (.-' (.-' ( | ( )| | | | )( )| | (.-'
  7. # ' ' --' --' -' - -' ' ' -' -' -' ' - --'
  8. #
  9. # Freedom in the Cloud
  10. #
  11. # Based on bin/freedombox-customize from freedom-maker
  12. #
  13. # License
  14. # =======
  15. #
  16. # This program is free software: you can redistribute it and/or modify
  17. # it under the terms of the GNU General Public License as published by
  18. # the Free Software Foundation, either version 3 of the License, or
  19. # (at your option) any later version.
  20. #
  21. # This program is distributed in the hope that it will be useful,
  22. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  23. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  24. # GNU General Public License for more details.
  25. #
  26. # You should have received a copy of the GNU General Public License
  27. # along with this program. If not, see <http://www.gnu.org/licenses/>.
  28. set -e
  29. set -x
  30. PROJECT_NAME='freedombone'
  31. # username created by default within a debian image
  32. GENERIC_IMAGE_USERNAME='fbone'
  33. export TEXTDOMAIN=${PROJECT_NAME}-image-customise
  34. export TEXTDOMAINDIR="/usr/share/locale"
  35. # Whether to minimise the number of decisions during interactive install
  36. MINIMAL_INSTALL="yes"
  37. MY_USERNAME='debian'
  38. MY_PASSWORD="${PROJECT_NAME}"
  39. # IP address of the router (gateway)
  40. ROUTER_IP_ADDRESS="192.168.1.254"
  41. # The fixed IP address of the Beaglebone Black on your local network
  42. BOX_IP_ADDRESS="192.168.1.55"
  43. # DNS
  44. NAMESERVER1='213.73.91.35'
  45. NAMESERVER2='85.214.20.141'
  46. # optional configuration file containing freedombone settings
  47. CONFIG_FILENAME=
  48. # Optional ssh public key to allow
  49. SSH_PUBKEY="no"
  50. # Whether this is a generic image for mass redistribution on the interwebs
  51. GENERIC_IMAGE="no"
  52. # default SSH port
  53. SSH_PORT=2222
  54. # Whether sites are accessible only within a Tor browser
  55. ONION_ONLY="no"
  56. enable_eatmydata_override() {
  57. chroot $rootdir apt-get install --no-install-recommends -y eatmydata
  58. if [ -x $rootdir/usr/bin/eatmydata ] && \
  59. [ ! -f $rootdir/etc/apt/apt.conf.d/95debian-edu-install-dpkg-eatmydata ]; then
  60. echo $"info: Adding apt config to call dpkg via eatmydata"
  61. printf "#!/bin/sh\nexec eatmydata dpkg \"\$@\"\n" \
  62. > $rootdir/var/tmp/dpkg-eatmydata
  63. chmod 755 $rootdir/var/tmp/dpkg-eatmydata
  64. cat > $rootdir/etc/apt/apt.conf.d/95debian-edu-install-dpkg-eatmydata <<EOF
  65. Dir::Bin::dpkg "/var/tmp/dpkg-eatmydata";
  66. EOF
  67. else
  68. echo $"error: unable to find /usr/bin/eatmydata after installing the eatmydata package"
  69. fi
  70. }
  71. disable_eatmydata_override() {
  72. for override in \
  73. /etc/apt/apt.conf.d/95debian-edu-install-dpkg-eatmydata \
  74. /var/tmp/dpkg-eatmydata ; do
  75. echo $"info: Removing apt config to call dpkg via eatmydata"
  76. if [ -f $rootdir$override ] ; then
  77. rm -f $rootdir$override
  78. else
  79. echo $"warning: missing $rootdir$override"
  80. fi
  81. done
  82. sync # Flush file buffers before continuing
  83. }
  84. set_apt_sources() {
  85. NEW_MIRROR="$1"
  86. COMPONENTS="main"
  87. cat <<EOF > etc/apt/sources.list
  88. deb $NEW_MIRROR $SUITE $COMPONENTS
  89. deb-src $NEW_MIRROR $SUITE $COMPONENTS
  90. #deb http://security.debian.org/ $SUITE/updates main
  91. #deb-src http://security.debian.org/ $SUITE/updates main
  92. EOF
  93. }
  94. configure_networking() {
  95. if [[ $GENERIC_IMAGE == "no" ]]; then
  96. echo "# This file describes the network interfaces available on your system
  97. # and how to activate them. For more information, see interfaces(5).
  98. # The loopback network interface
  99. auto lo
  100. iface lo inet loopback
  101. # The primary network interface
  102. auto eth0
  103. iface eth0 inet static
  104. address $BOX_IP_ADDRESS
  105. netmask 255.255.255.0
  106. gateway $ROUTER_IP_ADDRESS
  107. dns-nameservers $NAMESERVER1 $NAMESERVER2
  108. # Example to keep MAC address between reboots
  109. #hwaddress ether B5:A2:BE:3F:1A:FE
  110. # The secondary network interface
  111. #auto eth1
  112. #iface eth1 inet dhcp
  113. # WiFi Example
  114. #auto wlan0
  115. #iface wlan0 inet dhcp
  116. # wpa-ssid \"essid\"
  117. # wpa-psk \"password\"
  118. # Ethernet/RNDIS gadget (g_ether)
  119. # ... or on host side, usbnet and random hwaddr
  120. # Note on some boards, usb0 is automaticly setup with an init script
  121. #iface usb0 inet static
  122. # address 192.168.7.2
  123. # netmask 255.255.255.0
  124. # network 192.168.7.0
  125. # gateway 192.168.7.1" > $rootdir/etc/network/interfaces
  126. hexarray=( 1 2 3 4 5 6 7 8 9 0 a b c d e f )
  127. a=${hexarray[$RANDOM%16]}${hexarray[$RANDOM%16]}
  128. b=${hexarray[$RANDOM%16]}${hexarray[$RANDOM%16]}
  129. c=${hexarray[$RANDOM%16]}${hexarray[$RANDOM%16]}
  130. d=${hexarray[$RANDOM%16]}${hexarray[$RANDOM%16]}
  131. e=${hexarray[$RANDOM%16]}${hexarray[$RANDOM%16]}
  132. sed -i "s|#hwaddress ether.*|hwaddress ether de:$a:$b:$c:$d:$e|g" \
  133. $rootdir/etc/network/interfaces
  134. fi
  135. sed -i "s/nameserver.*/nameserver $NAMESERVER1/g" $rootdir/etc/resolv.conf
  136. sed -i "/nameserver $NAMESERVER1/a\nameserver $NAMESERVER2" $rootdir/etc/resolv.conf
  137. # change the motd to show further install instructions
  138. echo $"
  139. .---. . .
  140. | | |
  141. |--- .--. .-. .-. .-.| .-. .--.--. |.-. .-. .--. .-.
  142. | | (.-' (.-' ( | ( )| | | | )( )| | (.-'
  143. ' ' --' --' -' - -' ' ' -' -' -' ' - --'
  144. Initial base install
  145. Your system is not yet installed. To complete the process run the
  146. following commands, then enter your details.
  147. sudo su
  148. ${PROJECT_NAME} menuconfig
  149. " > $rootdir/etc/motd
  150. }
  151. configure_ssh() {
  152. sed -i "s/Port .*/Port ${SSH_PORT}/g" $rootdir/etc/ssh/sshd_config
  153. if [[ "$SSH_PUBKEY" != "no" ]]; then
  154. if [ ! -d $rootdir/home/$MY_USERNAME/.ssh ]; then
  155. mkdir $rootdir/home/$MY_USERNAME/.ssh
  156. fi
  157. echo "$SSH_PUBKEY" > $rootdir/home/$MY_USERNAME/.ssh/authorized_keys
  158. chroot $rootdir chown -R $MY_USERNAME:$MY_USERNAME /home/$MY_USERNAME/.ssh
  159. sed -i 's|PasswordAuthentication.*|PasswordAuthentication no|g' $rootdir/etc/ssh/sshd_config
  160. echo $"Using ssh public key:"
  161. echo $SSH_PUBKEY
  162. echo $'Password ssh authentication turned off'
  163. fi
  164. }
  165. admin_user_sudo() {
  166. echo "$MY_USERNAME ALL=(ALL) ALL" >> $rootdir/etc/sudoers
  167. }
  168. create_generic_image() {
  169. if [[ $GENERIC_IMAGE == "no" ]]; then
  170. return
  171. fi
  172. VARIANT="full"
  173. if [ $CONFIG_FILENAME ]; then
  174. if [[ "$CONFIG_FILENAME" == *"mesh.cfg"* ]]; then
  175. VARIANT="mesh"
  176. fi
  177. fi
  178. # Don't install any configuration. This will be a base system
  179. if [[ $VARIANT != "mesh" ]]; then
  180. CONFIG_FILENAME=
  181. else
  182. touch $rootdir/root/.initial_mesh_setup
  183. fi
  184. # The presence of this file indicates that the initial
  185. # setup has not yet been completed
  186. touch $rootdir/home/$MY_USERNAME/.initial_setup
  187. chroot $rootdir chown $MY_USERNAME:$MY_USERNAME /home/$MY_USERNAME/.initial_setup
  188. touch $rootdir/root/.initial_setup
  189. cat >> $rootdir/home/$MY_USERNAME/.bashrc <<EOF
  190. # initial setup of the system
  191. if [ -f ~/.initial_setup ]; then
  192. clear
  193. echo "
  194. .---. . .
  195. | | |
  196. |--- .--. .-. .-. .-.| .-. .--.--. |.-. .-. .--. .-.
  197. | | (.-' (.-' ( | ( )| | | | )( )| | (.-'
  198. ' ' --' --' -' - -' ' ' -' -' -' ' - --'
  199. Initial setup process
  200. Please enter your password a second time.
  201. "
  202. sudo su
  203. fi
  204. EOF
  205. echo '# initial setup of the system' >> $rootdir/root/.bashrc
  206. echo 'if [ -f ~/.initial_setup ]; then' >> $rootdir/root/.bashrc
  207. echo ' if [ -f ~/login.txt ]; then' >> $rootdir/root/.bashrc
  208. echo ' NEW_USER_PASSWORD=$(printf `cat ~/login.txt`)' >> $rootdir/root/.bashrc
  209. echo ' else' >> $rootdir/root/.bashrc
  210. echo ' ENTROPY=$(cat /proc/sys/kernel/random/entropy_avail)' >> $rootdir/root/.bashrc
  211. echo ' if [ $ENTROPY -lt 500 ]; then' >> $rootdir/root/.bashrc
  212. echo ' dialog --backtitle "Initial setup process" --title "Password Generation" --msgbox "WARNING: The entropy available on this system is too low to generate a password.\n\nThe installation process cannot continue." 8 50' >> $rootdir/root/.bashrc
  213. echo ' exit' >> $rootdir/root/.bashrc
  214. echo ' fi' >> $rootdir/root/.bashrc
  215. echo ' NEW_USER_PASSWORD="$(openssl rand -base64 12 | cut -c1-10)"' >> $rootdir/root/.bashrc
  216. echo ' fi' >> $rootdir/root/.bashrc
  217. echo ' echo "${NEW_USER_PASSWORD}" > ~/login.txt' >> $rootdir/root/.bashrc
  218. echo ' clear' >> $rootdir/root/.bashrc
  219. echo ' echo ""' >> $rootdir/root/.bashrc
  220. echo ' echo "Your new login password is:"' >> $rootdir/root/.bashrc
  221. echo ' echo ""' >> $rootdir/root/.bashrc
  222. echo ' toilet "${NEW_USER_PASSWORD}"' >> $rootdir/root/.bashrc
  223. echo ' echo ""' >> $rootdir/root/.bashrc
  224. echo ' echo " ${NEW_USER_PASSWORD}"' >> $rootdir/root/.bashrc
  225. echo ' echo ""' >> $rootdir/root/.bashrc
  226. echo ' echo "Use it whenever you wish to ssh into this system."' >> $rootdir/root/.bashrc
  227. echo ' echo ""' >> $rootdir/root/.bashrc
  228. echo ' echo "IMPORTANT: Please take a moment to enter the above password into a"' >> $rootdir/root/.bashrc
  229. echo ' echo "password manager or write it down somewhere."' >> $rootdir/root/.bashrc
  230. echo ' echo ""' >> $rootdir/root/.bashrc
  231. echo ' read -n1 -r -p "Press any key to continue..." key' >> $rootdir/root/.bashrc
  232. # change the password for the admin user
  233. echo -n " echo \"${MY_USERNAME}:" >> $rootdir/root/.bashrc
  234. echo '$(printf `cat ~/login.txt`)"|chpasswd' >> $rootdir/root/.bashrc
  235. # update before continuing
  236. echo " cd /root/${PROJECT_NAME}" >> $rootdir/root/.bashrc
  237. echo " git stash" >> $rootdir/root/.bashrc
  238. echo " git pull" >> $rootdir/root/.bashrc
  239. echo " make install" >> $rootdir/root/.bashrc
  240. if [[ $VARIANT != "mesh" ]]; then
  241. if [[ $ONION_ONLY == "no" ]]; then
  242. if [[ $MINIMAL_INSTALL == "no" ]]; then
  243. echo " ${PROJECT_NAME} menuconfig-full" >> $rootdir/root/.bashrc
  244. else
  245. echo " ${PROJECT_NAME} menuconfig" >> $rootdir/root/.bashrc
  246. fi
  247. else
  248. echo " ${PROJECT_NAME} menuconfig-onion" >> $rootdir/root/.bashrc
  249. fi
  250. else
  251. echo ' echo ""'
  252. fi
  253. echo ' if [ "$?" = "0" ]; then' >> $rootdir/root/.bashrc
  254. echo " if [ -f ~/${PROJECT_NAME}-completed.txt ]; then" >> $rootdir/root/.bashrc
  255. # Remove the initial setup files
  256. echo ' rm /root/.initial_setup' >> $rootdir/root/.bashrc
  257. echo " rm /home/${MY_USERNAME}/.initial_setup" >> $rootdir/root/.bashrc
  258. echo " touch /root/.remove_${GENERIC_IMAGE_USERNAME}" >> $rootdir/root/.bashrc
  259. echo ' shred -zu ~/login.txt' >> $rootdir/root/.bashrc
  260. END_MESSAGE1=$'Congratulations!'
  261. if [[ $VARIANT != "mesh" ]]; then
  262. END_MESSAGE2=$'\nYour Freedombone system has now installed\n\nThe onion ssh service is at $SSH_ONION_HOSTNAME\n\nPress any key to reboot and begin using it'
  263. echo ' SSH_ONION_HOSTNAME=$(cat /var/lib/tor/hidden_service_ssh/hostname)' >> $rootdir/root/.bashrc
  264. else
  265. END_MESSAGE2=$'\nYour Freedombone system has now installed\n\nPress any key to reboot and begin using it'
  266. fi
  267. echo " dialog --title '$END_MESSAGE1' --msgbox \"$END_MESSAGE2\" 9 50" >> $rootdir/root/.bashrc
  268. echo ' reboot' >> $rootdir/root/.bashrc
  269. echo ' fi' >> $rootdir/root/.bashrc
  270. echo ' else' >> $rootdir/root/.bashrc
  271. echo ' key=' >> $rootdir/root/.bashrc
  272. echo ' while [[ $key != "x" ]]; do' >> $rootdir/root/.bashrc
  273. echo ' read -n1 -r -p "Press x to continue..." key' >> $rootdir/root/.bashrc
  274. echo ' done' >> $rootdir/root/.bashrc
  275. echo ' fi' >> $rootdir/root/.bashrc
  276. echo ' exit' >> $rootdir/root/.bashrc
  277. echo 'else' >> $rootdir/root/.bashrc
  278. echo ' # Remove default account after install' >> $rootdir/root/.bashrc
  279. echo " if [ -f /root/.remove_${GENERIC_IMAGE_USERNAME} ]; then" >> $rootdir/root/.bashrc
  280. echo " if [ -d /home/${GENERIC_IMAGE_USERNAME} ]; then" >> $rootdir/root/.bashrc
  281. echo " userdel -r ${GENERIC_IMAGE_USERNAME}" >> $rootdir/root/.bashrc
  282. echo " if [ -d /home/${GENERIC_IMAGE_USERNAME} ]; then" >> $rootdir/root/.bashrc
  283. echo " rm -rf /home/${GENERIC_IMAGE_USERNAME}" >> $rootdir/root/.bashrc
  284. echo " rm /root/.remove_${GENERIC_IMAGE_USERNAME}" >> $rootdir/root/.bashrc
  285. echo ' fi' >> $rootdir/root/.bashrc
  286. echo ' fi' >> $rootdir/root/.bashrc
  287. echo ' fi' >> $rootdir/root/.bashrc
  288. echo 'fi' >> $rootdir/root/.bashrc
  289. }
  290. continue_installation() {
  291. # If a configuration file exists then run with it
  292. # otherwise the interactive installer can be used
  293. # This is equivalent to installing freedombox-setup on freedombox
  294. if [ $CONFIG_FILENAME ]; then
  295. if [ ${#CONFIG_FILENAME} -gt 2 ]; then
  296. cp $CONFIG_FILENAME $rootdir/root/$PROJECT_NAME.cfg
  297. cat $rootdir/root/$PROJECT_NAME.cfg
  298. chroot "$rootdir" su -c "$PROJECT_NAME -c /root/$PROJECT_NAME.cfg" - root
  299. fi
  300. fi
  301. }
  302. atheros_wifi() {
  303. firmware_filename="open-ath9k-htc-firmware_1.3-1_all.deb"
  304. firmware_hash='5fea58ffefdf0ef15b504db7fbe3bc078c03e0d927bba64085e4b6f2546102f5'
  305. firmware_url="http://us.archive.trisquel.info/trisquel/pool/main/o/open-ath9k-htc-firmware/$firmware_filename"
  306. firmware_tempfile="/tmp/$firmware_filename"
  307. wget "$firmware_url" -O "$rootdir$firmware_tempfile"
  308. downloaded_firmware_hash=$(sha256sum "$rootdir$firmware_tempfile" | awk -F ' ' '{print $1}')
  309. if [[ "$downloaded_firmware_hash" == "$firmware_hash" ]]; then
  310. chroot "$rootdir" dpkg -i "$firmware_tempfile"
  311. else
  312. echo 'WARNING: Atheros Wifi firmware hash does not match. The driver has not been installed.'
  313. fi
  314. }
  315. initialise_mesh() {
  316. if [[ $VARIANT != "mesh" ]]; then
  317. return
  318. fi
  319. MESH_SERVICE='mesh-setup.service'
  320. MESH_SETUP_DAEMON=$rootdir/etc/systemd/system/$MESH_SERVICE
  321. echo '[Unit]' > $MESH_SETUP_DAEMON
  322. echo 'Description=Initial mesh router configuration' >> $MESH_SETUP_DAEMON
  323. echo 'After=syslog.target' >> $MESH_SETUP_DAEMON
  324. echo 'After=network.target' >> $MESH_SETUP_DAEMON
  325. echo '[Service]' >> $MESH_SETUP_DAEMON
  326. echo 'Type=simple' >> $MESH_SETUP_DAEMON
  327. echo 'User=root' >> $MESH_SETUP_DAEMON
  328. echo 'Group=root' >> $MESH_SETUP_DAEMON
  329. echo 'WorkingDirectory=/root' >> $MESH_SETUP_DAEMON
  330. echo "ExecStart=/usr/local/bin/${PROJECT_NAME}-image-mesh > /var/log/mesh-setup.log" >> $MESH_SETUP_DAEMON
  331. echo '' >> $MESH_SETUP_DAEMON
  332. echo 'TimeoutSec=99999' >> $MESH_SETUP_DAEMON
  333. echo '' >> $MESH_SETUP_DAEMON
  334. echo '[Install]' >> $MESH_SETUP_DAEMON
  335. echo 'WantedBy=multi-user.target' >> $MESH_SETUP_DAEMON
  336. chroot "$rootdir" systemctl enable $MESH_SERVICE
  337. }
  338. # Set to true/false to control if eatmydata is used during build
  339. use_eatmydata=true
  340. rootdir="$1"
  341. fmdir="$(pwd)"
  342. image="$fmdir"/"$2"
  343. cd "$rootdir"
  344. echo info: building $MACHINE for $ARCHITECTURE
  345. export DEBIAN_FRONTEND=noninteractive DEBCONF_NONINTERACTIVE_SEEN=true
  346. export LC_ALL=C LANGUAGE=C LANG=C
  347. # Override libpam-tmpdir setting during build, as the directories
  348. # are not created yet.
  349. export TMP=/tmp/ TMPDIR=/tmp/
  350. username=$MY_USERNAME
  351. echo $"warning: creating initial user $username with well known password!"
  352. password=$MY_PASSWORD
  353. chroot "$rootdir" adduser --gecos $username --disabled-password $username
  354. echo $username:$password | chroot $rootdir /usr/sbin/chpasswd
  355. chroot "$rootdir" adduser $username sudo
  356. case "$MACHINE" in
  357. virtualbox)
  358. # hide irrelevant console keyboard messages.
  359. echo "echo \"4 4 1 7\" > /proc/sys/kernel/printk" \
  360. >> /etc/init.d/rc.local
  361. ;;
  362. qemu)
  363. # hide irrelevant console keyboard messages.
  364. echo "echo \"4 4 1 7\" > /proc/sys/kernel/printk" \
  365. >> /etc/init.d/rc.local
  366. ;;
  367. esac
  368. set_apt_sources $BUILD_MIRROR
  369. chroot "$rootdir" apt-get update
  370. cat > $rootdir/usr/sbin/policy-rc.d <<EOF
  371. #!/bin/sh
  372. exit 101
  373. EOF
  374. chmod a+rx $rootdir/usr/sbin/policy-rc.d
  375. if $use_eatmydata ; then
  376. enable_eatmydata_override
  377. fi
  378. if [ -n "$CUSTOM_SETUP" ]; then
  379. cp "$CUSTOM_SETUP" "$rootdir"/tmp
  380. chroot "$rootdir" apt-get install -y gdebi-core
  381. chroot "$rootdir" gdebi -n /tmp/"$(basename $CUSTOM_SETUP)"
  382. fi
  383. chroot "$rootdir" apt-get install -y sudo git dialog toilet build-essential openssh-server
  384. chroot "$rootdir" apt-get install -y avahi-daemon avahi-utils avahi-discover avahi-autoipd
  385. chroot "$rootdir" apt-get install -y iptables dnsutils net-tools network-manager iputils-ping
  386. chroot "$rootdir" apt-get install -y libnss-mdns libnss-myhostname libnss-gw-name nano man ntp
  387. chroot "$rootdir" apt-get install -y locales locales-all debconf
  388. sed -i "s|#host-name=.*|host-name=${PROJECT_NAME}|g" $rootdir/etc/avahi/avahi-daemon.conf
  389. chroot "$rootdir" /bin/bash -x <<EOF
  390. git clone https://github.com/bashrc/freedombone /root/freedombone
  391. cd /root/freedombone
  392. make install
  393. EOF
  394. chroot "$rootdir" ${PROJECT_NAME}-image-hardware-setup 2>&1 | \
  395. tee $rootdir/var/log/${PROJECT_NAME}-image-hardware-setup.log
  396. rm $rootdir/usr/sbin/policy-rc.d
  397. # Set up HRNG for systems known to have one
  398. # Otherwise install haveged
  399. if [[ "$MACHINE" != "beaglebone" ]]; then
  400. chroot $rootdir apt-get -y install haveged
  401. else
  402. chroot $rootdir apt-get -y install rng-tools
  403. sed -i 's|#HRNGDEVICE=/dev/hwrng|HRNGDEVICE=/dev/hwrng|g' $rootdir/etc/default/rng-tools
  404. fi
  405. # copy u-boot to beginning of image
  406. case "$MACHINE" in
  407. beaglebone)
  408. dd if=$rootdir/usr/lib/u-boot/am335x_boneblack/MLO of="$image" \
  409. count=1 seek=1 conv=notrunc bs=128k
  410. dd if=$rootdir/usr/lib/u-boot/am335x_boneblack/u-boot.img of="$image" \
  411. count=2 seek=1 conv=notrunc bs=384k
  412. ;;
  413. cubieboard2)
  414. dd if=$rootdir/usr/lib/u-boot/Cubieboard2/u-boot-sunxi-with-spl.bin of="$image" \
  415. seek=8 conv=notrunc bs=1k
  416. ;;
  417. esac
  418. if $use_eatmydata ; then
  419. disable_eatmydata_override
  420. fi
  421. set_apt_sources $MIRROR
  422. chroot "$rootdir" apt-get update
  423. configure_ssh
  424. configure_networking
  425. admin_user_sudo
  426. create_generic_image
  427. atheros_wifi
  428. continue_installation
  429. initialise_mesh
  430. cd /
  431. echo $"info: killing leftover processes in chroot"
  432. fuser -mvk $rootdir/. || true