freedombone-image-customise 19KB

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