freedombone-image-customise 53KB

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