freedombone-image-customise 35KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834
  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. mesh_avahi() {
  329. chroot "$rootdir" apt-get -y install avahi-utils avahi-autoipd avahi-dnsconfd
  330. decarray=( 1 2 3 4 5 6 7 8 9 0 )
  331. PEER_ID=${decarray[$RANDOM%10]}${decarray[$RANDOM%10]}${decarray[$RANDOM%10]}${decarray[$RANDOM%10]}${decarray[$RANDOM%10]}${decarray[$RANDOM%10]}${decarray[$RANDOM%10]}${decarray[$RANDOM%10]}
  332. sed -i "s|#host-name=.*|host-name=P$PEER_ID|g" $rootdir/etc/avahi/avahi-daemon.conf
  333. if [ ! -d $rootdir/etc/avahi/services ]; then
  334. mkdir -p $rootdir/etc/avahi/services
  335. fi
  336. # remove an avahi service which isn't used
  337. if [ -f $rootdir/etc/avahi/services/udisks.service ]; then
  338. rm $rootdir/etc/avahi/services/udisks.service
  339. fi
  340. # Add an ssh service
  341. echo '<?xml version="1.0" standalone="no"?><!--*-nxml-*-->' > $rootdir/etc/avahi/services/ssh.service
  342. echo '<!DOCTYPE service-group SYSTEM "avahi-service.dtd">' >> $rootdir/etc/avahi/services/ssh.service
  343. echo '<service-group>' >> $rootdir/etc/avahi/services/ssh.service
  344. echo ' <name replace-wildcards="yes">%h SSH</name>' >> $rootdir/etc/avahi/services/ssh.service
  345. echo ' <service>' >> $rootdir/etc/avahi/services/ssh.service
  346. echo ' <type>_ssh._tcp</type>' >> $rootdir/etc/avahi/services/ssh.service
  347. echo " <port>$SSH_PORT</port>" >> $rootdir/etc/avahi/services/ssh.service
  348. echo ' </service>' >> $rootdir/etc/avahi/services/ssh.service
  349. echo '</service-group>' >> $rootdir/etc/avahi/services/ssh.service
  350. # keep the daemon running
  351. WATCHDOG_SCRIPT_NAME="keepon"
  352. echo '' >> $rootdir/usr/bin/$WATCHDOG_SCRIPT_NAME
  353. echo '# keep avahi daemon running' >> $rootdir/usr/bin/$WATCHDOG_SCRIPT_NAME
  354. echo 'AVAHI_RUNNING=$(pgrep avahi-daemon > /dev/null && echo Running)' >> $rootdir/usr/bin/$WATCHDOG_SCRIPT_NAME
  355. echo 'if [ ! $AVAHI_RUNNING ]; then' >> $rootdir/usr/bin/$WATCHDOG_SCRIPT_NAME
  356. echo ' systemctl start avahi-daemon' >> $rootdir/usr/bin/$WATCHDOG_SCRIPT_NAME
  357. echo ' echo -n $CURRENT_DATE >> $LOGFILE' >> $rootdir/usr/bin/$WATCHDOG_SCRIPT_NAME
  358. echo ' echo " Avahi daemon restarted" >> $LOGFILE' >> $rootdir/usr/bin/$WATCHDOG_SCRIPT_NAME
  359. echo 'fi' >> $rootdir/usr/bin/$WATCHDOG_SCRIPT_NAME
  360. chmod +x $rootdir/usr/bin/$WATCHDOG_SCRIPT_NAME
  361. }
  362. mesh_batman() {
  363. chroot "$rootdir" apt-get -y install iproute bridge-utils libnetfilter-conntrack3 batctl
  364. chroot "$rootdir" apt-get -y install python-dev libevent-dev ebtables python-pip git
  365. chroot "$rootdir" apt-get -y install wireless-tools rfkill
  366. if ! grep -q "batman_adv" $rootdir/etc/modules; then
  367. echo 'batman_adv' >> $rootdir/etc/modules
  368. fi
  369. if [ -f /usr/local/bin/${PROJECT_NAME}-mesh-batman ]; then
  370. cp /usr/local/bin/${PROJECT_NAME}-mesh-batman $rootdir/var/lib/batman
  371. else
  372. cp /usr/bin/${PROJECT_NAME}-mesh-batman $rootdir/var/lib/batman
  373. fi
  374. echo '[Unit]' > $rootdir/etc/systemd/system/batman.service
  375. echo 'Description=B.A.T.M.A.N. Advanced' >> $rootdir/etc/systemd/system/batman.service
  376. echo '' >> $rootdir/etc/systemd/system/batman.service
  377. echo '[Service]' >> $rootdir/etc/systemd/system/batman.service
  378. echo 'Type=oneshot' >> $rootdir/etc/systemd/system/batman.service
  379. echo "ExecStart=/var/lib/batman start" >> $rootdir/etc/systemd/system/batman.service
  380. echo "ExecStop=/var/lib/batman stop" >> $rootdir/etc/systemd/system/batman.service
  381. echo 'RemainAfterExit=yes' >> $rootdir/etc/systemd/system/batman.service
  382. echo '' >> $rootdir/etc/systemd/system/batman.service
  383. echo '# Allow time for the server to start/stop' >> $rootdir/etc/systemd/system/batman.service
  384. echo 'TimeoutSec=300' >> $rootdir/etc/systemd/system/batman.service
  385. echo '' >> $rootdir/etc/systemd/system/batman.service
  386. echo '[Install]' >> $rootdir/etc/systemd/system/batman.service
  387. echo 'WantedBy=multi-user.target' >> $rootdir/etc/systemd/system/batman.service
  388. chroot "$rootdir" systemctl enable batman
  389. }
  390. mesh_firewall() {
  391. TOX_PORT=33445
  392. ZERONET_PORT=15441
  393. FIREWALL_FILENAME=$rootdir/etc/systemd/system/meshfirewall.service
  394. MESH_FIREWALL_SCRIPT=/usr/bin/mesh-firewall
  395. echo '#!/bin/bash' > $rootdir/$MESH_FIREWALL_SCRIPT
  396. echo 'iptables -P INPUT ACCEPT' >> $rootdir/$MESH_FIREWALL_SCRIPT
  397. echo 'ip6tables -P INPUT ACCEPT' >> $rootdir/$MESH_FIREWALL_SCRIPT
  398. echo 'iptables -F' >> $rootdir/$MESH_FIREWALL_SCRIPT
  399. echo 'ip6tables -F' >> $rootdir/$MESH_FIREWALL_SCRIPT
  400. echo 'iptables -t nat -F' >> $rootdir/$MESH_FIREWALL_SCRIPT
  401. echo 'ip6tables -t nat -F' >> $rootdir/$MESH_FIREWALL_SCRIPT
  402. echo 'iptables -X' >> $rootdir/$MESH_FIREWALL_SCRIPT
  403. echo 'ip6tables -X' >> $rootdir/$MESH_FIREWALL_SCRIPT
  404. echo 'iptables -P INPUT DROP' >> $rootdir/$MESH_FIREWALL_SCRIPT
  405. echo 'ip6tables -P INPUT DROP' >> $rootdir/$MESH_FIREWALL_SCRIPT
  406. echo 'iptables -A INPUT -i lo -j ACCEPT' >> $rootdir/$MESH_FIREWALL_SCRIPT
  407. echo 'iptables -A INPUT -m conntrack --ctstate ESTABLISHED,RELATED -j ACCEPT' >> $rootdir/$MESH_FIREWALL_SCRIPT
  408. echo '' >> $rootdir/$MESH_FIREWALL_SCRIPT
  409. echo '# Make sure incoming tcp connections are SYN packets' >> $rootdir/$MESH_FIREWALL_SCRIPT
  410. echo 'iptables -A INPUT -p tcp ! --syn -m state --state NEW -j DROP' >> $rootdir/$MESH_FIREWALL_SCRIPT
  411. echo '' >> $rootdir/$MESH_FIREWALL_SCRIPT
  412. echo '# Drop packets with incoming fragments' >> $rootdir/$MESH_FIREWALL_SCRIPT
  413. echo 'iptables -A INPUT -f -j DROP' >> $rootdir/$MESH_FIREWALL_SCRIPT
  414. echo '' >> $rootdir/$MESH_FIREWALL_SCRIPT
  415. echo '# Drop bogons' >> $rootdir/$MESH_FIREWALL_SCRIPT
  416. echo 'iptables -A INPUT -p tcp --tcp-flags ALL ALL -j DROP' >> $rootdir/$MESH_FIREWALL_SCRIPT
  417. echo 'iptables -A INPUT -p tcp --tcp-flags ALL FIN,PSH,URG -j DROP' >> $rootdir/$MESH_FIREWALL_SCRIPT
  418. echo 'iptables -A INPUT -p tcp --tcp-flags ALL SYN,RST,ACK,FIN,URG -j DROP' >> $rootdir/$MESH_FIREWALL_SCRIPT
  419. echo '' >> $rootdir/$MESH_FIREWALL_SCRIPT
  420. echo '# Incoming malformed NULL packets:' >> $rootdir/$MESH_FIREWALL_SCRIPT
  421. echo 'iptables -A INPUT -p tcp --tcp-flags ALL NONE -j DROP' >> $rootdir/$MESH_FIREWALL_SCRIPT
  422. echo '' >> $rootdir/$MESH_FIREWALL_SCRIPT
  423. echo "iptables -A INPUT -p tcp --dport $TOX_PORT -j ACCEPT" >> $rootdir/$MESH_FIREWALL_SCRIPT
  424. echo "iptables -A INPUT -i $WIFI_INTERFACE -p udp --dport $ZERONET_PORT -j ACCEPT" >> $rootdir/$MESH_FIREWALL_SCRIPT
  425. echo "iptables -A INPUT -i $WIFI_INTERFACE -p tcp --dport $ZERONET_PORT -j ACCEPT" >> $rootdir/$MESH_FIREWALL_SCRIPT
  426. echo "iptables -A INPUT -i $WIFI_INTERFACE -p udp --dport $TRACKER_PORT -j ACCEPT" >> $rootdir/$MESH_FIREWALL_SCRIPT
  427. echo "iptables -A INPUT -i $WIFI_INTERFACE -p tcp --dport $TRACKER_PORT -j ACCEPT" >> $rootdir/$MESH_FIREWALL_SCRIPT
  428. echo "iptables -A INPUT -i $WIFI_INTERFACE -p udp --dport 1900 -j ACCEPT" >> $rootdir/$MESH_FIREWALL_SCRIPT
  429. chmod +x $rootdir/$MESH_FIREWALL_SCRIPT
  430. echo '[Unit]' > $FIREWALL_FILENAME
  431. echo 'Description=Mesh Firewall' >> $FIREWALL_FILENAME
  432. echo '' >> $FIREWALL_FILENAME
  433. echo '[Service]' >> $FIREWALL_FILENAME
  434. echo 'Type=oneshot' >> $FIREWALL_FILENAME
  435. echo "ExecStart=$MESH_FIREWALL_SCRIPT" >> $FIREWALL_FILENAME
  436. echo 'RemainAfterExit=no' >> $FIREWALL_FILENAME
  437. echo '' >> $FIREWALL_FILENAME
  438. echo 'TimeoutSec=30' >> $FIREWALL_FILENAME
  439. echo '' >> $FIREWALL_FILENAME
  440. echo '[Install]' >> $FIREWALL_FILENAME
  441. echo 'WantedBy=multi-user.target' >> $FIREWALL_FILENAME
  442. chroot "$rootdir" systemctl enable meshfirewall
  443. }
  444. mesh_tox_node() {
  445. TOX_REPO='git://github.com/irungentoo/toxcore.git'
  446. TOX_COMMIT='73b2144edcfd1ca617e9054479b66ab0c0361a14'
  447. # These are some default nodes, but you can replace them with trusted nodes
  448. # as you prefer. See https://wiki.tox.im/Nodes
  449. TOX_NODES=
  450. #TOX_NODES=(
  451. # '192.254.75.102,2607:5600:284::2,33445,951C88B7E75C867418ACDB5D273821372BB5BD652740BCDF623A4FA293E75D2F,Tox RELENG,US'
  452. # '144.76.60.215,2a01:4f8:191:64d6::1,33445,04119E835DF3E78BACF0F84235B300546AF8B936F035185E2A8E9E0A67C8924F,sonOfRa,DE'
  453. #)
  454. chroot "$rootdir" apt-get -y install build-essential libtool autotools-dev
  455. chroot "$rootdir" apt-get -y install automake checkinstall check git yasm
  456. chroot "$rootdir" apt-get -y install libsodium13 libsodium-dev libcap2-bin
  457. chroot "$rootdir" apt-get -y install libconfig9 libconfig-dev
  458. chroot "$rootdir" git clone $TOX_REPO $INSTALL_DIR/toxcore
  459. chroot "$rootdir" cd $INSTALL_DIR/toxcore
  460. chroot "$rootdir" git checkout $TOX_COMMIT -b $TOX_COMMIT
  461. chroot "$rootdir" autoreconf -i
  462. chroot "$rootdir" ./configure --enable-daemon
  463. chroot "$rootdir" make
  464. chroot "$rootdir" make install
  465. chroot "$rootdir" cp /usr/local/lib/libtoxcore* /usr/lib/
  466. if [ ! -f $rootdir/usr/local/bin/tox-bootstrapd ]; then
  467. echo $"File not found /usr/local/bin/tox-bootstrapd"
  468. return
  469. fi
  470. chroot "$rootdir" useradd --home-dir /var/lib/tox-bootstrapd --create-home --system --shell /sbin/nologin --comment $"Account to run Tox's DHT bootstrap daemon" --user-group tox-bootstrapd
  471. chroot "$rootdir" chmod 700 /var/lib/tox-bootstrapd
  472. if [ ! -f $rootdir/$INSTALL_DIR/toxcore/other/bootstrap_daemon/tox-bootstrapd.conf ]; then
  473. echo $"File not found $INSTALL_DIR/toxcore/other/bootstrap_daemon/tox-bootstrapd.conf"
  474. fi
  475. # remove Maildir
  476. if [ -d $rootdir/var/lib/tox-bootstrapd/Maildir ]; then
  477. rm -rf $rootdir/var/lib/tox-bootstrapd/Maildir
  478. fi
  479. # create configuration file
  480. echo "port = $TOX_PORT" > $rootdir/etc/tox-bootstrapd.conf
  481. echo 'keys_file_path = "/var/lib/tox-bootstrapd/keys"' >> $rootdir/etc/tox-bootstrapd.conf
  482. echo 'pid_file_path = "/var/run/tox-bootstrapd/tox-bootstrapd.pid"' >> $rootdir/etc/tox-bootstrapd.conf
  483. echo 'enable_ipv6 = true' >> $rootdir/etc/tox-bootstrapd.conf
  484. echo 'enable_ipv4_fallback = true' >> $rootdir/etc/tox-bootstrapd.conf
  485. echo 'enable_lan_discovery = true' >> $rootdir/etc/tox-bootstrapd.conf
  486. echo 'enable_tcp_relay = true' >> $rootdir/etc/tox-bootstrapd.conf
  487. echo "tcp_relay_ports = [443, 3389, $TOX_PORT]" >> $rootdir/etc/tox-bootstrapd.conf
  488. echo 'enable_motd = true' >> $rootdir/etc/tox-bootstrapd.conf
  489. echo 'motd = "tox-bootstrapd"' >> $rootdir/etc/tox-bootstrapd.conf
  490. if [ $TOX_NODES ]; then
  491. echo 'bootstrap_nodes = (' >> $rootdir/etc/tox-bootstrapd.conf
  492. toxcount=0
  493. while [ "x${TOX_NODES[toxcount]}" != "x" ]
  494. do
  495. toxval_ipv4=$(echo $TOX_NODES[toxcount] | awk -F ',' '{print $1}')
  496. toxval_ipv6=$(echo $TOX_NODES[toxcount] | awk -F ',' '{print $2}')
  497. toxval_port=$(echo $TOX_NODES[toxcount] | awk -F ',' '{print $3}')
  498. toxval_pubkey=$(echo $TOX_NODES[toxcount] | awk -F ',' '{print $4}')
  499. toxval_maintainer=$(echo $TOX_NODES[toxcount] | awk -F ',' '{print $5}')
  500. echo "{ // $toxval_maintainer" >> $rootdir/etc/tox-bootstrapd.conf
  501. if [[ $toxval_ipv6 != 'NONE' ]]; then
  502. echo " address = \"$toxval_ipv6\"" >> $rootdir/etc/tox-bootstrapd.conf
  503. else
  504. echo " address = \"$toxval_ipv4\"" >> $rootdir/etc/tox-bootstrapd.conf
  505. fi
  506. echo " port = $toxval_port" >> $rootdir/etc/tox-bootstrapd.conf
  507. echo " public_key = \"$toxval_pubkey\"" >> $rootdir/etc/tox-bootstrapd.conf
  508. toxcount=$(( $toxcount + 1 ))
  509. if [ "x${TOX_NODES[toxcount]}" != "x" ]; then
  510. echo "}," >> $rootdir/etc/tox-bootstrapd.conf
  511. else
  512. echo "}" >> $rootdir/etc/tox-bootstrapd.conf
  513. fi
  514. done
  515. echo ')' >> $rootdir/etc/tox-bootstrapd.conf
  516. fi
  517. if [ ! -f $rootdir/$INSTALL_DIR/toxcore/other/bootstrap_daemon/tox-bootstrapd.service ]; then
  518. echo $"File not found $INSTALL_DIR/toxcore/other/bootstrap_daemon/tox-bootstrapd.service"
  519. fi
  520. cp $rootdir/$INSTALL_DIR/toxcore/other/bootstrap_daemon/tox-bootstrapd.service $rootdir/etc/systemd/system/
  521. chroot "$rootdir" systemctl enable tox-bootstrapd.service
  522. }
  523. function mesh_tox_client {
  524. chroot "$rootdir" apt-get -y install libncursesw5-dev libconfig-dev libqrencode-dev libcurl4-openssl-dev
  525. chroot "$rootdir" git clone $TOXIC_REPO $INSTALL_DIR/toxic
  526. chroot "$rootdir" cd $INSTALL_DIR/toxic
  527. chroot "$rootdir" git checkout $TOXIC_COMMIT -b $TOXIC_COMMIT
  528. echo "Toxic commit:$TOXIC_COMMIT" >> $rootdir$COMPLETION_FILE
  529. chroot "$rootdir" make
  530. chroot "$rootdir" make install
  531. }
  532. function mesh_zeronet {
  533. ZERONET_REPO='https://github.com/HelloZeroNet/ZeroNet.git'
  534. ZERONET_COMMIT='675bd462556c541d65e2d95f91f899146a373aad'
  535. chroot "$rootdir" apt-get -y install python python-msgpack python-gevent
  536. chroot "$rootdir" apt-get -y install python-pip bittornado
  537. chroot "$rootdir" pip install msgpack-python --upgrade
  538. chroot "$rootdir" useradd -d /opt/zeronet/ -s /bin/false zeronet
  539. git clone $ZERONET_REPO $rootdir/opt/zeronet
  540. if [ ! -d $rootdir/opt/zeronet ]; then
  541. echo 'WARNING: Unable to clone zeronet'
  542. return
  543. fi
  544. cd $rootdir/opt/zeronet
  545. git checkout $ZERONET_COMMIT -b $ZERONET_COMMIT
  546. echo "ZeroNet commit:$ZERONET_COMMIT" >> $rootdir$COMPLETION_FILE
  547. chown -R zeronet:zeronet $rootdir/opt/zeronet
  548. # Hack to ensure that the file access port is opened
  549. # This is because zeronet normally relies on an internet site
  550. # to do this, but on a purely local mesh the internet isn't available
  551. sed -i 's|fileserver_port = 0|fileserver_port = config.fileserver_port\n sys.modules["main"].file_server.port_opened = True|g' $rootdir/opt/zeronet/src/Site/Site.py
  552. echo '[Unit]' > $rootdir/etc/systemd/system/zeronet.service
  553. echo 'Description=Zeronet Server' >> $rootdir/etc/systemd/system/zeronet.service
  554. echo 'After=syslog.target' >> $rootdir/etc/systemd/system/zeronet.service
  555. echo 'After=network.target' >> $rootdir/etc/systemd/system/zeronet.service
  556. echo '[Service]' >> $rootdir/etc/systemd/system/zeronet.service
  557. echo 'Type=simple' >> $rootdir/etc/systemd/system/zeronet.service
  558. echo 'User=zeronet' >> $rootdir/etc/systemd/system/zeronet.service
  559. echo 'Group=zeronet' >> $rootdir/etc/systemd/system/zeronet.service
  560. echo 'WorkingDirectory=/opt/zeronet' >> $rootdir/etc/systemd/system/zeronet.service
  561. echo 'ExecStart=/usr/bin/python zeronet.py --ip_external replace.local --trackers_file /opt/zeronet/bootstrap' >> $rootdir/etc/systemd/system/zeronet.service
  562. echo '' >> $rootdir/etc/systemd/system/zeronet.service
  563. echo 'TimeoutSec=300' >> $rootdir/etc/systemd/system/zeronet.service
  564. echo '' >> $rootdir/etc/systemd/system/zeronet.service
  565. echo '[Install]' >> $rootdir/etc/systemd/system/zeronet.service
  566. echo 'WantedBy=multi-user.target' >> $rootdir/etc/systemd/system/zeronet.service
  567. echo '[Unit]' > $rootdir/etc/systemd/system/tracker.service
  568. echo 'Description=Torrent Tracker' >> $rootdir/etc/systemd/system/tracker.service
  569. echo 'After=syslog.target' >> $rootdir/etc/systemd/system/tracker.service
  570. echo 'After=network.target' >> $rootdir/etc/systemd/system/tracker.service
  571. echo '[Service]' >> $rootdir/etc/systemd/system/tracker.service
  572. echo 'Type=simple' >> $rootdir/etc/systemd/system/tracker.service
  573. echo 'User=tracker' >> $rootdir/etc/systemd/system/tracker.service
  574. echo 'Group=tracker' >> $rootdir/etc/systemd/system/tracker.service
  575. echo 'WorkingDirectory=/opt/tracker' >> $rootdir/etc/systemd/system/tracker.service
  576. echo "ExecStart=/usr/bin/bttrack --port $TRACKER_PORT --dfile /opt/tracker/dstate --logfile /opt/tracker/tracker.log --nat_check 0 --scrape_allowed full --ipv6_enabled 0" >> $rootdir/etc/systemd/system/tracker.service
  577. echo '' >> $rootdir/etc/systemd/system/tracker.service
  578. echo 'TimeoutSec=300' >> $rootdir/etc/systemd/system/tracker.service
  579. echo '' >> $rootdir/etc/systemd/system/tracker.service
  580. echo '[Install]' >> $rootdir/etc/systemd/system/tracker.service
  581. echo 'WantedBy=multi-user.target' >> $rootdir/etc/systemd/system/tracker.service
  582. chroot "$rootdir" useradd -d /opt/tracker/ -s /bin/false tracker
  583. if [ ! -d $rootdir/opt/tracker ]; then
  584. mkdir $rootdir/opt/tracker
  585. fi
  586. chown -R tracker:tracker $rootdir/opt/tracker
  587. # publish regularly
  588. echo "* * * * * root zeronetavahi > /dev/null" >> $rootdir/etc/crontab
  589. chroot "$rootdir" systemctl enable tracker.service
  590. chroot "$rootdir" systemctl enable zeronet.service
  591. }
  592. initialise_mesh() {
  593. if [[ $VARIANT != "mesh" ]]; then
  594. return
  595. fi
  596. mesh_firewall
  597. mesh_avahi
  598. mesh_batman
  599. mesh_tox_node
  600. mesh_tox_client
  601. mesh_zeronet
  602. MESH_SERVICE='mesh-setup.service'
  603. MESH_SETUP_DAEMON=$rootdir/etc/systemd/system/$MESH_SERVICE
  604. echo '[Unit]' > $MESH_SETUP_DAEMON
  605. echo 'Description=Initial mesh router configuration' >> $MESH_SETUP_DAEMON
  606. echo 'After=syslog.target' >> $MESH_SETUP_DAEMON
  607. echo 'After=network.target' >> $MESH_SETUP_DAEMON
  608. echo '[Service]' >> $MESH_SETUP_DAEMON
  609. echo 'Type=simple' >> $MESH_SETUP_DAEMON
  610. echo 'User=root' >> $MESH_SETUP_DAEMON
  611. echo 'Group=root' >> $MESH_SETUP_DAEMON
  612. echo 'WorkingDirectory=/root' >> $MESH_SETUP_DAEMON
  613. echo "ExecStart=/usr/local/bin/${PROJECT_NAME}-image-mesh > /var/log/mesh-setup.log" >> $MESH_SETUP_DAEMON
  614. echo '' >> $MESH_SETUP_DAEMON
  615. echo 'TimeoutSec=99999' >> $MESH_SETUP_DAEMON
  616. echo '' >> $MESH_SETUP_DAEMON
  617. echo '[Install]' >> $MESH_SETUP_DAEMON
  618. echo 'WantedBy=multi-user.target' >> $MESH_SETUP_DAEMON
  619. chroot "$rootdir" systemctl enable $MESH_SERVICE
  620. }
  621. # Set to true/false to control if eatmydata is used during build
  622. use_eatmydata=true
  623. rootdir="$1"
  624. fmdir="$(pwd)"
  625. image="$fmdir"/"$2"
  626. cd "$rootdir"
  627. echo info: building $MACHINE for $ARCHITECTURE
  628. export DEBIAN_FRONTEND=noninteractive DEBCONF_NONINTERACTIVE_SEEN=true
  629. export LC_ALL=C LANGUAGE=C LANG=C
  630. # Override libpam-tmpdir setting during build, as the directories
  631. # are not created yet.
  632. export TMP=/tmp/ TMPDIR=/tmp/
  633. username=$MY_USERNAME
  634. echo $"warning: creating initial user $username with well known password!"
  635. password=$MY_PASSWORD
  636. chroot "$rootdir" adduser --gecos $username --disabled-password $username
  637. echo $username:$password | chroot $rootdir /usr/sbin/chpasswd
  638. chroot "$rootdir" adduser $username sudo
  639. case "$MACHINE" in
  640. virtualbox)
  641. # hide irrelevant console keyboard messages.
  642. echo "echo \"4 4 1 7\" > /proc/sys/kernel/printk" \
  643. >> /etc/init.d/rc.local
  644. ;;
  645. qemu)
  646. # hide irrelevant console keyboard messages.
  647. echo "echo \"4 4 1 7\" > /proc/sys/kernel/printk" \
  648. >> /etc/init.d/rc.local
  649. ;;
  650. esac
  651. set_apt_sources $BUILD_MIRROR
  652. chroot "$rootdir" apt-get clean
  653. chroot "$rootdir" rm -rf /var/lib/apt/lists/*
  654. chroot "$rootdir" apt-get clean
  655. chroot "$rootdir" apt-get update
  656. cat > $rootdir/usr/sbin/policy-rc.d <<EOF
  657. #!/bin/sh
  658. exit 101
  659. EOF
  660. chmod a+rx $rootdir/usr/sbin/policy-rc.d
  661. if $use_eatmydata ; then
  662. enable_eatmydata_override
  663. fi
  664. if [ -n "$CUSTOM_SETUP" ]; then
  665. cp "$CUSTOM_SETUP" "$rootdir"/tmp
  666. chroot "$rootdir" apt-get install -y gdebi-core
  667. chroot "$rootdir" gdebi -n /tmp/"$(basename $CUSTOM_SETUP)"
  668. fi
  669. chroot "$rootdir" apt-get install -y sudo git dialog toilet build-essential openssh-server
  670. chroot "$rootdir" apt-get install -y avahi-daemon avahi-utils avahi-discover avahi-autoipd
  671. chroot "$rootdir" apt-get install -y iptables dnsutils net-tools network-manager iputils-ping
  672. chroot "$rootdir" apt-get install -y libnss-mdns libnss-myhostname libnss-gw-name nano man ntp
  673. chroot "$rootdir" apt-get install -y locales locales-all debconf
  674. sed -i "s|#host-name=.*|host-name=${PROJECT_NAME}|g" $rootdir/etc/avahi/avahi-daemon.conf
  675. chroot "$rootdir" /bin/bash -x <<EOF
  676. git clone $PROJECT_REPO /root/$PROJECT_NAME
  677. cd /root/$PROJECT_NAME
  678. make install
  679. EOF
  680. chroot "$rootdir" ${PROJECT_NAME}-image-hardware-setup 2>&1 | \
  681. tee $rootdir/var/log/${PROJECT_NAME}-image-hardware-setup.log
  682. rm $rootdir/usr/sbin/policy-rc.d
  683. # Set up HRNG for systems known to have one
  684. # Otherwise install haveged
  685. if [[ "$MACHINE" != "beaglebone" ]]; then
  686. chroot $rootdir apt-get -y install haveged
  687. else
  688. chroot $rootdir apt-get -y install rng-tools
  689. sed -i 's|#HRNGDEVICE=/dev/hwrng|HRNGDEVICE=/dev/hwrng|g' $rootdir/etc/default/rng-tools
  690. fi
  691. # copy u-boot to beginning of image
  692. case "$MACHINE" in
  693. beaglebone)
  694. dd if=$rootdir/usr/lib/u-boot/am335x_boneblack/MLO of="$image" \
  695. count=1 seek=1 conv=notrunc bs=128k
  696. dd if=$rootdir/usr/lib/u-boot/am335x_boneblack/u-boot.img of="$image" \
  697. count=2 seek=1 conv=notrunc bs=384k
  698. ;;
  699. cubieboard2)
  700. dd if=$rootdir/usr/lib/u-boot/Cubieboard2/u-boot-sunxi-with-spl.bin of="$image" \
  701. seek=8 conv=notrunc bs=1k
  702. ;;
  703. a20-olinuxino-lime)
  704. dd if=$rootdir/usr/lib/u-boot/A20-OLinuXino-Lime/u-boot-sunxi-with-spl.bin \
  705. of="$image" seek=8 conv=notrunc bs=1k
  706. ;;
  707. esac
  708. if $use_eatmydata ; then
  709. disable_eatmydata_override
  710. fi
  711. set_apt_sources $MIRROR
  712. chroot "$rootdir" apt-get update
  713. configure_ssh
  714. configure_networking
  715. admin_user_sudo
  716. create_generic_image
  717. atheros_wifi
  718. continue_installation
  719. initialise_mesh
  720. cd /
  721. echo $"info: killing leftover processes in chroot"
  722. fuser -mvk $rootdir/. || true