freedombone-image-customise 42KB

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