freedombone-image-customise 40KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033
  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_initial_background.png
  77. # The browser application to use
  78. BROWSER=iceweasel
  79. MESH_INSTALL_DIR=/var/lib
  80. # for mesh installs whether to delete all data and generate
  81. # a new identity at every shutdown/boot
  82. AMNESIC='no'
  83. # defines the initial keyboard layout
  84. KEYBOARD_MAP='gb'
  85. # Strings used for setting the username
  86. MESH_TITLE=$"Freedombone Mesh"
  87. MESH_SET_USERNAME=$"Welcome to the Freedombone mesh.\n\nThe first thing you will need to do is set a username so that other peers can find you."
  88. # Whether to enable zeronet on the mesh
  89. ENABLE_ZERONET=
  90. MESH_TEXT_EDITOR='pluma'
  91. function configure_backports {
  92. echo "deb http://${DEBIAN_REPO}/debian/ ${DEBIAN_VERSION}-backports main" >> $rootdir/etc/apt/sources.list
  93. }
  94. function configure_contrib_repo {
  95. if ! grep -q "contrib" $rootdir/etc/apt/sources.list; then
  96. chroot "$rootdir" sed -i "s| main| main contrib|g" /etc/apt/sources.list
  97. fi
  98. }
  99. enable_eatmydata_override() {
  100. chroot $rootdir apt-get install --no-install-recommends -y eatmydata
  101. if [ -x $rootdir/usr/bin/eatmydata ] && \
  102. [ ! -f $rootdir/etc/apt/apt.conf.d/95debian-edu-install-dpkg-eatmydata ]; then
  103. echo $"info: Adding apt config to call dpkg via eatmydata"
  104. printf "#!/bin/sh\nexec eatmydata dpkg \"\$@\"\n" \
  105. > $rootdir/var/tmp/dpkg-eatmydata
  106. chmod 755 $rootdir/var/tmp/dpkg-eatmydata
  107. cat > $rootdir/etc/apt/apt.conf.d/95debian-edu-install-dpkg-eatmydata <<EOF
  108. Dir::Bin::dpkg "/var/tmp/dpkg-eatmydata";
  109. EOF
  110. else
  111. echo $"error: unable to find /usr/bin/eatmydata after installing the eatmydata package"
  112. fi
  113. }
  114. disable_eatmydata_override() {
  115. for override in \
  116. /etc/apt/apt.conf.d/95debian-edu-install-dpkg-eatmydata \
  117. /var/tmp/dpkg-eatmydata ; do
  118. echo $"info: Removing apt config to call dpkg via eatmydata"
  119. if [ -f $rootdir$override ] ; then
  120. rm -f $rootdir$override
  121. else
  122. echo $"warning: missing $rootdir$override"
  123. fi
  124. done
  125. sync # Flush file buffers before continuing
  126. }
  127. set_apt_sources() {
  128. NEW_MIRROR="$1"
  129. COMPONENTS="main"
  130. cat <<EOF > etc/apt/sources.list
  131. deb $NEW_MIRROR $SUITE $COMPONENTS
  132. deb-src $NEW_MIRROR $SUITE $COMPONENTS
  133. #deb http://security.debian.org/ $SUITE/updates main
  134. #deb-src http://security.debian.org/ $SUITE/updates main
  135. EOF
  136. }
  137. configure_networking() {
  138. if [[ $DEBIAN_INSTALL_ONLY != "no" ]]; then
  139. return
  140. fi
  141. if [[ $GENERIC_IMAGE == "no" ]]; then
  142. echo "# This file describes the network interfaces available on your system
  143. # and how to activate them. For more information, see interfaces(5).
  144. # The loopback network interface
  145. auto lo
  146. iface lo inet loopback
  147. # The primary network interface
  148. auto eth0
  149. iface eth0 inet static
  150. address $BOX_IP_ADDRESS
  151. netmask 255.255.255.0
  152. gateway $ROUTER_IP_ADDRESS
  153. dns-nameservers $NAMESERVER1 $NAMESERVER2
  154. # Example to keep MAC address between reboots
  155. #hwaddress ether B5:A2:BE:3F:1A:FE
  156. # The secondary network interface
  157. #auto eth1
  158. #iface eth1 inet dhcp
  159. # WiFi Example
  160. #auto wlan0
  161. #iface wlan0 inet dhcp
  162. # wpa-ssid \"essid\"
  163. # wpa-psk \"password\"
  164. # Ethernet/RNDIS gadget (g_ether)
  165. # ... or on host side, usbnet and random hwaddr
  166. # Note on some boards, usb0 is automaticly setup with an init script
  167. #iface usb0 inet static
  168. # address 192.168.7.2
  169. # netmask 255.255.255.0
  170. # network 192.168.7.0
  171. # gateway 192.168.7.1" > $rootdir/etc/network/interfaces
  172. hexarray=( 1 2 3 4 5 6 7 8 9 0 a b c d e f )
  173. a=${hexarray[$RANDOM%16]}${hexarray[$RANDOM%16]}
  174. b=${hexarray[$RANDOM%16]}${hexarray[$RANDOM%16]}
  175. c=${hexarray[$RANDOM%16]}${hexarray[$RANDOM%16]}
  176. d=${hexarray[$RANDOM%16]}${hexarray[$RANDOM%16]}
  177. e=${hexarray[$RANDOM%16]}${hexarray[$RANDOM%16]}
  178. sed -i "s|#hwaddress ether.*|hwaddress ether de:$a:$b:$c:$d:$e|g" \
  179. $rootdir/etc/network/interfaces
  180. fi
  181. sed -i "s/nameserver.*/nameserver $NAMESERVER1/g" $rootdir/etc/resolv.conf
  182. sed -i "/nameserver $NAMESERVER1/a\nameserver $NAMESERVER2" $rootdir/etc/resolv.conf
  183. if [[ $VARIANT != "meshclient" && $VARIANT != "meshusb" ]]; then
  184. # change the motd to show further install instructions
  185. echo $"
  186. .---. . .
  187. | | |
  188. |--- .--. .-. .-. .-.| .-. .--.--. |.-. .-. .--. .-.
  189. | | (.-' (.-' ( | ( )| | | | )( )| | (.-'
  190. ' ' --' --' -' - -' ' ' -' -' -' ' - --'
  191. Initial base install
  192. Your system is not yet installed. To complete the process run the
  193. following commands, then enter your details.
  194. sudo su
  195. ${PROJECT_NAME} menuconfig
  196. " > $rootdir/etc/motd
  197. else
  198. echo $"
  199. .---. . .
  200. | | |
  201. |--- .--. .-. .-. .-.| .-. .--.--. |.-. .-. .--. .-.
  202. | | (.-' (.-' ( | ( )| | | | )( )| | (.-'
  203. ' ' --' --' -' - -' ' ' -' -' -' ' - --'
  204. Freedom in the Mesh
  205. " > $rootdir/etc/motd
  206. fi
  207. }
  208. configure_ssh() {
  209. if [[ $VARIANT == "mesh" || $VARIANT == "meshclient" || $VARIANT == "meshusb" ]]; then
  210. return
  211. fi
  212. sed -i "s/Port .*/Port ${SSH_PORT}/g" $rootdir/etc/ssh/sshd_config
  213. if [[ "$SSH_PUBKEY" != "no" ]]; then
  214. if [ ! -d $rootdir/home/$MY_USERNAME/.ssh ]; then
  215. mkdir $rootdir/home/$MY_USERNAME/.ssh
  216. fi
  217. echo "$SSH_PUBKEY" > $rootdir/home/$MY_USERNAME/.ssh/authorized_keys
  218. chroot $rootdir chown -R $MY_USERNAME:$MY_USERNAME /home/$MY_USERNAME/.ssh
  219. sed -i 's|PasswordAuthentication.*|PasswordAuthentication no|g' $rootdir/etc/ssh/sshd_config
  220. echo $"Using ssh public key:"
  221. echo $SSH_PUBKEY
  222. echo $'Password ssh authentication turned off'
  223. fi
  224. }
  225. admin_user_sudo() {
  226. echo "$MY_USERNAME ALL=(ALL) ALL" >> $rootdir/etc/sudoers
  227. }
  228. create_generic_image() {
  229. if [[ $DEBIAN_INSTALL_ONLY != "no" ]]; then
  230. return
  231. fi
  232. if [[ $GENERIC_IMAGE == "no" ]]; then
  233. return
  234. fi
  235. if [ $CONFIG_FILENAME ]; then
  236. if [[ "$CONFIG_FILENAME" == *"mesh.cfg"* ]]; then
  237. VARIANT="mesh"
  238. fi
  239. fi
  240. # Don't install any configuration. This will be a base system
  241. if [[ $VARIANT != "mesh" && $VARIANT != "meshclient" && $VARIANT != "meshusb" ]]; then
  242. CONFIG_FILENAME=
  243. else
  244. touch $rootdir/root/.initial_mesh_setup
  245. fi
  246. # Stick with the existing login for mesh clients
  247. if [[ $VARIANT == "meshclient" || $VARIANT == "meshusb" ]]; then
  248. return
  249. fi
  250. # The presence of this file indicates that the initial
  251. # setup has not yet been completed
  252. touch $rootdir/home/$MY_USERNAME/.initial_setup
  253. chroot $rootdir chown $MY_USERNAME:$MY_USERNAME /home/$MY_USERNAME/.initial_setup
  254. touch $rootdir/root/.initial_setup
  255. cat >> $rootdir/home/$MY_USERNAME/.bashrc <<EOF
  256. # initial setup of the system
  257. if [ -f ~/.initial_setup ]; then
  258. clear
  259. echo "
  260. .---. . .
  261. | | |
  262. |--- .--. .-. .-. .-.| .-. .--.--. |.-. .-. .--. .-.
  263. | | (.-' (.-' ( | ( )| | | | )( )| | (.-'
  264. ' ' --' --' -' - -' ' ' -' -' -' ' - --'
  265. Initial setup process
  266. Please enter your password a second time.
  267. "
  268. sudo su
  269. fi
  270. EOF
  271. echo '# initial setup of the system' >> $rootdir/root/.bashrc
  272. echo 'if [ -f ~/.initial_setup ]; then' >> $rootdir/root/.bashrc
  273. echo ' if [ -f ~/login.txt ]; then' >> $rootdir/root/.bashrc
  274. echo ' NEW_USER_PASSWORD=$(printf `cat ~/login.txt`)' >> $rootdir/root/.bashrc
  275. echo ' else' >> $rootdir/root/.bashrc
  276. echo ' ENTROPY=$(cat /proc/sys/kernel/random/entropy_avail)' >> $rootdir/root/.bashrc
  277. echo ' if [ $ENTROPY -lt 500 ]; then' >> $rootdir/root/.bashrc
  278. ENTROPY_MESSAGE1=$'Initial setup process'
  279. ENTROPY_MESSAGE2=$'Password Generation'
  280. ENTROPY_MESSAGE3=$'WARNING: The entropy available on this system is too low to generate a password.\n\nThe installation process cannot continue.'
  281. echo " dialog --backtitle \"${ENTROPY_MESSAGE1}\" --title \"${ENTROPY_MESSAGE2}\" --msgbox \"${ENTROPY_MESSAGE3}\" 8 50" >> $rootdir/root/.bashrc
  282. echo ' exit' >> $rootdir/root/.bashrc
  283. echo ' fi' >> $rootdir/root/.bashrc
  284. echo -n ' NEW_USER_PASSWORD="$(openssl rand -base64 30 | cut -c1-' >> $rootdir/root/.bashrc
  285. echo "${MINIMUM_PASSWORD_LENGTH})\"" >> $rootdir/root/.bashrc
  286. echo ' fi' >> $rootdir/root/.bashrc
  287. echo ' echo "${NEW_USER_PASSWORD}" > ~/login.txt' >> $rootdir/root/.bashrc
  288. echo ' clear' >> $rootdir/root/.bashrc
  289. echo ' echo ""' >> $rootdir/root/.bashrc
  290. NEW_LOGIN_PASSWORD_MESSAGE1=$'Your new login password is:'
  291. NEW_LOGIN_PASSWORD_MESSAGE2=$'Use it whenever you wish to ssh into this system.'
  292. NEW_LOGIN_PASSWORD_MESSAGE3=$'IMPORTANT: Please take a moment to enter the above password into a\npassword manager or write it down somewhere.'
  293. PRESS_KEY_MESSAGE=$'Press any key to continue...'
  294. echo " echo \"${NEW_LOGIN_PASSWORD_MESSAGE1}\"" >> $rootdir/root/.bashrc
  295. echo ' echo ""' >> $rootdir/root/.bashrc
  296. echo ' toilet "${NEW_USER_PASSWORD}"' >> $rootdir/root/.bashrc
  297. echo ' echo ""' >> $rootdir/root/.bashrc
  298. echo ' echo " ${NEW_USER_PASSWORD}"' >> $rootdir/root/.bashrc
  299. echo ' echo ""' >> $rootdir/root/.bashrc
  300. echo " echo \"${NEW_LOGIN_PASSWORD_MESSAGE2}\"" >> $rootdir/root/.bashrc
  301. echo ' echo ""' >> $rootdir/root/.bashrc
  302. echo " echo \"${NEW_LOGIN_PASSWORD_MESSAGE3}\"" >> $rootdir/root/.bashrc
  303. echo ' echo ""' >> $rootdir/root/.bashrc
  304. echo " read -n1 -r -p \"${PRESS_KEY_MESSAGE}\" key" >> $rootdir/root/.bashrc
  305. # change the password for the admin user
  306. echo -n " echo \"${MY_USERNAME}:" >> $rootdir/root/.bashrc
  307. echo '$(printf `cat ~/login.txt`)"|chpasswd' >> $rootdir/root/.bashrc
  308. # update before continuing
  309. echo " cd /root/${PROJECT_NAME}" >> $rootdir/root/.bashrc
  310. echo " git stash" >> $rootdir/root/.bashrc
  311. echo " git pull" >> $rootdir/root/.bashrc
  312. echo " make install" >> $rootdir/root/.bashrc
  313. if [[ $VARIANT != "mesh" && $VARIANT != "meshclient" && $VARIANT != "meshusb" && $VARIANT != "usb" ]]; then
  314. if [[ $ONION_ONLY == "no" ]]; then
  315. if [[ $MINIMAL_INSTALL == "no" ]]; then
  316. echo " ${PROJECT_NAME} menuconfig-full" >> $rootdir/root/.bashrc
  317. else
  318. echo " ${PROJECT_NAME} menuconfig" >> $rootdir/root/.bashrc
  319. fi
  320. else
  321. echo " ${PROJECT_NAME} menuconfig-onion" >> $rootdir/root/.bashrc
  322. fi
  323. else
  324. echo " echo ''" >> $rootdir/root/.bashrc
  325. fi
  326. echo ' if [ "$?" = "0" ]; then' >> $rootdir/root/.bashrc
  327. echo " if [ -f ~/${PROJECT_NAME}-completed.txt ]; then" >> $rootdir/root/.bashrc
  328. # Remove the initial setup files
  329. echo ' rm /root/.initial_setup' >> $rootdir/root/.bashrc
  330. echo " rm /home/${MY_USERNAME}/.initial_setup" >> $rootdir/root/.bashrc
  331. echo " touch /root/.remove_${GENERIC_IMAGE_USERNAME}" >> $rootdir/root/.bashrc
  332. echo ' shred -zu ~/login.txt' >> $rootdir/root/.bashrc
  333. END_MESSAGE1=$'Congratulations!'
  334. if [[ $VARIANT != "mesh" && $VARIANT != "meshclient" && $VARIANT != "meshusb" && $VARIANT != "usb" ]]; then
  335. 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'
  336. echo ' SSH_ONION_HOSTNAME=$(cat /var/lib/tor/hidden_service_ssh/hostname)' >> $rootdir/root/.bashrc
  337. else
  338. END_MESSAGE2=$'\nYour system has now installed\n\nPress any key to reboot and begin using it'
  339. fi
  340. echo " dialog --title '$END_MESSAGE1' --msgbox \"$END_MESSAGE2\" 9 50" >> $rootdir/root/.bashrc
  341. echo ' reboot' >> $rootdir/root/.bashrc
  342. echo ' fi' >> $rootdir/root/.bashrc
  343. echo ' else' >> $rootdir/root/.bashrc
  344. echo ' key=' >> $rootdir/root/.bashrc
  345. echo ' while [[ $key != "x" ]]; do' >> $rootdir/root/.bashrc
  346. INSTALL_FAIL_MESSAGE=$"Install failed. Press x to continue..."
  347. echo " read -n1 -r -p \"${INSTALL_FAIL_MESSAGE}\" key" >> $rootdir/root/.bashrc
  348. echo ' done' >> $rootdir/root/.bashrc
  349. echo ' fi' >> $rootdir/root/.bashrc
  350. echo ' exit' >> $rootdir/root/.bashrc
  351. echo 'else' >> $rootdir/root/.bashrc
  352. echo ' # Remove default account after install' >> $rootdir/root/.bashrc
  353. echo " if [ -f /root/.remove_${GENERIC_IMAGE_USERNAME} ]; then" >> $rootdir/root/.bashrc
  354. echo " if [ -d /home/${GENERIC_IMAGE_USERNAME} ]; then" >> $rootdir/root/.bashrc
  355. echo " userdel -r ${GENERIC_IMAGE_USERNAME}" >> $rootdir/root/.bashrc
  356. echo " if [ -d /home/${GENERIC_IMAGE_USERNAME} ]; then" >> $rootdir/root/.bashrc
  357. echo " rm -rf /home/${GENERIC_IMAGE_USERNAME}" >> $rootdir/root/.bashrc
  358. echo " rm /root/.remove_${GENERIC_IMAGE_USERNAME}" >> $rootdir/root/.bashrc
  359. echo ' fi' >> $rootdir/root/.bashrc
  360. echo ' fi' >> $rootdir/root/.bashrc
  361. echo ' fi' >> $rootdir/root/.bashrc
  362. echo 'fi' >> $rootdir/root/.bashrc
  363. }
  364. continue_installation() {
  365. # If a configuration file exists then run with it
  366. # otherwise the interactive installer can be used
  367. # This is equivalent to installing freedombox-setup on freedombox
  368. if [ $CONFIG_FILENAME ]; then
  369. if [ ${#CONFIG_FILENAME} -gt 2 ]; then
  370. cp $CONFIG_FILENAME $rootdir/root/$PROJECT_NAME.cfg
  371. cat $rootdir/root/$PROJECT_NAME.cfg
  372. chroot "$rootdir" su -c "$PROJECT_NAME -c /root/$PROJECT_NAME.cfg" - root
  373. fi
  374. fi
  375. }
  376. atheros_wifi() {
  377. firmware_filename="open-ath9k-htc-firmware_1.3-1_all.deb"
  378. firmware_hash='5fea58ffefdf0ef15b504db7fbe3bc078c03e0d927bba64085e4b6f2546102f5'
  379. firmware_url="http://us.archive.trisquel.info/trisquel/pool/main/o/open-ath9k-htc-firmware/$firmware_filename"
  380. firmware_tempfile="/tmp/$firmware_filename"
  381. wget "$firmware_url" -O "$rootdir$firmware_tempfile"
  382. downloaded_firmware_hash=$(sha256sum "$rootdir$firmware_tempfile" | awk -F ' ' '{print $1}')
  383. if [[ "$downloaded_firmware_hash" == "$firmware_hash" ]]; then
  384. chroot "$rootdir" dpkg -i "$firmware_tempfile"
  385. else
  386. echo 'WARNING: Atheros Wifi firmware hash does not match. The driver has not been installed.'
  387. fi
  388. }
  389. configure_wifi() {
  390. if [[ $VARIANT == "mesh" || $VARIANT == "meshclient" || $VARIANT == "meshusb" ]]; then
  391. return
  392. fi
  393. if [ -f $WIFI_NETWORKS_FILE ]; then
  394. chroot "$rootdir" ${PROJECT_NAME}-wifi -i $WIFI_INTERFACE --networks $WIFI_NETWORKS_FILE
  395. return
  396. fi
  397. if [[ $WIFI_TYPE != 'none' ]]; then
  398. if [ ${#WIFI_PASSPHRASE} -lt 2 ]; then
  399. return
  400. fi
  401. chroot "$rootdir" ${PROJECT_NAME}-wifi -i $WIFI_INTERFACE -s $WIFI_SSID -t $WIFI_TYPE -p $WIFI_PASSPHRASE --hotspot $WIFI_HOTSPOT
  402. else
  403. chroot "$rootdir" ${PROJECT_NAME}-wifi -i $WIFI_INTERFACE -s $WIFI_SSID -t $WIFI_TYPE --hotspot $WIFI_HOTSPOT
  404. fi
  405. }
  406. ##############################################################################
  407. # Mesh networking
  408. ##############################################################################
  409. # for mesh installs
  410. TRACKER_PORT=6969
  411. WIFI_CHANNEL=2
  412. # B.A.T.M.A.N settings
  413. BATMAN_CELLID='02:BA:00:00:03:01'
  414. WIFI_SSID='mesh'
  415. # To avoid confusions these are obtained from the main project file
  416. TOXID_REPO=
  417. TOX_PORT=
  418. TOXCORE_REPO=
  419. TOXIC_REPO=
  420. TOXCORE_COMMIT=
  421. TOXIC_COMMIT=
  422. # These are some default nodes, but you can replace them with trusted nodes
  423. # as you prefer. See https://wiki.tox.im/Nodes
  424. TOX_NODES=
  425. #TOX_NODES=(
  426. # '192.254.75.102,2607:5600:284::2,33445,951C88B7E75C867418ACDB5D273821372BB5BD652740BCDF623A4FA293E75D2F,Tox RELENG,US'
  427. # '144.76.60.215,2a01:4f8:191:64d6::1,33445,04119E835DF3E78BACF0F84235B300546AF8B936F035185E2A8E9E0A67C8924F,sonOfRa,DE'
  428. #)
  429. # To avoid confusions these are obtained from the main project file
  430. ZERONET_REPO=
  431. ZERONET_COMMIT=
  432. ZERONET_PORT=
  433. ZERONET_BLOG_REPO=
  434. ZERONET_BLOG_COMMIT=
  435. ZERONET_MAIL_REPO=
  436. ZERONET_MAIL_COMMIT=
  437. ZERONET_FORUM_REPO=
  438. ZERONET_FORUM_COMMIT=
  439. ZERONET_ID_REPO=
  440. ZERONET_ID_COMMIT=
  441. # Directory where source code is downloaded and compiled
  442. INSTALL_DIR=$HOME/build
  443. INSTALLING_MESH=
  444. initialise_mesh() {
  445. if [[ $VARIANT != "mesh" && $VARIANT != "meshclient" && $VARIANT != "meshusb" ]]; then
  446. return
  447. fi
  448. if [[ $DEBIAN_INSTALL_ONLY != "no" ]]; then
  449. return
  450. fi
  451. if [[ $INSECURE == $'yes' ]]; then
  452. echo '*********************************************************'
  453. echo $'WARNING: non-free wifi drivers are being installed.'
  454. echo $' This may compromise the security of your system.'
  455. echo '*********************************************************'
  456. # enable non-free repo
  457. if ! grep -q "non-free" $rootdir/etc/apt/sources.list; then
  458. chroot "$rootdir" sed -i "s| main| main non-free|g" /etc/apt/sources.list
  459. fi
  460. chroot "$rootdir" apt-get update
  461. # install proprietary wifi drivers
  462. # see https://wiki.debian.org/iwlwifi
  463. chroot "$rootdir" apt-get -y install firmware-iwlwifi firmware-b43-installer firmware-brcm80211
  464. fi
  465. INSTALLING_MESH=1
  466. configure_firewall
  467. install_avahi
  468. install_batman
  469. install_tomb
  470. #install_tahoelafs
  471. #install_librevault
  472. #install_ipfs
  473. install_tox
  474. install_web_server
  475. if [ $ENABLE_ZERONET ]; then
  476. install_zeronet
  477. fi
  478. MESH_SERVICE='mesh-setup.service'
  479. MESH_SETUP_DAEMON=$rootdir/etc/systemd/system/$MESH_SERVICE
  480. MESH_STARTUP_PARAMS="${MY_USERNAME}"
  481. if [[ $AMNESIC != 'no' ]]; then
  482. MESH_STARTUP_PARAMS="${MY_USERNAME} amnesic"
  483. fi
  484. echo '[Unit]' > $MESH_SETUP_DAEMON
  485. echo 'Description=Initial mesh router configuration' >> $MESH_SETUP_DAEMON
  486. echo 'After=syslog.target' >> $MESH_SETUP_DAEMON
  487. echo 'After=network.target' >> $MESH_SETUP_DAEMON
  488. echo '[Service]' >> $MESH_SETUP_DAEMON
  489. echo 'Type=simple' >> $MESH_SETUP_DAEMON
  490. echo 'User=root' >> $MESH_SETUP_DAEMON
  491. echo 'Group=root' >> $MESH_SETUP_DAEMON
  492. echo 'WorkingDirectory=/root' >> $MESH_SETUP_DAEMON
  493. echo "ExecStart=/usr/local/bin/${PROJECT_NAME}-image-mesh ${MESH_STARTUP_PARAMS} > /var/log/mesh-setup.log" >> $MESH_SETUP_DAEMON
  494. echo '' >> $MESH_SETUP_DAEMON
  495. echo 'TimeoutSec=99999' >> $MESH_SETUP_DAEMON
  496. echo '' >> $MESH_SETUP_DAEMON
  497. echo '[Install]' >> $MESH_SETUP_DAEMON
  498. echo 'WantedBy=multi-user.target' >> $MESH_SETUP_DAEMON
  499. chroot "$rootdir" systemctl enable $MESH_SERVICE
  500. }
  501. # User interface for USB drive installs ######################################
  502. function mesh_client_startup_applications {
  503. if [ ! -d $rootdir/home/$MY_USERNAME/Desktop ]; then
  504. mkdir -p $rootdir/home/$MY_USERNAME/Desktop
  505. fi
  506. if [ ! -d $rootdir/home/$MY_USERNAME/.config/autostart ]; then
  507. mkdir -p $rootdir/home/$MY_USERNAME/.config/autostart
  508. chroot "$rootdir" chown -R $MY_USERNAME:$MY_USERNAME /home/$MY_USERNAME/.config
  509. fi
  510. START_DESKTOP=$rootdir/home/$MY_USERNAME/mesh-desktop.sh
  511. FIRST_BOOT=/home/$MY_USERNAME/.first_boot
  512. TAHOE_COMMAND="cd /var/lib/tahoelafs && venv/bin/tahoe"
  513. echo '#!/bin/bash' > $START_DESKTOP
  514. echo "setxkbmap ${KEYBOARD_MAP}" > $START_DESKTOP
  515. echo 'dconf write /org/mate/caja/desktop/volumes-visible false' >> $START_DESKTOP
  516. echo 'dconf write /org/mate/caja/desktop/computer-icon-visible false' >> $START_DESKTOP
  517. echo 'dconf write /org/mate/caja/desktop/home-icon-visible false' >> $START_DESKTOP
  518. echo 'dconf write /org/mate/caja/desktop/network-icon-visible false' >> $START_DESKTOP
  519. echo 'dconf write /org/mate/caja/desktop/trash-icon-visible false' >> $START_DESKTOP
  520. echo 'dconf write /org/mate/caja/desktop/volumes-visible false' >> $START_DESKTOP
  521. echo 'dconf write /org/mate/desktop/media-handling/automount-open false' >> $START_DESKTOP
  522. echo 'dconf write /org/mate/screensaver/lock-enabled false' >> $START_DESKTOP
  523. echo 'dconf write /org/mate/power-manager/lock-keyring-suspend false' >> $START_DESKTOP
  524. echo 'dconf write /org/mate/power-manager/lock-suspend false' >> $START_DESKTOP
  525. echo 'dconf write /org/mate/power-manager/lock-use-screensaver false' >> $START_DESKTOP
  526. echo 'dconf write /org/mate/power-manager/lock-blank-screen false' >> $START_DESKTOP
  527. echo 'dconf write /org/mate/power-manager/lock-hibernate false' >> $START_DESKTOP
  528. echo 'dconf write /org/mate/power-manager/lock-keyring-hibernate false' >> $START_DESKTOP
  529. echo 'dconf write /org/mate/desktop/peripherals/touchpad/scroll-method 2' >> $START_DESKTOP
  530. echo "touch /home/$MY_USERNAME/.dbus/Xdbus" >> $START_DESKTOP
  531. echo "chmod 600 /home/$MY_USERNAME/.dbus/Xdbus" >> $START_DESKTOP
  532. echo "env | grep DBUS_SESSION_BUS_ADDRESS > /home/$MY_USERNAME/.dbus/Xdbus" >> $START_DESKTOP
  533. echo "echo 'export DBUS_SESSION_BUS_ADDRESS' >> /home/$MY_USERNAME/.dbus/Xdbus" >> $START_DESKTOP
  534. echo '' >> $START_DESKTOP
  535. echo "amixer set 'Master' unmute" >> $START_DESKTOP
  536. echo "amixer set 'Master' 50%" >> $START_DESKTOP
  537. echo '' >> $START_DESKTOP
  538. echo '' >> $START_DESKTOP
  539. echo "if [ ! -f $FIRST_BOOT ]; then" >> $START_DESKTOP
  540. echo " $TAHOE_COMMAND start" >> $START_DESKTOP
  541. echo ' exit 0' >> $START_DESKTOP
  542. echo 'fi' >> $START_DESKTOP
  543. echo '' >> $START_DESKTOP
  544. echo 'INITIAL_TOX_USERNAME=' >> $START_DESKTOP
  545. echo 'while [ ! $INITIAL_TOX_USERNAME ]; do' >> $START_DESKTOP
  546. echo ' data=$(tempfile 2>/dev/null)' >> $START_DESKTOP
  547. echo ' trap "rm -f $data" 0 1 2 5 15' >> $START_DESKTOP
  548. echo -n " dialog --title \"${MESH_TITLE}\" " >> $START_DESKTOP
  549. echo -n "--backtitle \"${MESH_TITLE}\" " >> $START_DESKTOP
  550. echo -n "--inputbox \"${MESH_SET_USERNAME}\" 12 60 Anon " >> $START_DESKTOP
  551. echo '2>$data' >> $START_DESKTOP
  552. echo ' sel=$?' >> $START_DESKTOP
  553. echo ' case $sel in' >> $START_DESKTOP
  554. echo ' 0)' >> $START_DESKTOP
  555. echo ' INITIAL_TOX_USERNAME=$(<$data)' >> $START_DESKTOP
  556. echo ' if [ ${#INITIAL_TOX_USERNAME} -lt 1 ]; then' >> $START_DESKTOP
  557. echo ' INITIAL_TOX_USERNAME=' >> $START_DESKTOP
  558. echo ' fi' >> $START_DESKTOP
  559. echo ' ;;' >> $START_DESKTOP
  560. echo ' esac' >> $START_DESKTOP
  561. echo 'done' >> $START_DESKTOP
  562. echo '' >> $START_DESKTOP
  563. echo 'toxid --setuser "$INITIAL_TOX_USERNAME"' >> $START_DESKTOP
  564. echo '' >> $START_DESKTOP
  565. echo "if [ -f /home/$MY_USERNAME/.tahoe/tahoe.cfg ]; then" >> $START_DESKTOP
  566. echo " sed -i 's|nickname =.*|nickname = \$INITIAL_TOX_USERNAME|g' /home/$MY_USERNAME/.tahoe/tahoe.cfg" >> $START_DESKTOP
  567. echo " $TAHOE_COMMAND restart" >> $START_DESKTOP
  568. echo 'fi' >> $START_DESKTOP
  569. echo '' >> $START_DESKTOP
  570. echo "rm -f $FIRST_BOOT" >> $START_DESKTOP
  571. echo '' >> $START_DESKTOP
  572. echo 'exit 0' >> $START_DESKTOP
  573. chmod +x $START_DESKTOP
  574. START_DESKTOP2=$rootdir/home/$MY_USERNAME/.config/autostart/mesh-start.desktop
  575. echo '[Desktop Entry]' > $START_DESKTOP2
  576. echo 'Type=Application' >> $START_DESKTOP2
  577. echo 'Name=Mesh start desktop script' >> $START_DESKTOP2
  578. echo "Exec=bash -c '~/mesh-desktop.sh'" >> $START_DESKTOP2
  579. echo 'X-GNOME-Autostart-enabled=true' >> $START_DESKTOP2
  580. chmod +x $START_DESKTOP2
  581. START_DESKTOP3=$rootdir/home/$MY_USERNAME/.config/autostart/set_username.desktop
  582. echo '[Desktop Entry]' > $START_DESKTOP3
  583. echo 'Version=1.0' >> $START_DESKTOP3
  584. echo 'Name=Set Username' >> $START_DESKTOP3
  585. echo 'Type=Application' >> $START_DESKTOP3
  586. echo 'Comment=Set username' >> $START_DESKTOP3
  587. echo "Exec=mate-terminal -e \"bash -c /home/${MY_USERNAME}/mesh-desktop.sh\"" >> $START_DESKTOP3
  588. echo 'Icon=user-away' >> $START_DESKTOP3
  589. echo 'Terminal=false' >> $START_DESKTOP3
  590. echo 'Categories=Application;' >> $START_DESKTOP3
  591. chmod +x $START_DESKTOP3
  592. }
  593. function mesh_desktop_icons {
  594. if [ ! -d $rootdir/home/$MY_USERNAME/Desktop ]; then
  595. mkdir -p $rootdir/home/$MY_USERNAME/Desktop
  596. fi
  597. # Terminal
  598. #echo '[Desktop Entry]' > $rootdir/home/$MY_USERNAME/Desktop/terminal.desktop
  599. #echo 'Name=MATE Terminal' >> $rootdir/home/$MY_USERNAME/Desktop/terminal.desktop
  600. #echo 'Type=Application' >> $rootdir/home/$MY_USERNAME/Desktop/terminal.desktop
  601. #echo 'Comment=Use the command line' >> $rootdir/home/$MY_USERNAME/Desktop/terminal.desktop
  602. #echo 'TryExec=mate-terminal' >> $rootdir/home/$MY_USERNAME/Desktop/terminal.desktop
  603. #echo 'Exec=mate-terminal' >> $rootdir/home/$MY_USERNAME/Desktop/terminal.desktop
  604. #echo 'Icon=terminal' >> $rootdir/home/$MY_USERNAME/Desktop/terminal.desktop
  605. #echo 'StartupNotify=true' >> $rootdir/home/$MY_USERNAME/Desktop/terminal.desktop
  606. chroot "$rootdir" chown -R $MY_USERNAME:$MY_USERNAME /home/$MY_USERNAME/Desktop
  607. }
  608. function configure_user_interface {
  609. if [[ $VARIANT != "meshclient" && $VARIANT != "meshusb" && $VARIANT != "usb" ]]; then
  610. return
  611. fi
  612. # desktop
  613. chroot "$rootdir" apt-get -y install mate-desktop-environment
  614. # tool to change desktop settings from command line
  615. chroot "$rootdir" apt-get -y install dconf-cli dconf-gsettings-backend dbus dbus-x11
  616. # for tomb
  617. chroot "$rootdir" apt-get -y install pinentry-gtk2
  618. # for tox video
  619. chroot "$rootdir" apt-get -y install ffmpeg cheese v4l-utils
  620. # to provide notifications
  621. chroot "$rootdir" apt-get -y install libnotify-bin
  622. # for video/audio
  623. chroot "$rootdir" apt-get -y install libtheora-bin libvorbis-dev v4l-utils
  624. # a sane editor
  625. chroot "$rootdir" apt-get -y install emacs24
  626. # for sound level control
  627. chroot "$rootdir" apt-get -y install alsa-utils
  628. # android adb to allow phones to be connected and for example transfer photos/documents
  629. chroot "$rootdir" apt-get -y install android-tools-adb
  630. # Produce a text file on the desktop listing users on the mesh
  631. cat <<EOF > $rootdir/usr/bin/list-tox-users
  632. #!/bin/bash
  633. users_list=\$(lstox | awk -F ' ' '{\$1=""; print \$0}' | sed -e 's/^[[:space:]]*//' | sort -d)
  634. if [ ! \$users_list ]; then
  635. no_of_users=0
  636. else
  637. no_of_users=\$(echo "\$users_list" | wc -l)
  638. fi
  639. if [ \$no_of_users -gt 0 ]; then
  640. echo "\$users_list" > /home/$MY_USERNAME/Users.txt
  641. chown $MY_USERNAME:$MY_USERNAME /home/$MY_USERNAME/Users.txt
  642. echo 'showing_users=\$(ps aux | grep $MESH_TEXT_EDITOR | grep "Users.txt")' > /home/$MY_USERNAME/showusers
  643. echo 'if [ \${#showing_users} -eq 0 ]; then' >> /home/$MY_USERNAME/showusers
  644. echo ' $MESH_TEXT_EDITOR /home/$MY_USERNAME/Users.txt' >> /home/$MY_USERNAME/showusers
  645. echo 'fi' >> /home/$MY_USERNAME/showusers
  646. echo 'exit 0' >> /home/$MY_USERNAME/showusers
  647. chmod +x /home/$MY_USERNAME/showusers
  648. chown $MY_USERNAME:$MY_USERNAME /home/$MY_USERNAME/showusers
  649. echo '[Desktop Entry]' > /home/$MY_USERNAME/Desktop/Users.desktop
  650. if [ \$no_of_users -lt 2 ]; then
  651. echo "Name=\$no_of_users Other User" >> /home/$MY_USERNAME/Desktop/Users.desktop
  652. else
  653. echo "Name=\$no_of_users Other Users" >> /home/$MY_USERNAME/Desktop/Users.desktop
  654. fi
  655. echo 'Type=Application' >> /home/$MY_USERNAME/Desktop/Users.desktop
  656. echo 'Comment=List of users' >> /home/$MY_USERNAME/Desktop/Users.desktop
  657. echo 'Exec=bash /home/$MY_USERNAME/showusers' >> /home/$MY_USERNAME/Desktop/Users.desktop
  658. echo 'Icon=/usr/share/freedombone/avatars/anon002.jpg' >> /home/$MY_USERNAME/Desktop/Users.desktop
  659. echo 'StartupNotify=false' >> /home/$MY_USERNAME/Desktop/Users.desktop
  660. chmod +x /home/$MY_USERNAME/Desktop/Users.desktop
  661. chown $MY_USERNAME:$MY_USERNAME /home/$MY_USERNAME/Desktop/Users.desktop
  662. if [ ! -f /home/$MY_USERNAME/runtox ]; then
  663. echo 'qtox_running=\$(ps aux | grep qtox | grep data)' > /home/$MY_USERNAME/runtox
  664. echo 'if [ \${#qtox_running} -eq 0 ]; then' >> /home/$MY_USERNAME/runtox
  665. echo ' bash -c "qtox -p data"' >> /home/$MY_USERNAME/runtox
  666. echo 'fi' >> /home/$MY_USERNAME/runtox
  667. echo 'exit 0' >> /home/$MY_USERNAME/runtox
  668. chmod +x /home/$MY_USERNAME/runtox
  669. chown $MY_USERNAME:$MY_USERNAME /home/$MY_USERNAME/runtox
  670. echo '[Desktop Entry]' > /home/$MY_USERNAME/Desktop/tox.desktop
  671. echo 'Name=Tox Chat' >> /home/$MY_USERNAME/Desktop/tox.desktop
  672. echo 'Type=Application' >> /home/$MY_USERNAME/Desktop/tox.desktop
  673. echo 'Comment=Chat, VoIP and Video' >> /home/$MY_USERNAME/Desktop/tox.desktop
  674. echo 'Exec=bash /home/$MY_USERNAME/runtox' >> /home/$MY_USERNAME/Desktop/tox.desktop
  675. echo 'Icon=/usr/share/icons/hicolor/32x32/apps/qtox.png' >> /home/$MY_USERNAME/Desktop/tox.desktop
  676. echo 'StartupNotify=true' >> /home/$MY_USERNAME/Desktop/tox.desktop
  677. chmod +x /home/$MY_USERNAME/Desktop/tox.desktop
  678. chown $MY_USERNAME:$MY_USERNAME /home/$MY_USERNAME/Desktop/tox.desktop
  679. fi
  680. else
  681. if [ -f /home/$MY_USERNAME/Users.txt ]; then
  682. rm /home/$MY_USERNAME/Users.txt
  683. rm /home/$MY_USERNAME/Desktop/Users.desktop
  684. if [ -f /home/$MY_USERNAME/Desktop/Users.desktop ]; then
  685. rm /home/$MY_USERNAME/Desktop/Users.desktop
  686. fi
  687. if [ -f /home/$MY_USERNAME/Desktop/tox.desktop ]; then
  688. rm /home/$MY_USERNAME/Desktop/tox.desktop
  689. fi
  690. pkill qtox
  691. fi
  692. fi
  693. EOF
  694. chroot "$rootdir" chown $MY_USERNAME:$MY_USERNAME /usr/bin/list-tox-users
  695. chroot "$rootdir" chmod +x /usr/bin/list-tox-users
  696. echo "* * * * * $MY_USERNAME bash -c /usr/bin/list-tox-users > /dev/null" >> $rootdir/etc/crontab
  697. if [[ $VARIANT != "usb" ]]; then
  698. # log in automatically
  699. chroot "$rootdir" apt-get -y install nodm xinit
  700. echo 'NODM_ENABLED=true' > /etc/default/nodm
  701. echo "NODM_USER=$MY_USERNAME" >> /etc/default/nodm
  702. chroot "$rootdir" mkdir /etc/systemd/system/getty@tty1.service.d
  703. echo '[Service]' > $rootdir/etc/systemd/system/getty@tty1.service.d/override.conf
  704. echo 'ExecStart=' >> $rootdir/etc/systemd/system/getty@tty1.service.d/override.conf
  705. echo 'ExecStart=-/sbin/agetty --autologin fbone --noclear %I $TERM' >> $rootdir/etc/systemd/system/getty@tty1.service.d/override.conf
  706. echo '[[ -z $DISPLAY && $XDG_VTNR -eq 1 ]] && exec startx' >> $rootdir/home/$MY_USERNAME/.profile
  707. chroot "$rootdir" systemctl set-default multi-user.target
  708. mesh_client_startup_applications
  709. mesh_desktop_icons
  710. # Different desktop background for amnesic
  711. if [[ $AMNESIC != 'no' ]]; then
  712. MESH_DESKTOP_BACKGROUND_IMAGE=/usr/local/share/${PROJECT_NAME}_mesh_amnesic_background.png
  713. fi
  714. # change the desktop background
  715. if [ $MESH_DESKTOP_BACKGROUND_IMAGE ]; then
  716. if [ -f $MESH_DESKTOP_BACKGROUND_IMAGE ]; then
  717. if [ -d $rootdir/usr/share/images/desktop-base ]; then
  718. cp $MESH_DESKTOP_BACKGROUND_IMAGE $rootdir/usr/share/images/desktop-base/${PROJECT_NAME}_mesh_background.png
  719. chroot "$rootdir" rm /usr/share/images/desktop-base/desktop-background
  720. chroot "$rootdir" ln -s /usr/share/images/desktop-base/${PROJECT_NAME}_mesh_background.png /usr/share/images/desktop-base/desktop-background
  721. fi
  722. fi
  723. fi
  724. else
  725. chroot "$rootdir" apt-get -y install lightdm
  726. fi
  727. # browser
  728. chroot "$rootdir" apt-get -y install $BROWSER
  729. # Tox user interface
  730. enable_tox_repo
  731. mesh_tox_qtox
  732. # copy the default qtox ini file
  733. if [ ! -d ${rootdir}/home/${MY_USERNAME}/.config/tox ]; then
  734. mkdir ${rootdir}/home/${MY_USERNAME}/.config/tox
  735. cp /usr/local/bin/freedombone-config-qtox ${rootdir}/home/${MY_USERNAME}/.config/tox/qtox.ini
  736. chroot "$rootdir" chown -R ${MY_USERNAME}:${MY_USERNAME} /home/${MY_USERNAME}/.config
  737. fi
  738. if [[ $VARIANT == "usb" ]]; then
  739. # tor
  740. chroot "$rootdir" apt-get -y install tor
  741. # xmpp client
  742. chroot "$rootdir" echo "deb ftp://ftp.gajim.org/debian unstable main" > /etc/apt/sources.list.d/gajim.list
  743. chroot "$rootdir" apt-get update
  744. chroot "$rootdir" apt-get -y install gajim-dev-keyring
  745. chroot "$rootdir" apt-get -y install git python-dev python-pip gajim-nightly
  746. chroot "$rootdir" mkdir /home/$GENERIC_IMAGE_USERNAME/.local/share/gajim/plugins -p
  747. chroot "$rootdir" git clone https://github.com/omemo/gajim-omemo /home/$GENERIC_IMAGE_USERNAME/.local/share/gajim/plugins/gajim-omemo
  748. chroot "$rootdir" pip install protobuf==2.6.1, python-axolotl==0.1.35
  749. chroot "$rootdir" chown -R $GENERIC_IMAGE_USERNAME:$GENERIC_IMAGE_USERNAME /home/$GENERIC_IMAGE_USERNAME/.local
  750. # IRC client
  751. chroot "$rootdir" apt-get -y install hexchat profanity
  752. fi
  753. }
  754. ##############################################################################
  755. # Set to true/false to control if eatmydata is used during build
  756. use_eatmydata=true
  757. rootdir="$1"
  758. fmdir="$(pwd)"
  759. image="$fmdir"/"$2"
  760. cd "$rootdir"
  761. echo info: building $MACHINE for $ARCHITECTURE
  762. export DEBIAN_FRONTEND=noninteractive DEBCONF_NONINTERACTIVE_SEEN=true
  763. export LC_ALL=C LANGUAGE=C LANG=C
  764. # Override libpam-tmpdir setting during build, as the directories
  765. # are not created yet.
  766. export TMP=/tmp/ TMPDIR=/tmp/
  767. if [ ! $MY_USERNAME ]; then
  768. echo $'No username was specified'
  769. exit 52825
  770. fi
  771. username=$MY_USERNAME
  772. echo $"warning: creating initial user $username with well known password!"
  773. password=$MY_PASSWORD
  774. chroot "$rootdir" adduser --gecos $username --disabled-password $username
  775. echo $username:$password | chroot $rootdir /usr/sbin/chpasswd
  776. chroot "$rootdir" adduser $username sudo
  777. case "$MACHINE" in
  778. virtualbox)
  779. # hide irrelevant console keyboard messages.
  780. echo "echo \"4 4 1 7\" > /proc/sys/kernel/printk" \
  781. >> /etc/init.d/rc.local
  782. ;;
  783. qemu)
  784. # hide irrelevant console keyboard messages.
  785. echo "echo \"4 4 1 7\" > /proc/sys/kernel/printk" \
  786. >> /etc/init.d/rc.local
  787. ;;
  788. esac
  789. if [ ! $DEBIAN_REPO ]; then
  790. DEBIAN_REPO='ftp.de.debian.org'
  791. fi
  792. if [ ! $DEBIAN_VERSION ]; then
  793. DEBIAN_VERSION='jessie'
  794. fi
  795. set_apt_sources $BUILD_MIRROR
  796. chroot "$rootdir" apt-get clean
  797. chroot "$rootdir" rm -rf /var/lib/apt/lists/*
  798. chroot "$rootdir" apt-get clean
  799. set_apt_sources $MIRROR
  800. configure_backports
  801. configure_contrib_repo
  802. chroot "$rootdir" apt-get update
  803. cat > $rootdir/usr/sbin/policy-rc.d <<EOF
  804. #!/bin/sh
  805. exit 101
  806. EOF
  807. chmod a+rx $rootdir/usr/sbin/policy-rc.d
  808. if $use_eatmydata ; then
  809. enable_eatmydata_override
  810. fi
  811. if [ -n "$CUSTOM_SETUP" ]; then
  812. cp "$CUSTOM_SETUP" "$rootdir"/tmp
  813. chroot "$rootdir" apt-get install -y gdebi-core
  814. chroot "$rootdir" gdebi -n /tmp/"$(basename $CUSTOM_SETUP)"
  815. fi
  816. if [[ $VARIANT != "meshclient" && $VARIANT != "meshusb" && $VARIANT != "mesh" ]]; then
  817. chroot "$rootdir" apt-get install -y openssh-server
  818. fi
  819. chroot "$rootdir" apt-get install -y sudo git dialog toilet build-essential
  820. chroot "$rootdir" apt-get install -y avahi-daemon avahi-utils avahi-discover avahi-autoipd
  821. chroot "$rootdir" apt-get install -y iptables dnsutils net-tools network-manager iputils-ping
  822. chroot "$rootdir" apt-get install -y libnss-mdns libnss-myhostname libnss-gw-name nano man ntp
  823. chroot "$rootdir" apt-get install -y locales locales-all debconf wireless-tools wpasupplicant
  824. chroot "$rootdir" apt-get install -y usbutils cryptsetup zsh pinentry-curses iotop bc
  825. sed -i "s|#host-name=.*|host-name=${PROJECT_NAME}|g" $rootdir/etc/avahi/avahi-daemon.conf
  826. sed -i "s|host-name=.*|host-name=${PROJECT_NAME}|g" $rootdir/etc/avahi/avahi-daemon.conf
  827. chroot "$rootdir" /bin/bash -x <<EOF
  828. git clone $PROJECT_REPO /root/$PROJECT_NAME
  829. cd /root/$PROJECT_NAME
  830. git checkout origin/stockholm -b stockholm
  831. make install
  832. EOF
  833. chroot "$rootdir" ${PROJECT_NAME}-image-hardware-setup 2>&1 | \
  834. tee $rootdir/var/log/${PROJECT_NAME}-image-hardware-setup.log
  835. rm $rootdir/usr/sbin/policy-rc.d
  836. # Set up HRNG for systems known to have one
  837. # Otherwise install haveged
  838. if [[ "$MACHINE" != "beaglebone" ]]; then
  839. chroot $rootdir apt-get -y install haveged
  840. else
  841. chroot $rootdir apt-get -y install rng-tools
  842. sed -i 's|#HRNGDEVICE=/dev/hwrng|HRNGDEVICE=/dev/hwrng|g' $rootdir/etc/default/rng-tools
  843. fi
  844. # copy u-boot to beginning of image
  845. case "$MACHINE" in
  846. beaglebone)
  847. dd if=$rootdir/usr/lib/u-boot/am335x_boneblack/MLO of="$image" \
  848. count=1 seek=1 conv=notrunc bs=128k
  849. dd if=$rootdir/usr/lib/u-boot/am335x_boneblack/u-boot.img of="$image" \
  850. count=2 seek=1 conv=notrunc bs=384k
  851. ;;
  852. cubieboard2)
  853. dd if=$rootdir/usr/lib/u-boot/Cubieboard2/u-boot-sunxi-with-spl.bin of="$image" \
  854. seek=8 conv=notrunc bs=1k
  855. ;;
  856. a20-olinuxino-lime)
  857. dd if=$rootdir/usr/lib/u-boot/A20-OLinuXino-Lime/u-boot-sunxi-with-spl.bin \
  858. of="$image" seek=8 conv=notrunc bs=1k
  859. ;;
  860. esac
  861. if $use_eatmydata ; then
  862. disable_eatmydata_override
  863. fi
  864. configure_ssh
  865. configure_networking
  866. admin_user_sudo
  867. create_generic_image
  868. atheros_wifi
  869. continue_installation
  870. initialise_mesh
  871. configure_wifi
  872. configure_user_interface
  873. # remove downloaded packages
  874. chroot $rootdir apt-get clean
  875. cd /
  876. echo $"info: killing leftover processes in chroot"
  877. fuser -mvk $rootdir/. || true
  878. exit 0