freedombone-image-customise 45KB

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