freedombone-image-customise 46KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241
  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. VARIANT='full'
  35. # username created by default within a debian image
  36. GENERIC_IMAGE_USERNAME='fbone'
  37. export TEXTDOMAIN=${PROJECT_NAME}-image-customise
  38. export TEXTDOMAINDIR="/usr/share/locale"
  39. # Whether to minimise the number of decisions during interactive install
  40. MINIMAL_INSTALL="yes"
  41. MY_USERNAME='debian'
  42. MY_PASSWORD="${PROJECT_NAME}"
  43. # Minimum number of characters in a password
  44. MINIMUM_PASSWORD_LENGTH=10
  45. # IP address of the router (gateway)
  46. ROUTER_IP_ADDRESS="192.168.1.254"
  47. # The fixed IP address of the Beaglebone Black on your local network
  48. BOX_IP_ADDRESS="192.168.1.55"
  49. # DNS
  50. NAMESERVER1='213.73.91.35'
  51. NAMESERVER2='85.214.20.141'
  52. # optional configuration file containing freedombone settings
  53. CONFIG_FILENAME=
  54. # Optional ssh public key to allow
  55. SSH_PUBKEY="no"
  56. # Whether this is a generic image for mass redistribution on the interwebs
  57. GENERIC_IMAGE="no"
  58. # default SSH port
  59. SSH_PORT=2222
  60. # for mesh installs
  61. TRACKER_PORT=6969
  62. # Whether sites are accessible only within a Tor browser
  63. ONION_ONLY="no"
  64. # Whether to only install debian and nothing else
  65. DEBIAN_INSTALL_ONLY="no"
  66. # wifi settings
  67. WIFI_INTERFACE='wlan0'
  68. WIFI_SSID=
  69. WIFI_TYPE='wpa2-psk'
  70. WIFI_PASSPHRASE=
  71. WIFI_HOTSPOT='no'
  72. WIFI_NETWORKS_FILE=~/${PROJECT_NAME}-wifi.cfg
  73. # Whether to install non-free wifi drivers for the mesh client
  74. INSECURE='no'
  75. enable_eatmydata_override() {
  76. chroot $rootdir apt-get install --no-install-recommends -y eatmydata
  77. if [ -x $rootdir/usr/bin/eatmydata ] && \
  78. [ ! -f $rootdir/etc/apt/apt.conf.d/95debian-edu-install-dpkg-eatmydata ]; then
  79. echo $"info: Adding apt config to call dpkg via eatmydata"
  80. printf "#!/bin/sh\nexec eatmydata dpkg \"\$@\"\n" \
  81. > $rootdir/var/tmp/dpkg-eatmydata
  82. chmod 755 $rootdir/var/tmp/dpkg-eatmydata
  83. cat > $rootdir/etc/apt/apt.conf.d/95debian-edu-install-dpkg-eatmydata <<EOF
  84. Dir::Bin::dpkg "/var/tmp/dpkg-eatmydata";
  85. EOF
  86. else
  87. echo $"error: unable to find /usr/bin/eatmydata after installing the eatmydata package"
  88. fi
  89. }
  90. disable_eatmydata_override() {
  91. for override in \
  92. /etc/apt/apt.conf.d/95debian-edu-install-dpkg-eatmydata \
  93. /var/tmp/dpkg-eatmydata ; do
  94. echo $"info: Removing apt config to call dpkg via eatmydata"
  95. if [ -f $rootdir$override ] ; then
  96. rm -f $rootdir$override
  97. else
  98. echo $"warning: missing $rootdir$override"
  99. fi
  100. done
  101. sync # Flush file buffers before continuing
  102. }
  103. set_apt_sources() {
  104. NEW_MIRROR="$1"
  105. COMPONENTS="main"
  106. cat <<EOF > etc/apt/sources.list
  107. deb $NEW_MIRROR $SUITE $COMPONENTS
  108. deb-src $NEW_MIRROR $SUITE $COMPONENTS
  109. #deb http://security.debian.org/ $SUITE/updates main
  110. #deb-src http://security.debian.org/ $SUITE/updates main
  111. EOF
  112. }
  113. configure_networking() {
  114. if [[ $DEBIAN_INSTALL_ONLY != "no" ]]; then
  115. return
  116. fi
  117. if [[ $GENERIC_IMAGE == "no" ]]; then
  118. echo "# This file describes the network interfaces available on your system
  119. # and how to activate them. For more information, see interfaces(5).
  120. # The loopback network interface
  121. auto lo
  122. iface lo inet loopback
  123. # The primary network interface
  124. auto eth0
  125. iface eth0 inet static
  126. address $BOX_IP_ADDRESS
  127. netmask 255.255.255.0
  128. gateway $ROUTER_IP_ADDRESS
  129. dns-nameservers $NAMESERVER1 $NAMESERVER2
  130. # Example to keep MAC address between reboots
  131. #hwaddress ether B5:A2:BE:3F:1A:FE
  132. # The secondary network interface
  133. #auto eth1
  134. #iface eth1 inet dhcp
  135. # WiFi Example
  136. #auto wlan0
  137. #iface wlan0 inet dhcp
  138. # wpa-ssid \"essid\"
  139. # wpa-psk \"password\"
  140. # Ethernet/RNDIS gadget (g_ether)
  141. # ... or on host side, usbnet and random hwaddr
  142. # Note on some boards, usb0 is automaticly setup with an init script
  143. #iface usb0 inet static
  144. # address 192.168.7.2
  145. # netmask 255.255.255.0
  146. # network 192.168.7.0
  147. # gateway 192.168.7.1" > $rootdir/etc/network/interfaces
  148. hexarray=( 1 2 3 4 5 6 7 8 9 0 a b c d e f )
  149. a=${hexarray[$RANDOM%16]}${hexarray[$RANDOM%16]}
  150. b=${hexarray[$RANDOM%16]}${hexarray[$RANDOM%16]}
  151. c=${hexarray[$RANDOM%16]}${hexarray[$RANDOM%16]}
  152. d=${hexarray[$RANDOM%16]}${hexarray[$RANDOM%16]}
  153. e=${hexarray[$RANDOM%16]}${hexarray[$RANDOM%16]}
  154. sed -i "s|#hwaddress ether.*|hwaddress ether de:$a:$b:$c:$d:$e|g" \
  155. $rootdir/etc/network/interfaces
  156. fi
  157. sed -i "s/nameserver.*/nameserver $NAMESERVER1/g" $rootdir/etc/resolv.conf
  158. sed -i "/nameserver $NAMESERVER1/a\nameserver $NAMESERVER2" $rootdir/etc/resolv.conf
  159. # change the motd to show further install instructions
  160. echo $"
  161. .---. . .
  162. | | |
  163. |--- .--. .-. .-. .-.| .-. .--.--. |.-. .-. .--. .-.
  164. | | (.-' (.-' ( | ( )| | | | )( )| | (.-'
  165. ' ' --' --' -' - -' ' ' -' -' -' ' - --'
  166. Initial base install
  167. Your system is not yet installed. To complete the process run the
  168. following commands, then enter your details.
  169. sudo su
  170. ${PROJECT_NAME} menuconfig
  171. " > $rootdir/etc/motd
  172. }
  173. configure_ssh() {
  174. sed -i "s/Port .*/Port ${SSH_PORT}/g" $rootdir/etc/ssh/sshd_config
  175. if [[ "$SSH_PUBKEY" != "no" ]]; then
  176. if [ ! -d $rootdir/home/$MY_USERNAME/.ssh ]; then
  177. mkdir $rootdir/home/$MY_USERNAME/.ssh
  178. fi
  179. echo "$SSH_PUBKEY" > $rootdir/home/$MY_USERNAME/.ssh/authorized_keys
  180. chroot $rootdir chown -R $MY_USERNAME:$MY_USERNAME /home/$MY_USERNAME/.ssh
  181. sed -i 's|PasswordAuthentication.*|PasswordAuthentication no|g' $rootdir/etc/ssh/sshd_config
  182. echo $"Using ssh public key:"
  183. echo $SSH_PUBKEY
  184. echo $'Password ssh authentication turned off'
  185. fi
  186. }
  187. admin_user_sudo() {
  188. echo "$MY_USERNAME ALL=(ALL) ALL" >> $rootdir/etc/sudoers
  189. }
  190. create_generic_image() {
  191. if [[ $DEBIAN_INSTALL_ONLY != "no" ]]; then
  192. return
  193. fi
  194. if [[ $GENERIC_IMAGE == "no" ]]; then
  195. return
  196. fi
  197. if [ $CONFIG_FILENAME ]; then
  198. if [[ "$CONFIG_FILENAME" == *"mesh.cfg"* ]]; then
  199. VARIANT="mesh"
  200. fi
  201. fi
  202. # Don't install any configuration. This will be a base system
  203. if [[ $VARIANT != "mesh" && $VARIANT != "meshclient" && $VARIANT != "meshusb" ]]; then
  204. CONFIG_FILENAME=
  205. else
  206. touch $rootdir/root/.initial_mesh_setup
  207. fi
  208. # The presence of this file indicates that the initial
  209. # setup has not yet been completed
  210. touch $rootdir/home/$MY_USERNAME/.initial_setup
  211. chroot $rootdir chown $MY_USERNAME:$MY_USERNAME /home/$MY_USERNAME/.initial_setup
  212. touch $rootdir/root/.initial_setup
  213. cat >> $rootdir/home/$MY_USERNAME/.bashrc <<EOF
  214. # initial setup of the system
  215. if [ -f ~/.initial_setup ]; then
  216. clear
  217. echo "
  218. .---. . .
  219. | | |
  220. |--- .--. .-. .-. .-.| .-. .--.--. |.-. .-. .--. .-.
  221. | | (.-' (.-' ( | ( )| | | | )( )| | (.-'
  222. ' ' --' --' -' - -' ' ' -' -' -' ' - --'
  223. Initial setup process
  224. Please enter your password a second time.
  225. "
  226. sudo su
  227. fi
  228. EOF
  229. echo '# initial setup of the system' >> $rootdir/root/.bashrc
  230. echo 'if [ -f ~/.initial_setup ]; then' >> $rootdir/root/.bashrc
  231. echo ' if [ -f ~/login.txt ]; then' >> $rootdir/root/.bashrc
  232. echo ' NEW_USER_PASSWORD=$(printf `cat ~/login.txt`)' >> $rootdir/root/.bashrc
  233. echo ' else' >> $rootdir/root/.bashrc
  234. echo ' ENTROPY=$(cat /proc/sys/kernel/random/entropy_avail)' >> $rootdir/root/.bashrc
  235. echo ' if [ $ENTROPY -lt 500 ]; then' >> $rootdir/root/.bashrc
  236. ENTROPY_MESSAGE1=$'Initial setup process'
  237. ENTROPY_MESSAGE2=$'Password Generation'
  238. ENTROPY_MESSAGE3=$'WARNING: The entropy available on this system is too low to generate a password.\n\nThe installation process cannot continue.'
  239. echo " dialog --backtitle \"${ENTROPY_MESSAGE1}\" --title \"${ENTROPY_MESSAGE2}\" --msgbox \"${ENTROPY_MESSAGE3}\" 8 50" >> $rootdir/root/.bashrc
  240. echo ' exit' >> $rootdir/root/.bashrc
  241. echo ' fi' >> $rootdir/root/.bashrc
  242. echo -n ' NEW_USER_PASSWORD="$(openssl rand -base64 30 | cut -c1-' >> $rootdir/root/.bashrc
  243. echo "${MINIMUM_PASSWORD_LENGTH})\"" >> $rootdir/root/.bashrc
  244. echo ' fi' >> $rootdir/root/.bashrc
  245. echo ' echo "${NEW_USER_PASSWORD}" > ~/login.txt' >> $rootdir/root/.bashrc
  246. echo ' clear' >> $rootdir/root/.bashrc
  247. echo ' echo ""' >> $rootdir/root/.bashrc
  248. NEW_LOGIN_PASSWORD_MESSAGE1=$'Your new login password is:'
  249. NEW_LOGIN_PASSWORD_MESSAGE2=$'Use it whenever you wish to ssh into this system.'
  250. NEW_LOGIN_PASSWORD_MESSAGE3=$'IMPORTANT: Please take a moment to enter the above password into a\npassword manager or write it down somewhere.'
  251. PRESS_KEY_MESSAGE=$'Press any key to continue...'
  252. echo " echo \"${NEW_LOGIN_PASSWORD_MESSAGE1}\"" >> $rootdir/root/.bashrc
  253. echo ' echo ""' >> $rootdir/root/.bashrc
  254. echo ' toilet "${NEW_USER_PASSWORD}"' >> $rootdir/root/.bashrc
  255. echo ' echo ""' >> $rootdir/root/.bashrc
  256. echo ' echo " ${NEW_USER_PASSWORD}"' >> $rootdir/root/.bashrc
  257. echo ' echo ""' >> $rootdir/root/.bashrc
  258. echo " echo \"${NEW_LOGIN_PASSWORD_MESSAGE2}\"" >> $rootdir/root/.bashrc
  259. echo ' echo ""' >> $rootdir/root/.bashrc
  260. echo " echo \"${NEW_LOGIN_PASSWORD_MESSAGE3}\"" >> $rootdir/root/.bashrc
  261. echo ' echo ""' >> $rootdir/root/.bashrc
  262. echo " read -n1 -r -p \"${PRESS_KEY_MESSAGE}\" key" >> $rootdir/root/.bashrc
  263. # change the password for the admin user
  264. echo -n " echo \"${MY_USERNAME}:" >> $rootdir/root/.bashrc
  265. echo '$(printf `cat ~/login.txt`)"|chpasswd' >> $rootdir/root/.bashrc
  266. # update before continuing
  267. echo " cd /root/${PROJECT_NAME}" >> $rootdir/root/.bashrc
  268. echo " git stash" >> $rootdir/root/.bashrc
  269. echo " git pull" >> $rootdir/root/.bashrc
  270. echo " make install" >> $rootdir/root/.bashrc
  271. if [[ $VARIANT != "mesh" && $VARIANT != "meshclient" && $VARIANT != "meshusb" && $VARIANT != "usb" ]]; then
  272. if [[ $ONION_ONLY == "no" ]]; then
  273. if [[ $MINIMAL_INSTALL == "no" ]]; then
  274. echo " ${PROJECT_NAME} menuconfig-full" >> $rootdir/root/.bashrc
  275. else
  276. echo " ${PROJECT_NAME} menuconfig" >> $rootdir/root/.bashrc
  277. fi
  278. else
  279. echo " ${PROJECT_NAME} menuconfig-onion" >> $rootdir/root/.bashrc
  280. fi
  281. else
  282. echo " echo ''" >> $rootdir/root/.bashrc
  283. fi
  284. echo ' if [ "$?" = "0" ]; then' >> $rootdir/root/.bashrc
  285. echo " if [ -f ~/${PROJECT_NAME}-completed.txt ]; then" >> $rootdir/root/.bashrc
  286. # Remove the initial setup files
  287. echo ' rm /root/.initial_setup' >> $rootdir/root/.bashrc
  288. echo " rm /home/${MY_USERNAME}/.initial_setup" >> $rootdir/root/.bashrc
  289. echo " touch /root/.remove_${GENERIC_IMAGE_USERNAME}" >> $rootdir/root/.bashrc
  290. echo ' shred -zu ~/login.txt' >> $rootdir/root/.bashrc
  291. END_MESSAGE1=$'Congratulations!'
  292. if [[ $VARIANT != "mesh" && $VARIANT != "meshclient" && $VARIANT != "meshusb" && $VARIANT != "usb" ]]; then
  293. 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'
  294. echo ' SSH_ONION_HOSTNAME=$(cat /var/lib/tor/hidden_service_ssh/hostname)' >> $rootdir/root/.bashrc
  295. else
  296. END_MESSAGE2=$'\nYour system has now installed\n\nPress any key to reboot and begin using it'
  297. fi
  298. echo " dialog --title '$END_MESSAGE1' --msgbox \"$END_MESSAGE2\" 9 50" >> $rootdir/root/.bashrc
  299. echo ' reboot' >> $rootdir/root/.bashrc
  300. echo ' fi' >> $rootdir/root/.bashrc
  301. echo ' else' >> $rootdir/root/.bashrc
  302. echo ' key=' >> $rootdir/root/.bashrc
  303. echo ' while [[ $key != "x" ]]; do' >> $rootdir/root/.bashrc
  304. INSTALL_FAIL_MESSAGE=$"Install failed. Press x to continue..."
  305. echo " read -n1 -r -p \"${INSTALL_FAIL_MESSAGE}\" key" >> $rootdir/root/.bashrc
  306. echo ' done' >> $rootdir/root/.bashrc
  307. echo ' fi' >> $rootdir/root/.bashrc
  308. echo ' exit' >> $rootdir/root/.bashrc
  309. echo 'else' >> $rootdir/root/.bashrc
  310. echo ' # Remove default account after install' >> $rootdir/root/.bashrc
  311. echo " if [ -f /root/.remove_${GENERIC_IMAGE_USERNAME} ]; then" >> $rootdir/root/.bashrc
  312. echo " if [ -d /home/${GENERIC_IMAGE_USERNAME} ]; then" >> $rootdir/root/.bashrc
  313. echo " userdel -r ${GENERIC_IMAGE_USERNAME}" >> $rootdir/root/.bashrc
  314. echo " if [ -d /home/${GENERIC_IMAGE_USERNAME} ]; then" >> $rootdir/root/.bashrc
  315. echo " rm -rf /home/${GENERIC_IMAGE_USERNAME}" >> $rootdir/root/.bashrc
  316. echo " rm /root/.remove_${GENERIC_IMAGE_USERNAME}" >> $rootdir/root/.bashrc
  317. echo ' fi' >> $rootdir/root/.bashrc
  318. echo ' fi' >> $rootdir/root/.bashrc
  319. echo ' fi' >> $rootdir/root/.bashrc
  320. echo 'fi' >> $rootdir/root/.bashrc
  321. }
  322. continue_installation() {
  323. # If a configuration file exists then run with it
  324. # otherwise the interactive installer can be used
  325. # This is equivalent to installing freedombox-setup on freedombox
  326. if [ $CONFIG_FILENAME ]; then
  327. if [ ${#CONFIG_FILENAME} -gt 2 ]; then
  328. cp $CONFIG_FILENAME $rootdir/root/$PROJECT_NAME.cfg
  329. cat $rootdir/root/$PROJECT_NAME.cfg
  330. chroot "$rootdir" su -c "$PROJECT_NAME -c /root/$PROJECT_NAME.cfg" - root
  331. fi
  332. fi
  333. }
  334. atheros_wifi() {
  335. firmware_filename="open-ath9k-htc-firmware_1.3-1_all.deb"
  336. firmware_hash='5fea58ffefdf0ef15b504db7fbe3bc078c03e0d927bba64085e4b6f2546102f5'
  337. firmware_url="http://us.archive.trisquel.info/trisquel/pool/main/o/open-ath9k-htc-firmware/$firmware_filename"
  338. firmware_tempfile="/tmp/$firmware_filename"
  339. wget "$firmware_url" -O "$rootdir$firmware_tempfile"
  340. downloaded_firmware_hash=$(sha256sum "$rootdir$firmware_tempfile" | awk -F ' ' '{print $1}')
  341. if [[ "$downloaded_firmware_hash" == "$firmware_hash" ]]; then
  342. chroot "$rootdir" dpkg -i "$firmware_tempfile"
  343. else
  344. echo 'WARNING: Atheros Wifi firmware hash does not match. The driver has not been installed.'
  345. fi
  346. }
  347. configure_wifi() {
  348. if [[ $VARIANT == "mesh" || $VARIANT == "meshclient" || $VARIANT == "meshusb" ]]; then
  349. return
  350. fi
  351. if [ -f $WIFI_NETWORKS_FILE ]; then
  352. chroot "$rootdir" ${PROJECT_NAME}-wifi -i $WIFI_INTERFACE --networks $WIFI_NETWORKS_FILE
  353. return
  354. fi
  355. if [[ $WIFI_TYPE != 'none' ]]; then
  356. if [ ${#WIFI_PASSPHRASE} -lt 2 ]; then
  357. return
  358. fi
  359. chroot "$rootdir" ${PROJECT_NAME}-wifi -i $WIFI_INTERFACE -s $WIFI_SSID -t $WIFI_TYPE -p $WIFI_PASSPHRASE --hotspot $WIFI_HOTSPOT
  360. else
  361. chroot "$rootdir" ${PROJECT_NAME}-wifi -i $WIFI_INTERFACE -s $WIFI_SSID -t $WIFI_TYPE --hotspot $WIFI_HOTSPOT
  362. fi
  363. }
  364. ##############################################################################
  365. # Mesh networking
  366. ##############################################################################
  367. # for mesh installs
  368. TRACKER_PORT=6969
  369. WIFI_CHANNEL=2
  370. # B.A.T.M.A.N settings
  371. BATMAN_CELLID='02:BA:00:00:03:01'
  372. WIFI_SSID='mesh'
  373. # To avoid confusions these are obtained from the main project file
  374. TOXID_REPO=
  375. TOX_PORT=
  376. TOXCORE_REPO=
  377. TOXIC_REPO=
  378. TOXCORE_COMMIT=
  379. TOXIC_COMMIT=
  380. # These are some default nodes, but you can replace them with trusted nodes
  381. # as you prefer. See https://wiki.tox.im/Nodes
  382. TOX_NODES=
  383. #TOX_NODES=(
  384. # '192.254.75.102,2607:5600:284::2,33445,951C88B7E75C867418ACDB5D273821372BB5BD652740BCDF623A4FA293E75D2F,Tox RELENG,US'
  385. # '144.76.60.215,2a01:4f8:191:64d6::1,33445,04119E835DF3E78BACF0F84235B300546AF8B936F035185E2A8E9E0A67C8924F,sonOfRa,DE'
  386. #)
  387. # To avoid confusions these are obtained from the main project file
  388. ZERONET_REPO=
  389. ZERONET_COMMIT=
  390. ZERONET_PORT=
  391. # Directory where source code is downloaded and compiled
  392. INSTALL_DIR=$HOME/build
  393. function mesh_avahi {
  394. chroot "$rootdir" apt-get -y install avahi-utils avahi-autoipd avahi-dnsconfd
  395. decarray=( 1 2 3 4 5 6 7 8 9 0 )
  396. 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]}
  397. sed -i "s|#host-name=.*|host-name=P$PEER_ID|g" $rootdir/etc/avahi/avahi-daemon.conf
  398. if [ ! -d $rootdir/etc/avahi/services ]; then
  399. mkdir -p $rootdir/etc/avahi/services
  400. fi
  401. # remove an avahi service which isn't used
  402. if [ -f $rootdir/etc/avahi/services/udisks.service ]; then
  403. rm $rootdir/etc/avahi/services/udisks.service
  404. fi
  405. # Add an ssh service
  406. echo '<?xml version="1.0" standalone="no"?><!--*-nxml-*-->' > $rootdir/etc/avahi/services/ssh.service
  407. echo '<!DOCTYPE service-group SYSTEM "avahi-service.dtd">' >> $rootdir/etc/avahi/services/ssh.service
  408. echo '<service-group>' >> $rootdir/etc/avahi/services/ssh.service
  409. echo ' <name replace-wildcards="yes">%h SSH</name>' >> $rootdir/etc/avahi/services/ssh.service
  410. echo ' <service>' >> $rootdir/etc/avahi/services/ssh.service
  411. echo ' <type>_ssh._tcp</type>' >> $rootdir/etc/avahi/services/ssh.service
  412. echo " <port>$SSH_PORT</port>" >> $rootdir/etc/avahi/services/ssh.service
  413. echo ' </service>' >> $rootdir/etc/avahi/services/ssh.service
  414. echo '</service-group>' >> $rootdir/etc/avahi/services/ssh.service
  415. # keep the daemon running
  416. WATCHDOG_SCRIPT_NAME="keepon"
  417. echo '' >> $rootdir/usr/bin/$WATCHDOG_SCRIPT_NAME
  418. echo '# keep avahi daemon running' >> $rootdir/usr/bin/$WATCHDOG_SCRIPT_NAME
  419. echo 'AVAHI_RUNNING=$(pgrep avahi-daemon > /dev/null && echo Running)' >> $rootdir/usr/bin/$WATCHDOG_SCRIPT_NAME
  420. echo 'if [ ! $AVAHI_RUNNING ]; then' >> $rootdir/usr/bin/$WATCHDOG_SCRIPT_NAME
  421. echo ' systemctl start avahi-daemon' >> $rootdir/usr/bin/$WATCHDOG_SCRIPT_NAME
  422. echo ' echo -n $CURRENT_DATE >> $LOGFILE' >> $rootdir/usr/bin/$WATCHDOG_SCRIPT_NAME
  423. echo ' echo " Avahi daemon restarted" >> $LOGFILE' >> $rootdir/usr/bin/$WATCHDOG_SCRIPT_NAME
  424. echo 'fi' >> $rootdir/usr/bin/$WATCHDOG_SCRIPT_NAME
  425. chmod +x $rootdir/usr/bin/$WATCHDOG_SCRIPT_NAME
  426. }
  427. function mesh_batman {
  428. chroot "$rootdir" apt-get -y install iproute bridge-utils libnetfilter-conntrack3 batctl
  429. chroot "$rootdir" apt-get -y install python-dev libevent-dev ebtables python-pip git
  430. chroot "$rootdir" apt-get -y install wireless-tools rfkill
  431. if ! grep -q "batman_adv" $rootdir/etc/modules; then
  432. echo 'batman_adv' >> $rootdir/etc/modules
  433. fi
  434. BATMAN_SCRIPT=$rootdir/var/lib/batman
  435. if [ -f /usr/local/bin/${PROJECT_NAME}-mesh-batman ]; then
  436. cp /usr/local/bin/${PROJECT_NAME}-mesh-batman $BATMAN_SCRIPT
  437. else
  438. cp /usr/bin/${PROJECT_NAME}-mesh-batman $BATMAN_SCRIPT
  439. fi
  440. BATMAN_DAEMON=$rootdir/etc/systemd/system/batman.service
  441. echo '[Unit]' > $BATMAN_DAEMON
  442. echo 'Description=B.A.T.M.A.N. Advanced' >> $BATMAN_DAEMON
  443. echo '' >> $BATMAN_DAEMON
  444. echo '[Service]' >> $BATMAN_DAEMON
  445. echo 'Type=oneshot' >> $BATMAN_DAEMON
  446. echo "ExecStart=/var/lib/batman start" >> $BATMAN_DAEMON
  447. echo "ExecStop=/var/lib/batman stop" >> $BATMAN_DAEMON
  448. echo 'RemainAfterExit=yes' >> $BATMAN_DAEMON
  449. echo '' >> $BATMAN_DAEMON
  450. echo '# Allow time for the server to start/stop' >> $BATMAN_DAEMON
  451. echo 'TimeoutSec=300' >> $BATMAN_DAEMON
  452. echo '' >> $BATMAN_DAEMON
  453. echo '[Install]' >> $BATMAN_DAEMON
  454. echo 'WantedBy=multi-user.target' >> $BATMAN_DAEMON
  455. chroot "$rootdir" systemctl enable batman
  456. }
  457. function mesh_firewall {
  458. FIREWALL_FILENAME=${rootdir}/etc/systemd/system/meshfirewall.service
  459. MESH_FIREWALL_SCRIPT=${rootdir}/usr/bin/mesh-firewall
  460. echo '#!/bin/bash' > $MESH_FIREWALL_SCRIPT
  461. echo 'iptables -P INPUT ACCEPT' >> $MESH_FIREWALL_SCRIPT
  462. echo 'ip6tables -P INPUT ACCEPT' >> $MESH_FIREWALL_SCRIPT
  463. echo 'iptables -F' >> $MESH_FIREWALL_SCRIPT
  464. echo 'ip6tables -F' >> $MESH_FIREWALL_SCRIPT
  465. echo 'iptables -t nat -F' >> $MESH_FIREWALL_SCRIPT
  466. echo 'ip6tables -t nat -F' >> $MESH_FIREWALL_SCRIPT
  467. echo 'iptables -X' >> $MESH_FIREWALL_SCRIPT
  468. echo 'ip6tables -X' >> $MESH_FIREWALL_SCRIPT
  469. echo 'iptables -P INPUT DROP' >> $MESH_FIREWALL_SCRIPT
  470. echo 'ip6tables -P INPUT DROP' >> $MESH_FIREWALL_SCRIPT
  471. echo 'iptables -A INPUT -i lo -j ACCEPT' >> $MESH_FIREWALL_SCRIPT
  472. echo 'iptables -A INPUT -m conntrack --ctstate ESTABLISHED,RELATED -j ACCEPT' >> $MESH_FIREWALL_SCRIPT
  473. echo '' >> $MESH_FIREWALL_SCRIPT
  474. echo '# Make sure incoming tcp connections are SYN packets' >> $MESH_FIREWALL_SCRIPT
  475. echo 'iptables -A INPUT -p tcp ! --syn -m state --state NEW -j DROP' >> $MESH_FIREWALL_SCRIPT
  476. echo '' >> $MESH_FIREWALL_SCRIPT
  477. echo '# Drop packets with incoming fragments' >> $MESH_FIREWALL_SCRIPT
  478. echo 'iptables -A INPUT -f -j DROP' >> $MESH_FIREWALL_SCRIPT
  479. echo '' >> $MESH_FIREWALL_SCRIPT
  480. echo '# Drop bogons' >> $MESH_FIREWALL_SCRIPT
  481. echo 'iptables -A INPUT -p tcp --tcp-flags ALL ALL -j DROP' >> $MESH_FIREWALL_SCRIPT
  482. echo 'iptables -A INPUT -p tcp --tcp-flags ALL FIN,PSH,URG -j DROP' >> $MESH_FIREWALL_SCRIPT
  483. echo 'iptables -A INPUT -p tcp --tcp-flags ALL SYN,RST,ACK,FIN,URG -j DROP' >> $MESH_FIREWALL_SCRIPT
  484. echo '' >> $MESH_FIREWALL_SCRIPT
  485. echo '# Incoming malformed NULL packets:' >> $MESH_FIREWALL_SCRIPT
  486. echo 'iptables -A INPUT -p tcp --tcp-flags ALL NONE -j DROP' >> $MESH_FIREWALL_SCRIPT
  487. echo '' >> $MESH_FIREWALL_SCRIPT
  488. echo "iptables -A INPUT -p tcp --dport $TOX_PORT -j ACCEPT" >> $MESH_FIREWALL_SCRIPT
  489. echo "iptables -A INPUT -i $WIFI_INTERFACE -p udp --dport $ZERONET_PORT -j ACCEPT" >> $MESH_FIREWALL_SCRIPT
  490. echo "iptables -A INPUT -i $WIFI_INTERFACE -p tcp --dport $ZERONET_PORT -j ACCEPT" >> $MESH_FIREWALL_SCRIPT
  491. echo "iptables -A INPUT -i $WIFI_INTERFACE -p udp --dport $TRACKER_PORT -j ACCEPT" >> $MESH_FIREWALL_SCRIPT
  492. echo "iptables -A INPUT -i $WIFI_INTERFACE -p tcp --dport $TRACKER_PORT -j ACCEPT" >> $MESH_FIREWALL_SCRIPT
  493. echo "iptables -A INPUT -i $WIFI_INTERFACE -p udp --dport 1900 -j ACCEPT" >> $MESH_FIREWALL_SCRIPT
  494. chmod +x $MESH_FIREWALL_SCRIPT
  495. echo '[Unit]' > $FIREWALL_FILENAME
  496. echo 'Description=Mesh Firewall' >> $FIREWALL_FILENAME
  497. echo '' >> $FIREWALL_FILENAME
  498. echo '[Service]' >> $FIREWALL_FILENAME
  499. echo 'Type=oneshot' >> $FIREWALL_FILENAME
  500. echo 'ExecStart=/usr/bin/mesh-firewall' >> $FIREWALL_FILENAME
  501. echo 'RemainAfterExit=no' >> $FIREWALL_FILENAME
  502. echo '' >> $FIREWALL_FILENAME
  503. echo 'TimeoutSec=30' >> $FIREWALL_FILENAME
  504. echo '' >> $FIREWALL_FILENAME
  505. echo '[Install]' >> $FIREWALL_FILENAME
  506. echo 'WantedBy=multi-user.target' >> $FIREWALL_FILENAME
  507. chroot "$rootdir" systemctl enable meshfirewall
  508. }
  509. function mesh_tox_node {
  510. # obtain commits from the main file
  511. if [ -f /usr/local/bin/${PROJECT_NAME} ]; then
  512. TOXCORE_COMMIT_MAIN=$(cat /usr/local/bin/${PROJECT_NAME} | grep "TOXCORE_COMMIT=" | head -n 1 | awk -F "'" '{print $2}')
  513. else
  514. TOXCORE_COMMIT_MAIN=$(cat /usr/bin/${PROJECT_NAME} | grep "TOXCORE_COMMIT=" | head -n 1 | awk -F "'" '{print $2}')
  515. fi
  516. if [ ${#TOXCORE_COMMIT_MAIN} -gt 10 ]; then
  517. TOXCORE_COMMIT=$TOXCORE_COMMIT_MAIN
  518. fi
  519. if [ ! $TOXCORE_COMMIT ]; then
  520. echo $'No Tox commit was specified'
  521. exit 76325
  522. fi
  523. if [ -f /usr/local/bin/${PROJECT_NAME} ]; then
  524. TOX_PORT_MAIN=$(cat /usr/local/bin/${PROJECT_NAME} | grep "TOX_PORT=" | head -n 1 | awk -F '=' '{print $2}')
  525. else
  526. TOX_PORT_MAIN=$(cat /usr/bin/${PROJECT_NAME} | grep "TOX_PORT=" | head -n 1 | awk -F '=' '{print $2}')
  527. fi
  528. if [ ${#TOX_PORT_MAIN} -gt 2 ]; then
  529. TOX_PORT=$TOX_PORT_MAIN
  530. fi
  531. if [ ! $TOX_PORT ]; then
  532. echo $'No Tox port was specified'
  533. exit 32856
  534. fi
  535. if [ -f /usr/local/bin/${PROJECT_NAME} ]; then
  536. TOXCORE_REPO_MAIN=$(cat /usr/local/bin/${PROJECT_NAME} | grep "TOXCORE_REPO=" | head -n 1 | awk -F '"' '{print $2}')
  537. else
  538. TOXCORE_REPO_MAIN=$(cat /usr/bin/${PROJECT_NAME} | grep "TOXCORE_REPO=" | head -n 1 | awk -F '"' '{print $2}')
  539. fi
  540. if [ ${#TOXCORE_REPO_MAIN} -gt 10 ]; then
  541. TOXCORE_REPO=$TOXCORE_REPO_MAIN
  542. fi
  543. if [ ! $TOXCORE_REPO ]; then
  544. echo $'No Tox repo was specified'
  545. exit 16865
  546. fi
  547. chroot "$rootdir" apt-get -y install build-essential libtool autotools-dev
  548. chroot "$rootdir" apt-get -y install automake checkinstall check git yasm
  549. chroot "$rootdir" apt-get -y install libsodium13 libsodium-dev libcap2-bin
  550. chroot "$rootdir" apt-get -y install libconfig9 libconfig-dev
  551. TEMP_SCRIPT_NAME=fbtmp37272.sh
  552. TEMP_SCRIPT=/tmp/$TEMP_SCRIPT_NAME
  553. echo '#!/bin/bash' > $TEMP_SCRIPT
  554. echo "mkdir -p $INSTALL_DIR" >> $TEMP_SCRIPT
  555. echo "git clone $TOXCORE_REPO $INSTALL_DIR/toxcore" >> $TEMP_SCRIPT
  556. echo "cd $INSTALL_DIR/toxcore" >> $TEMP_SCRIPT
  557. echo "git checkout $TOXCORE_COMMIT -b $TOXCORE_COMMIT" >> $TEMP_SCRIPT
  558. echo 'autoreconf -i' >> $TEMP_SCRIPT
  559. echo './configure --enable-daemon --disable-av' >> $TEMP_SCRIPT
  560. echo 'make' >> $TEMP_SCRIPT
  561. echo 'if [ ! "$?" = "0" ]; then' >> $TEMP_SCRIPT
  562. echo ' exit 1' >> $TEMP_SCRIPT
  563. echo 'fi' >> $TEMP_SCRIPT
  564. echo 'make install' >> $TEMP_SCRIPT
  565. echo 'cp /usr/local/lib/libtoxcore* /usr/lib/' >> $TEMP_SCRIPT
  566. echo "cp $INSTALL_DIR/toxcore/other/bootstrap_daemon/tox-bootstrapd.service /etc/systemd/system/" >> $TEMP_SCRIPT
  567. echo "sed -i 's|ExecStart=.*|ExecStart=/usr/local/bin/tox-bootstrapd --config /etc/tox-bootstrapd.conf|g' /etc/systemd/system/tox-bootstrapd.service" >> $TEMP_SCRIPT
  568. echo 'systemctl enable tox-bootstrapd.service' >> $TEMP_SCRIPT
  569. echo 'exit 0' >> $TEMP_SCRIPT
  570. chmod +x $TEMP_SCRIPT
  571. cp $TEMP_SCRIPT $rootdir/root/
  572. SECONDS=0
  573. chroot "$rootdir" /root/$TEMP_SCRIPT_NAME
  574. if [ ! "$?" = "0" ]; then
  575. duration=$SECONDS
  576. echo $"Toxcore compile failed at $(($duration / 60)) minutes and $(($duration % 60)) seconds elapsed."
  577. echo $'Unable to make toxcore'
  578. rm $TEMP_SCRIPT
  579. exit 73835
  580. fi
  581. duration=$SECONDS
  582. echo $"Toxcore compile $(($duration / 60)) minutes and $(($duration % 60)) seconds elapsed."
  583. rm $TEMP_SCRIPT
  584. if [ ! -f $rootdir/usr/local/bin/tox-bootstrapd ]; then
  585. echo $"File not found /usr/local/bin/tox-bootstrapd"
  586. exit 37825
  587. fi
  588. 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
  589. chroot "$rootdir" chmod 700 /var/lib/tox-bootstrapd
  590. # remove Maildir
  591. if [ -d $rootdir/var/lib/tox-bootstrapd/Maildir ]; then
  592. rm -rf $rootdir/var/lib/tox-bootstrapd/Maildir
  593. fi
  594. # create configuration file
  595. TOX_BOOTSTRAP_CONFIG=$rootdir/etc/tox-bootstrapd.conf
  596. echo "port = $TOX_PORT" > $TOX_BOOTSTRAP_CONFIG
  597. echo 'keys_file_path = "/var/lib/tox-bootstrapd/keys"' >> $TOX_BOOTSTRAP_CONFIG
  598. echo 'pid_file_path = "/var/run/tox-bootstrapd/tox-bootstrapd.pid"' >> $TOX_BOOTSTRAP_CONFIG
  599. echo 'enable_ipv6 = true' >> $TOX_BOOTSTRAP_CONFIG
  600. echo 'enable_ipv4_fallback = true' >> $TOX_BOOTSTRAP_CONFIG
  601. echo 'enable_lan_discovery = true' >> $TOX_BOOTSTRAP_CONFIG
  602. echo 'enable_tcp_relay = true' >> $TOX_BOOTSTRAP_CONFIG
  603. echo "tcp_relay_ports = [443, 3389, $TOX_PORT]" >> $TOX_BOOTSTRAP_CONFIG
  604. echo 'enable_motd = true' >> $TOX_BOOTSTRAP_CONFIG
  605. echo 'motd = "tox-bootstrapd"' >> $TOX_BOOTSTRAP_CONFIG
  606. if [ $TOX_NODES ]; then
  607. echo 'bootstrap_nodes = (' >> $TOX_BOOTSTRAP_CONFIG
  608. toxcount=0
  609. while [ "x${TOX_NODES[toxcount]}" != "x" ]
  610. do
  611. toxval_ipv4=$(echo $TOX_NODES[toxcount] | awk -F ',' '{print $1}')
  612. toxval_ipv6=$(echo $TOX_NODES[toxcount] | awk -F ',' '{print $2}')
  613. toxval_port=$(echo $TOX_NODES[toxcount] | awk -F ',' '{print $3}')
  614. toxval_pubkey=$(echo $TOX_NODES[toxcount] | awk -F ',' '{print $4}')
  615. toxval_maintainer=$(echo $TOX_NODES[toxcount] | awk -F ',' '{print $5}')
  616. echo "{ // $toxval_maintainer" >> $TOX_BOOTSTRAP_CONFIG
  617. if [[ $toxval_ipv6 != 'NONE' ]]; then
  618. echo " address = \"$toxval_ipv6\"" >> $TOX_BOOTSTRAP_CONFIG
  619. else
  620. echo " address = \"$toxval_ipv4\"" >> $TOX_BOOTSTRAP_CONFIG
  621. fi
  622. echo " port = $toxval_port" >> $TOX_BOOTSTRAP_CONFIG
  623. echo " public_key = \"$toxval_pubkey\"" >> $TOX_BOOTSTRAP_CONFIG
  624. toxcount=$(( $toxcount + 1 ))
  625. if [ "x${TOX_NODES[toxcount]}" != "x" ]; then
  626. echo "}," >> $TOX_BOOTSTRAP_CONFIG
  627. else
  628. echo "}" >> $TOX_BOOTSTRAP_CONFIG
  629. fi
  630. done
  631. echo ')' >> $TOX_BOOTSTRAP_CONFIG
  632. fi
  633. }
  634. function mesh_tox_avahi {
  635. if [ ! -d $rootdir/etc/avahi ]; then
  636. echo $'tox_avahi: avahi is not installed'
  637. exit 87359
  638. fi
  639. if [ -f /usr/local/bin/${PROJECT_NAME} ]; then
  640. TOXID_REPO_MAIN=$(cat /usr/local/bin/${PROJECT_NAME} | grep "TOXID_REPO=" | head -n 1 | awk -F '"' '{print $2}')
  641. else
  642. TOXID_REPO_MAIN=$(cat /usr/bin/${PROJECT_NAME} | grep "TOXID_REPO=" | head -n 1 | awk -F '"' '{print $2}')
  643. fi
  644. if [ ${#TOXID_REPO_MAIN} -gt 5 ]; then
  645. TOXID_REPO=$TOXID_REPO_MAIN
  646. fi
  647. if [ ! $TOXID_REPO ]; then
  648. echo $'No ToxID repo was specified'
  649. exit 78252
  650. fi
  651. TEMP_SCRIPT_NAME=fbtmp5328252.sh
  652. TEMP_SCRIPT=/tmp/$TEMP_SCRIPT_NAME
  653. echo '#!/bin/bash' > $TEMP_SCRIPT
  654. echo "mkdir -p $INSTALL_DIR" >> $TEMP_SCRIPT
  655. echo "git clone $TOXID_REPO $INSTALL_DIR/toxid" >> $TEMP_SCRIPT
  656. echo "if [ ! -d $INSTALL_DIR/toxid ]; then" >> $TEMP_SCRIPT
  657. echo ' exit 1' >> $TEMP_SCRIPT
  658. echo 'fi' >> $TEMP_SCRIPT
  659. echo "cd $INSTALL_DIR/toxid" >> $TEMP_SCRIPT
  660. echo "make" >> $TEMP_SCRIPT
  661. echo 'if [ ! "$?" = "0" ]; then' >> $TEMP_SCRIPT
  662. echo ' exit 2' >> $TEMP_SCRIPT
  663. echo 'fi' >> $TEMP_SCRIPT
  664. echo 'make install' >> $TEMP_SCRIPT
  665. echo 'if [ ! -f /usr/local/bin/toxavahi ]; then' >> $TEMP_SCRIPT
  666. echo ' exit 3' >> $TEMP_SCRIPT
  667. echo 'fi' >> $TEMP_SCRIPT
  668. echo 'toxavahi' >> $TEMP_SCRIPT
  669. echo 'echo "* * * * * root /usr/local/bin/toxavahi > /dev/null" >> /etc/crontab' >> $TEMP_SCRIPT
  670. echo 'systemctl restart avahi-daemon' >> $TEMP_SCRIPT
  671. echo 'exit 0' >> $TEMP_SCRIPT
  672. chmod +x $TEMP_SCRIPT
  673. cp $TEMP_SCRIPT $rootdir/root/
  674. chroot "$rootdir" /root/$TEMP_SCRIPT_NAME
  675. if [ ! "$?" = "0" ]; then
  676. echo $"Unable to install toxid, returned $?"
  677. rm $TEMP_SCRIPT
  678. exit 62835
  679. fi
  680. rm $TEMP_SCRIPT
  681. }
  682. function mesh_tox_client {
  683. if [ -f /usr/local/bin/${PROJECT_NAME} ]; then
  684. TOXIC_FILE=$(cat /usr/local/bin/${PROJECT_NAME} | grep "TOXIC_FILE=" | head -n 1 | awk -F '=' '{print $2}')
  685. else
  686. TOXIC_FILE=$(cat /usr/bin/${PROJECT_NAME} | grep "TOXIC_FILE=" | head -n 1 | awk -F '=' '{print $2}')
  687. fi
  688. # obtain commits from the main file
  689. if [ -f /usr/local/bin/${PROJECT_NAME} ]; then
  690. TOXIC_COMMIT_MAIN=$(cat /usr/local/bin/${PROJECT_NAME} | grep "TOXIC_COMMIT=" | head -n 1 | awk -F "'" '{print $2}')
  691. else
  692. TOXIC_COMMIT_MAIN=$(cat /usr/bin/${PROJECT_NAME} | grep "TOXIC_COMMIT=" | head -n 1 | awk -F "'" '{print $2}')
  693. fi
  694. if [ ${#TOXIC_COMMIT_MAIN} -gt 10 ]; then
  695. TOXIC_COMMIT=$TOXIC_COMMIT_MAIN
  696. fi
  697. if [ -f /usr/local/bin/${PROJECT_NAME} ]; then
  698. TOXIC_REPO_MAIN=$(cat /usr/local/bin/${PROJECT_NAME} | grep "TOXIC_REPO=" | head -n 1 | awk -F '"' '{print $2}')
  699. else
  700. TOXIC_REPO_MAIN=$(cat /usr/bin/${PROJECT_NAME} | grep "TOXIC_REPO=" | head -n 1 | awk -F '"' '{print $2}')
  701. fi
  702. if [ ${#TOXIC_REPO_MAIN} -gt 5 ]; then
  703. TOXIC_REPO=$TOXIC_REPO_MAIN
  704. fi
  705. chroot "$rootdir" apt-get -y install libncursesw5-dev libconfig-dev libqrencode-dev
  706. chroot "$rootdir" apt-get -y install libcurl4-openssl-dev libvpx-dev libopenal-dev
  707. TEMP_SCRIPT_NAME=fbtmp728353.sh
  708. TEMP_SCRIPT=/tmp/$TEMP_SCRIPT_NAME
  709. echo '#!/bin/bash' > $TEMP_SCRIPT
  710. echo "mkdir -p $INSTALL_DIR" >> $TEMP_SCRIPT
  711. echo "git clone $TOXIC_REPO $INSTALL_DIR/toxic" >> $TEMP_SCRIPT
  712. echo "cd $INSTALL_DIR/toxic" >> $TEMP_SCRIPT
  713. echo "git checkout $TOXIC_COMMIT -b $TOXIC_COMMIT" >> $TEMP_SCRIPT
  714. echo 'make' >> $TEMP_SCRIPT
  715. echo 'if [ ! "$?" = "0" ]; then' >> $TEMP_SCRIPT
  716. echo ' exit 1' >> $TEMP_SCRIPT
  717. echo 'fi' >> $TEMP_SCRIPT
  718. echo 'make install' >> $TEMP_SCRIPT
  719. echo 'exit 0' >> $TEMP_SCRIPT
  720. chmod +x $TEMP_SCRIPT
  721. cp $TEMP_SCRIPT $rootdir/root/
  722. if [ -f /usr/local/bin/${PROJECT_NAME} ]; then
  723. TOXIC_FILE=$(cat /usr/local/bin/${PROJECT_NAME} | grep "TOXIC_FILE=" | head -n 1 | awk -F '=' '{print $2}')
  724. else
  725. TOXIC_FILE=$(cat /usr/bin/${PROJECT_NAME} | grep "TOXIC_FILE=" | head -n 1 | awk -F '=' '{print $2}')
  726. fi
  727. SECONDS=0
  728. chroot "$rootdir" /root/$TEMP_SCRIPT_NAME
  729. if [ ! "$?" = "0" ]; then
  730. duration=$SECONDS
  731. echo $"Toxic client compile failed at $(($duration / 60)) minutes and $(($duration % 60)) seconds elapsed."
  732. echo $'Unable to make tox client'
  733. rm $TEMP_SCRIPT
  734. exit 74872
  735. fi
  736. rm $TEMP_SCRIPT
  737. if [ ! -f $rootdir$TOXIC_FILE ]; then
  738. echo $"Tox client was not installed to $TOXIC_FILE"
  739. exit 63278
  740. fi
  741. duration=$SECONDS
  742. echo $"Toxic client compile $(($duration / 60)) minutes and $(($duration % 60)) seconds elapsed."
  743. }
  744. function mesh_zeronet {
  745. # obtain commits from the main file
  746. if [ -f /usr/local/bin/${PROJECT_NAME} ]; then
  747. ZERONET_COMMIT_MAIN=$(cat /usr/local/bin/${PROJECT_NAME} | grep "ZERONET_COMMIT=" | head -n 1 | awk -F "'" '{print $2}')
  748. else
  749. ZERONET_COMMIT_MAIN=$(cat /usr/bin/${PROJECT_NAME} | grep "ZERONET_COMMIT=" | head -n 1 | awk -F "'" '{print $2}')
  750. fi
  751. if [ ${#ZERONET_COMMIT_MAIN} -gt 10 ]; then
  752. ZERONET_COMMIT=$ZERONET_COMMIT_MAIN
  753. fi
  754. if [ ! $ZERONET_COMMIT ]; then
  755. echo $'No Tox commit was specified'
  756. exit 37046
  757. fi
  758. if [ -f /usr/local/bin/${PROJECT_NAME} ]; then
  759. ZERONET_REPO_MAIN=$(cat /usr/local/bin/${PROJECT_NAME} | grep "ZERONET_REPO=" | head -n 1 | awk -F '"' '{print $2}')
  760. else
  761. ZERONET_REPO_MAIN=$(cat /usr/bin/${PROJECT_NAME} | grep "ZERONET_REPO=" | head -n 1 | awk -F '"' '{print $2}')
  762. fi
  763. if [ ${#ZERONET_REPO_MAIN} -gt 5 ]; then
  764. ZERONET_REPO=$ZERONET_REPO_MAIN
  765. fi
  766. if [ ! $ZERONET_REPO ]; then
  767. echo $'No Tox commit was specified'
  768. exit 37046
  769. fi
  770. if [ -f /usr/local/bin/${PROJECT_NAME} ]; then
  771. ZERONET_PORT_MAIN=$(cat /usr/local/bin/${PROJECT_NAME} | grep "ZERONET_PORT=" | head -n 1 | awk -F '=' '{print $2}')
  772. else
  773. ZERONET_PORT_MAIN=$(cat /usr/bin/${PROJECT_NAME} | grep "ZERONET_PORT=" | head -n 1 | awk -F '=' '{print $2}')
  774. fi
  775. if [ ${#ZERONET_PORT_MAIN} -gt 1 ]; then
  776. ZERONET_PORT=$ZERONET_PORT_MAIN
  777. fi
  778. if [ ! $ZERONET_PORT ]; then
  779. echo $'No zeronet port was specified'
  780. exit 67433
  781. fi
  782. chroot "$rootdir" apt-get -y install python python-msgpack python-gevent
  783. chroot "$rootdir" apt-get -y install python-pip bittornado
  784. chroot "$rootdir" pip install msgpack-python --upgrade
  785. chroot "$rootdir" useradd -d /opt/zeronet/ -s /bin/false zeronet
  786. git clone $ZERONET_REPO $rootdir/opt/zeronet
  787. if [ ! -d $rootdir/opt/zeronet ]; then
  788. echo 'WARNING: Unable to clone zeronet'
  789. return
  790. fi
  791. cd $rootdir/opt/zeronet
  792. git checkout $ZERONET_COMMIT -b $ZERONET_COMMIT
  793. if ! grep -q "ZeroNet commit" $COMPLETION_FILE; then
  794. echo "ZeroNet commit:$ZERONET_COMMIT" >> $rootdir$COMPLETION_FILE
  795. else
  796. sed -i "s/ZeroNet commit.*/ZeroNet commit:$ZERONET_COMMIT/g" $COMPLETION_FILE
  797. fi
  798. chroot "$rootdir" chown -R zeronet:zeronet /opt/zeronet
  799. # Hack to ensure that the file access port is opened
  800. # This is because zeronet normally relies on an internet site
  801. # to do this, but on a purely local mesh the internet isn't available
  802. 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
  803. ZERONET_DAEMON=$rootdir/etc/systemd/system/zeronet.service
  804. echo '[Unit]' > $ZERONET_DAEMON
  805. echo 'Description=Zeronet Server' >> $ZERONET_DAEMON
  806. echo 'After=syslog.target' >> $ZERONET_DAEMON
  807. echo 'After=network.target' >> $ZERONET_DAEMON
  808. echo '[Service]' >> $ZERONET_DAEMON
  809. echo 'Type=simple' >> $ZERONET_DAEMON
  810. echo 'User=zeronet' >> $ZERONET_DAEMON
  811. echo 'Group=zeronet' >> $ZERONET_DAEMON
  812. echo 'WorkingDirectory=/opt/zeronet' >> $ZERONET_DAEMON
  813. echo 'ExecStart=/usr/bin/python zeronet.py --ip_external replace.local --trackers_file /opt/zeronet/bootstrap' >> $ZERONET_DAEMON
  814. echo '' >> $ZERONET_DAEMON
  815. echo 'TimeoutSec=300' >> $ZERONET_DAEMON
  816. echo '' >> $ZERONET_DAEMON
  817. echo '[Install]' >> $ZERONET_DAEMON
  818. echo 'WantedBy=multi-user.target' >> $ZERONET_DAEMON
  819. TRACKER_DAEMON=$rootdir/etc/systemd/system/tracker.service
  820. echo '[Unit]' > $TRACKER_DAEMON
  821. echo 'Description=Torrent Tracker' >> $TRACKER_DAEMON
  822. echo 'After=syslog.target' >> $TRACKER_DAEMON
  823. echo 'After=network.target' >> $TRACKER_DAEMON
  824. echo '[Service]' >> $TRACKER_DAEMON
  825. echo 'Type=simple' >> $TRACKER_DAEMON
  826. echo 'User=tracker' >> $TRACKER_DAEMON
  827. echo 'Group=tracker' >> $TRACKER_DAEMON
  828. echo 'WorkingDirectory=/opt/tracker' >> $TRACKER_DAEMON
  829. 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" >> $TRACKER_DAEMON
  830. echo '' >> $TRACKER_DAEMON
  831. echo 'TimeoutSec=300' >> $TRACKER_DAEMON
  832. echo '' >> $TRACKER_DAEMON
  833. echo '[Install]' >> $TRACKER_DAEMON
  834. echo 'WantedBy=multi-user.target' >> $TRACKER_DAEMON
  835. chroot "$rootdir" useradd -d /opt/tracker/ -s /bin/false tracker
  836. if [ ! -d $rootdir/opt/tracker ]; then
  837. mkdir $rootdir/opt/tracker
  838. fi
  839. chroot "$rootdir" chown -R tracker:tracker /opt/tracker
  840. # publish regularly
  841. echo "* * * * * root zeronetavahi > /dev/null" >> $rootdir/etc/crontab
  842. chroot "$rootdir" systemctl enable tracker.service
  843. chroot "$rootdir" systemctl enable zeronet.service
  844. }
  845. initialise_mesh() {
  846. if [[ $VARIANT != "mesh" && $VARIANT != "meshclient" && $VARIANT != "meshusb" ]]; then
  847. return
  848. fi
  849. if [[ $DEBIAN_INSTALL_ONLY != "no" ]]; then
  850. return
  851. fi
  852. if [[ $INSECURE == $'yes' ]]; then
  853. echo '*********************************************************'
  854. echo $'WARNING: non-free wifi drivers are being installed.'
  855. echo $' This may compromise the security of your system.'
  856. echo '*********************************************************'
  857. # enable non-free repo
  858. if ! grep -q "non-free" $rootdir/etc/apt/sources.list; then
  859. chroot "$rootdir" sed -i "s| main| main non-free|g" /etc/apt/sources.list
  860. chroot "$rootdir" apt-get update
  861. fi
  862. # install proprietary wifi drivers
  863. # see https://wiki.debian.org/iwlwifi
  864. chroot "$rootdir" apt-get -y install firmware-iwlwifi
  865. fi
  866. mesh_firewall
  867. mesh_avahi
  868. mesh_batman
  869. mesh_tox_node
  870. mesh_tox_avahi
  871. mesh_tox_client
  872. mesh_zeronet
  873. MESH_SERVICE='mesh-setup.service'
  874. MESH_SETUP_DAEMON=$rootdir/etc/systemd/system/$MESH_SERVICE
  875. echo '[Unit]' > $MESH_SETUP_DAEMON
  876. echo 'Description=Initial mesh router configuration' >> $MESH_SETUP_DAEMON
  877. echo 'After=syslog.target' >> $MESH_SETUP_DAEMON
  878. echo 'After=network.target' >> $MESH_SETUP_DAEMON
  879. echo '[Service]' >> $MESH_SETUP_DAEMON
  880. echo 'Type=simple' >> $MESH_SETUP_DAEMON
  881. echo 'User=root' >> $MESH_SETUP_DAEMON
  882. echo 'Group=root' >> $MESH_SETUP_DAEMON
  883. echo 'WorkingDirectory=/root' >> $MESH_SETUP_DAEMON
  884. echo "ExecStart=/usr/local/bin/${PROJECT_NAME}-image-mesh > /var/log/mesh-setup.log" >> $MESH_SETUP_DAEMON
  885. echo '' >> $MESH_SETUP_DAEMON
  886. echo 'TimeoutSec=99999' >> $MESH_SETUP_DAEMON
  887. echo '' >> $MESH_SETUP_DAEMON
  888. echo '[Install]' >> $MESH_SETUP_DAEMON
  889. echo 'WantedBy=multi-user.target' >> $MESH_SETUP_DAEMON
  890. chroot "$rootdir" systemctl enable $MESH_SERVICE
  891. }
  892. # User interface for USB drive installs ######################################
  893. function enable_tox_repo {
  894. echo 'deb http://download.opensuse.org/repositories/home:/antonbatenev:/tox/Debian_8.0/ /' > $rootdir/etc/apt/sources.list.d/tox.list
  895. chroot "$rootdir" wget -q http://download.opensuse.org/repositories/home:antonbatenev:tox/Debian_8.0/Release.key -O- | apt-key add -
  896. chroot "$rootdir" apt-get update
  897. echo "Tox Repository Installed."
  898. }
  899. function install_syncthing {
  900. if [[ $SYSTEM_TYPE == "$VARIANT_WRITER" || $SYSTEM_TYPE == "$VARIANT_MAILBOX" || $SYSTEM_TYPE == "$VARIANT_CHAT" || $SYSTEM_TYPE == "$VARIANT_SOCIAL" || $SYSTEM_TYPE == "$VARIANT_MEDIA" || $SYSTEM_TYPE == "$VARIANT_DEVELOPER" ]]; then
  901. return
  902. fi
  903. chroot "$rootdir" wget -q https://syncthing.net/release-key.txt -O- | apt-key add -
  904. echo "deb http://apt.syncthing.net/ syncthing release" | tee $rootdir/etc/apt/sources.list.d/syncthing.list
  905. chroot "$rootdir" apt-get update
  906. chroot "$rootdir" apt-get -y --force-yes install syncthing
  907. # This probably does need to run as root so that it can access the Sync directories
  908. # in each user's home directory
  909. chroot "$rootdir" echo '[Unit]' > /etc/systemd/system/syncthing.service
  910. chroot "$rootdir" echo 'Description=Syncthing - Open Source Continuous File Synchronization' >> /etc/systemd/system/syncthing.service
  911. chroot "$rootdir" echo 'Documentation=man:syncthing(1)' >> /etc/systemd/system/syncthing.service
  912. chroot "$rootdir" echo 'After=network.target' >> /etc/systemd/system/syncthing.service
  913. chroot "$rootdir" echo 'Wants=syncthing-inotify@.service' >> /etc/systemd/system/syncthing.service
  914. chroot "$rootdir" echo '' >> /etc/systemd/system/syncthing.service
  915. chroot "$rootdir" echo '[Service]' >> /etc/systemd/system/syncthing.service
  916. chroot "$rootdir" echo 'User=root' >> /etc/systemd/system/syncthing.service
  917. chroot "$rootdir" echo "Environment='all_proxy=socks5://localhost:9050'" >> /etc/systemd/system/syncthing.service
  918. chroot "$rootdir" echo 'ExecStart=/usr/bin/syncthing -no-browser -no-restart -logflags=0' >> /etc/systemd/system/syncthing.service
  919. chroot "$rootdir" echo 'Restart=on-failure' >> /etc/systemd/system/syncthing.service
  920. chroot "$rootdir" echo 'SuccessExitStatus=3 4' >> /etc/systemd/system/syncthing.service
  921. chroot "$rootdir" echo 'RestartForceExitStatus=3 4' >> /etc/systemd/system/syncthing.service
  922. chroot "$rootdir" echo '' >> /etc/systemd/system/syncthing.service
  923. chroot "$rootdir" echo '[Install]' >> /etc/systemd/system/syncthing.service
  924. chroot "$rootdir" echo 'WantedBy=multi-user.target' >> /etc/systemd/system/syncthing.service
  925. chroot "$rootdir" systemctl enable syncthing
  926. chroot "$rootdir" systemctl daemon-reload
  927. if ! grep -q "syncthing" $rootdir/etc/crontab; then
  928. chroot "$rootdir" echo "*/1 * * * * root /usr/local/bin/freedombone-syncthing > /dev/null" >> /etc/crontab
  929. chroot "$rootdir" systemctl restart cron
  930. fi
  931. echo 'install_syncthing'
  932. }
  933. function configure_user_interface {
  934. if [[ $VARIANT != "meshclient" && $VARIANT != "meshusb" && $VARIANT != "usb" ]]; then
  935. return
  936. fi
  937. # desktop
  938. chroot "$rootdir" apt-get -y install mate-desktop-environment lightdm
  939. # browser
  940. chroot "$rootdir" apt-get -y install iceweasel
  941. # NOTE: The Tox repo only supports a limited range of architectures
  942. if [[ $ARCHITECTURE == 'amd64' || $ARCHITECTURE == 'i386' ]]; then
  943. # Tox user interface
  944. enable_tox_repo
  945. # TODO: this may not work on all architectures
  946. chroot "$rootdir" apt-get -y --force-yes install qtox
  947. fi
  948. # Syncthing
  949. install_syncthing
  950. if [[ $VARIANT == "usb" ]]; then
  951. # tor
  952. chroot "$rootdir" apt-get -y install tor
  953. # xmpp client
  954. chroot "$rootdir" echo "deb ftp://ftp.gajim.org/debian unstable main" > /etc/apt/sources.list.d/gajim.list
  955. chroot "$rootdir" apt-get update
  956. chroot "$rootdir" apt-get -y install gajim-dev-keyring
  957. chroot "$rootdir" apt-get -y install git python-dev python-pip gajim-nightly
  958. chroot "$rootdir" mkdir /home/$GENERIC_IMAGE_USERNAME/.local/share/gajim/plugins -p
  959. chroot "$rootdir" git clone https://github.com/omemo/gajim-omemo /home/$GENERIC_IMAGE_USERNAME/.local/share/gajim/plugins/gajim-omemo
  960. chroot "$rootdir" pip install protobuf==2.6.1, python-axolotl==0.1.35
  961. chroot "$rootdir" chown -R $GENERIC_IMAGE_USERNAME:$GENERIC_IMAGE_USERNAME /home/$GENERIC_IMAGE_USERNAME/.local
  962. # IRC client
  963. chroot "$rootdir" apt-get -y install hexchat profanity
  964. # zeronet
  965. # TODO
  966. fi
  967. }
  968. ##############################################################################
  969. # Set to true/false to control if eatmydata is used during build
  970. use_eatmydata=true
  971. rootdir="$1"
  972. fmdir="$(pwd)"
  973. image="$fmdir"/"$2"
  974. cd "$rootdir"
  975. echo info: building $MACHINE for $ARCHITECTURE
  976. export DEBIAN_FRONTEND=noninteractive DEBCONF_NONINTERACTIVE_SEEN=true
  977. export LC_ALL=C LANGUAGE=C LANG=C
  978. # Override libpam-tmpdir setting during build, as the directories
  979. # are not created yet.
  980. export TMP=/tmp/ TMPDIR=/tmp/
  981. username=$MY_USERNAME
  982. echo $"warning: creating initial user $username with well known password!"
  983. password=$MY_PASSWORD
  984. chroot "$rootdir" adduser --gecos $username --disabled-password $username
  985. echo $username:$password | chroot $rootdir /usr/sbin/chpasswd
  986. chroot "$rootdir" adduser $username sudo
  987. case "$MACHINE" in
  988. virtualbox)
  989. # hide irrelevant console keyboard messages.
  990. echo "echo \"4 4 1 7\" > /proc/sys/kernel/printk" \
  991. >> /etc/init.d/rc.local
  992. ;;
  993. qemu)
  994. # hide irrelevant console keyboard messages.
  995. echo "echo \"4 4 1 7\" > /proc/sys/kernel/printk" \
  996. >> /etc/init.d/rc.local
  997. ;;
  998. esac
  999. set_apt_sources $BUILD_MIRROR
  1000. chroot "$rootdir" apt-get clean
  1001. chroot "$rootdir" rm -rf /var/lib/apt/lists/*
  1002. chroot "$rootdir" apt-get clean
  1003. chroot "$rootdir" apt-get update
  1004. cat > $rootdir/usr/sbin/policy-rc.d <<EOF
  1005. #!/bin/sh
  1006. exit 101
  1007. EOF
  1008. chmod a+rx $rootdir/usr/sbin/policy-rc.d
  1009. if $use_eatmydata ; then
  1010. enable_eatmydata_override
  1011. fi
  1012. if [ -n "$CUSTOM_SETUP" ]; then
  1013. cp "$CUSTOM_SETUP" "$rootdir"/tmp
  1014. chroot "$rootdir" apt-get install -y gdebi-core
  1015. chroot "$rootdir" gdebi -n /tmp/"$(basename $CUSTOM_SETUP)"
  1016. fi
  1017. chroot "$rootdir" apt-get install -y sudo git dialog toilet build-essential openssh-server
  1018. chroot "$rootdir" apt-get install -y avahi-daemon avahi-utils avahi-discover avahi-autoipd
  1019. chroot "$rootdir" apt-get install -y iptables dnsutils net-tools network-manager iputils-ping
  1020. chroot "$rootdir" apt-get install -y libnss-mdns libnss-myhostname libnss-gw-name nano man ntp
  1021. chroot "$rootdir" apt-get install -y locales locales-all debconf wireless-tools wpasupplicant
  1022. sed -i "s|#host-name=.*|host-name=${PROJECT_NAME}|g" $rootdir/etc/avahi/avahi-daemon.conf
  1023. sed -i "s|host-name=.*|host-name=${PROJECT_NAME}|g" $rootdir/etc/avahi/avahi-daemon.conf
  1024. chroot "$rootdir" /bin/bash -x <<EOF
  1025. git clone $PROJECT_REPO /root/$PROJECT_NAME
  1026. cd /root/$PROJECT_NAME
  1027. make install
  1028. EOF
  1029. chroot "$rootdir" ${PROJECT_NAME}-image-hardware-setup 2>&1 | \
  1030. tee $rootdir/var/log/${PROJECT_NAME}-image-hardware-setup.log
  1031. rm $rootdir/usr/sbin/policy-rc.d
  1032. # Set up HRNG for systems known to have one
  1033. # Otherwise install haveged
  1034. if [[ "$MACHINE" != "beaglebone" ]]; then
  1035. chroot $rootdir apt-get -y install haveged
  1036. else
  1037. chroot $rootdir apt-get -y install rng-tools
  1038. sed -i 's|#HRNGDEVICE=/dev/hwrng|HRNGDEVICE=/dev/hwrng|g' $rootdir/etc/default/rng-tools
  1039. fi
  1040. # copy u-boot to beginning of image
  1041. case "$MACHINE" in
  1042. beaglebone)
  1043. dd if=$rootdir/usr/lib/u-boot/am335x_boneblack/MLO of="$image" \
  1044. count=1 seek=1 conv=notrunc bs=128k
  1045. dd if=$rootdir/usr/lib/u-boot/am335x_boneblack/u-boot.img of="$image" \
  1046. count=2 seek=1 conv=notrunc bs=384k
  1047. ;;
  1048. cubieboard2)
  1049. dd if=$rootdir/usr/lib/u-boot/Cubieboard2/u-boot-sunxi-with-spl.bin of="$image" \
  1050. seek=8 conv=notrunc bs=1k
  1051. ;;
  1052. a20-olinuxino-lime)
  1053. dd if=$rootdir/usr/lib/u-boot/A20-OLinuXino-Lime/u-boot-sunxi-with-spl.bin \
  1054. of="$image" seek=8 conv=notrunc bs=1k
  1055. ;;
  1056. esac
  1057. if $use_eatmydata ; then
  1058. disable_eatmydata_override
  1059. fi
  1060. set_apt_sources $MIRROR
  1061. chroot "$rootdir" apt-get update
  1062. configure_ssh
  1063. configure_networking
  1064. admin_user_sudo
  1065. create_generic_image
  1066. atheros_wifi
  1067. continue_installation
  1068. initialise_mesh
  1069. configure_wifi
  1070. configure_user_interface
  1071. cd /
  1072. echo $"info: killing leftover processes in chroot"
  1073. fuser -mvk $rootdir/. || true
  1074. exit 0