freedombone-image-customise 20KB

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