freedombone-image-customise 62KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495
  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. LOCAL_NAME=${PROJECT_NAME}
  32. INSTALL_DIR=/root/build
  33. COMPLETION_FILE=$HOME/${PROJECT_NAME}-completed.txt
  34. PROJECT_REPO="https://github.com/bashrc/${PROJECT_NAME}"
  35. VARIANT='full'
  36. # username created by default within a debian image
  37. GENERIC_IMAGE_USERNAME='fbone'
  38. export TEXTDOMAIN=${PROJECT_NAME}-image-customise
  39. export TEXTDOMAINDIR="/usr/share/locale"
  40. # Whether to minimise the number of decisions during interactive install
  41. MINIMAL_INSTALL="yes"
  42. MY_USERNAME='debian'
  43. MY_PASSWORD="${PROJECT_NAME}"
  44. # Minimum number of characters in a password
  45. MINIMUM_PASSWORD_LENGTH=10
  46. # IP address of the router (gateway)
  47. ROUTER_IP_ADDRESS="192.168.1.254"
  48. # The fixed IP address of the Beaglebone Black on your local network
  49. BOX_IP_ADDRESS="192.168.1.55"
  50. # DNS
  51. NAMESERVER1='213.73.91.35'
  52. NAMESERVER2='85.214.20.141'
  53. # optional configuration file containing freedombone settings
  54. CONFIG_FILENAME=
  55. # Optional ssh public key to allow
  56. SSH_PUBKEY="no"
  57. # Whether this is a generic image for mass redistribution on the interwebs
  58. GENERIC_IMAGE="no"
  59. # default SSH port
  60. SSH_PORT=2222
  61. # for mesh installs
  62. TRACKER_PORT=6969
  63. # Whether sites are accessible only within a Tor browser
  64. ONION_ONLY="no"
  65. # Whether to only install debian and nothing else
  66. DEBIAN_INSTALL_ONLY="no"
  67. # wifi settings
  68. WIFI_INTERFACE='wlan0'
  69. WIFI_SSID=
  70. WIFI_TYPE='wpa2-psk'
  71. WIFI_PASSPHRASE=
  72. WIFI_HOTSPOT='no'
  73. WIFI_NETWORKS_FILE=~/${PROJECT_NAME}-wifi.cfg
  74. # Whether to install non-free wifi drivers for the mesh client
  75. INSECURE='no'
  76. # optional desktop background image for mesh
  77. MESH_DESKTOP_BACKGROUND_IMAGE=/usr/local/share/${PROJECT_NAME}_mesh_initial_background.png
  78. # The browser application to use
  79. BROWSER=midori
  80. MESH_INSTALL_DIR=/var/lib
  81. # for mesh installs whether to delete all data and generate
  82. # a new identity at every shutdown/boot
  83. AMNESIC='no'
  84. # Whether this is a dedicated gnusocial or postactiv instance
  85. SOCIALINSTANCE=
  86. # defines the initial keyboard layout
  87. KEYBOARD_MAP='gb'
  88. # Strings used for setting the username
  89. MESH_TITLE=$"Freedombone Mesh"
  90. 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."
  91. # Whether to enable zeronet on the mesh
  92. ENABLE_ZERONET=
  93. MESH_TEXT_EDITOR='pluma'
  94. PATH=/usr/local/bin:/usr/local/sbin:/usr/bin:/usr/sbin:/bin:/sbin
  95. function configure_backports {
  96. echo "deb http://${DEBIAN_REPO}/debian/ ${DEBIAN_VERSION}-backports main" >> $rootdir/etc/apt/sources.list
  97. }
  98. function configure_contrib_repo {
  99. if ! grep -q "contrib" $rootdir/etc/apt/sources.list; then
  100. chroot "$rootdir" /bin/sed -i "s| main| main contrib|g" /etc/apt/sources.list
  101. fi
  102. }
  103. enable_eatmydata_override() {
  104. chroot $rootdir apt-get install -y eatmydata
  105. if [ -x $rootdir/usr/bin/eatmydata ] && \
  106. [ ! -f $rootdir/etc/apt/apt.conf.d/95debian-edu-install-dpkg-eatmydata ]; then
  107. echo $"info: Adding apt config to call dpkg via eatmydata"
  108. printf "#!/bin/sh\nexec eatmydata dpkg \"\$@\"\n" \
  109. > $rootdir/var/tmp/dpkg-eatmydata
  110. chmod 755 $rootdir/var/tmp/dpkg-eatmydata
  111. cat > $rootdir/etc/apt/apt.conf.d/95debian-edu-install-dpkg-eatmydata <<EOF
  112. Dir::Bin::dpkg "/var/tmp/dpkg-eatmydata";
  113. EOF
  114. else
  115. echo $"error: unable to find /usr/bin/eatmydata after installing the eatmydata package"
  116. fi
  117. }
  118. disable_eatmydata_override() {
  119. for override in \
  120. /etc/apt/apt.conf.d/95debian-edu-install-dpkg-eatmydata \
  121. /var/tmp/dpkg-eatmydata ; do
  122. echo $"info: Removing apt config to call dpkg via eatmydata"
  123. if [ -f $rootdir$override ] ; then
  124. rm -f $rootdir$override
  125. else
  126. echo $"warning: missing $rootdir$override"
  127. fi
  128. done
  129. sync # Flush file buffers before continuing
  130. }
  131. set_apt_sources() {
  132. NEW_MIRROR="$1"
  133. COMPONENTS="main"
  134. cat <<EOF > etc/apt/sources.list
  135. deb $NEW_MIRROR $SUITE $COMPONENTS
  136. deb-src $NEW_MIRROR $SUITE $COMPONENTS
  137. #deb http://security.debian.org/ $SUITE/updates main
  138. #deb-src http://security.debian.org/ $SUITE/updates main
  139. EOF
  140. }
  141. configure_networking() {
  142. if [[ "$MACHINE" == "beaglebonewifi" ]]; then
  143. # Allow networking over USB in order to configure the
  144. # wifi login settings
  145. echo 'auto lo' > $rootdir/etc/network/interfaces
  146. echo 'iface lo inet loopback' >> $rootdir/etc/network/interfaces
  147. echo '' >> $rootdir/etc/network/interfaces
  148. echo 'iface usb0 inet static' >> $rootdir/etc/network/interfaces
  149. echo ' address 192.168.7.2' >> $rootdir/etc/network/interfaces
  150. echo ' netmask 255.255.255.252' >> $rootdir/etc/network/interfaces
  151. echo ' network 192.168.7.0' >> $rootdir/etc/network/interfaces
  152. echo ' gateway 192.168.7.1' >> $rootdir/etc/network/interfaces
  153. return
  154. fi
  155. if [[ $DEBIAN_INSTALL_ONLY != "no" ]]; then
  156. return
  157. fi
  158. if [[ $GENERIC_IMAGE == "no" ]]; then
  159. echo "# This file describes the network interfaces available on your system
  160. # and how to activate them. For more information, see interfaces(5).
  161. # The loopback network interface
  162. auto lo
  163. iface lo inet loopback
  164. # The primary network interface
  165. auto eth0
  166. iface eth0 inet static
  167. address $BOX_IP_ADDRESS
  168. netmask 255.255.255.0
  169. gateway $ROUTER_IP_ADDRESS
  170. dns-nameservers $NAMESERVER1 $NAMESERVER2
  171. # Example to keep MAC address between reboots
  172. #hwaddress ether B5:A2:BE:3F:1A:FE
  173. # The secondary network interface
  174. #auto eth1
  175. #iface eth1 inet dhcp
  176. # WiFi Example
  177. #auto wlan0
  178. #iface wlan0 inet dhcp
  179. # wpa-ssid \"essid\"
  180. # wpa-psk \"password\"
  181. # Ethernet/RNDIS gadget (g_ether)
  182. # ... or on host side, usbnet and random hwaddr
  183. # Note on some boards, usb0 is automaticly setup with an init script
  184. #iface usb0 inet static
  185. # address 192.168.7.2
  186. # netmask 255.255.255.0
  187. # network 192.168.7.0
  188. # gateway 192.168.7.1" > $rootdir/etc/network/interfaces
  189. hexarray=( 1 2 3 4 5 6 7 8 9 0 a b c d e f )
  190. a=${hexarray[$RANDOM%16]}${hexarray[$RANDOM%16]}
  191. b=${hexarray[$RANDOM%16]}${hexarray[$RANDOM%16]}
  192. c=${hexarray[$RANDOM%16]}${hexarray[$RANDOM%16]}
  193. d=${hexarray[$RANDOM%16]}${hexarray[$RANDOM%16]}
  194. e=${hexarray[$RANDOM%16]}${hexarray[$RANDOM%16]}
  195. sed -i "s|#hwaddress ether.*|hwaddress ether de:$a:$b:$c:$d:$e|g" \
  196. $rootdir/etc/network/interfaces
  197. fi
  198. # configure DNS
  199. resolvconf=$rootdir/etc/resolv.conf
  200. echo 'domain localdomain' > $resolvconf
  201. echo 'search localdomain' >> $resolvconf
  202. echo "nameserver $NAMESERVER1" >> $resolvconf
  203. echo "nameserver $NAMESERVER2" >> $resolvconf
  204. echo "nameserver $NAMESERVER3" >> $resolvconf
  205. echo "nameserver $NAMESERVER4" >> $resolvconf
  206. echo "nameserver $NAMESERVER5" >> $resolvconf
  207. echo "nameserver $NAMESERVER6" >> $resolvconf
  208. if [[ $VARIANT != "meshclient" && $VARIANT != "meshusb" ]]; then
  209. # change the motd to show further install instructions
  210. echo $"
  211. .---. . .
  212. | | |
  213. |--- .--. .-. .-. .-.| .-. .--.--. |.-. .-. .--. .-.
  214. | | (.-' (.-' ( | ( )| | | | )( )| | (.-'
  215. ' ' --' --' -' - -' ' ' -' -' -' ' - --'
  216. Initial base install
  217. Your system is not yet installed. To complete the process run the
  218. following commands, then enter your details.
  219. sudo su
  220. ${PROJECT_NAME} menuconfig
  221. " > $rootdir/etc/motd
  222. else
  223. echo $"
  224. .---. . .
  225. | | |
  226. |--- .--. .-. .-. .-.| .-. .--.--. |.-. .-. .--. .-.
  227. | | (.-' (.-' ( | ( )| | | | )( )| | (.-'
  228. ' ' --' --' -' - -' ' ' -' -' -' ' - --'
  229. Freedom in the Mesh
  230. " > $rootdir/etc/motd
  231. fi
  232. }
  233. configure_ssh() {
  234. if [[ $VARIANT == "mesh"* ]]; then
  235. return
  236. fi
  237. sed -i "s/Port .*/Port ${SSH_PORT}/g" $rootdir/etc/ssh/sshd_config
  238. sed -i "s/#Port ${SSH_PORT}/Port ${SSH_PORT}/g" $rootdir/etc/ssh/sshd_config
  239. if [[ "$SSH_PUBKEY" != "no" ]]; then
  240. if [ ! -d $rootdir/home/$MY_USERNAME/.ssh ]; then
  241. mkdir $rootdir/home/$MY_USERNAME/.ssh
  242. fi
  243. echo "$SSH_PUBKEY" > $rootdir/home/$MY_USERNAME/.ssh/authorized_keys
  244. chroot $rootdir /bin/chown -R $MY_USERNAME:$MY_USERNAME /home/$MY_USERNAME/.ssh
  245. sed -i 's|PasswordAuthentication.*|PasswordAuthentication no|g' $rootdir/etc/ssh/sshd_config
  246. sed -i 's|#PasswordAuthentication no|PasswordAuthentication no|g' $rootdir/etc/ssh/sshd_config
  247. echo $"Using ssh public key:"
  248. echo $SSH_PUBKEY
  249. echo $'Password ssh authentication turned off'
  250. fi
  251. }
  252. create_generic_image() {
  253. if [[ $DEBIAN_INSTALL_ONLY != "no" ]]; then
  254. return
  255. fi
  256. if [[ $GENERIC_IMAGE == "no" ]]; then
  257. return
  258. fi
  259. if [ $CONFIG_FILENAME ]; then
  260. if [[ "$CONFIG_FILENAME" == *"mesh.cfg"* ]]; then
  261. VARIANT="mesh"
  262. fi
  263. fi
  264. # Don't install any configuration. This will be a base system
  265. if [[ $VARIANT != "mesh"* ]]; then
  266. CONFIG_FILENAME=
  267. else
  268. touch $rootdir/root/.initial_mesh_setup
  269. fi
  270. # Stick with the existing login for mesh clients
  271. if [[ $VARIANT == "meshclient" || $VARIANT == "meshusb" ]]; then
  272. return
  273. fi
  274. # The presence of this file indicates that the initial
  275. # setup has not yet been completed
  276. touch $rootdir/home/$MY_USERNAME/.initial_setup
  277. chroot $rootdir /bin/chown $MY_USERNAME:$MY_USERNAME /home/$MY_USERNAME/.initial_setup
  278. touch $rootdir/root/.initial_setup
  279. cat >> $rootdir/home/$MY_USERNAME/.bashrc <<EOF
  280. # initial setup of the system
  281. if [ -f ~/.initial_setup ]; then
  282. clear
  283. echo "
  284. .---. . .
  285. | | |
  286. |--- .--. .-. .-. .-.| .-. .--.--. |.-. .-. .--. .-.
  287. | | (.-' (.-' ( | ( )| | | | )( )| | (.-'
  288. ' ' --' --' -' - -' ' ' -' -' -' ' - --'
  289. Initial setup process
  290. Please enter your password a second time.
  291. "
  292. sudo su
  293. fi
  294. EOF
  295. echo "MY_USERNAME=${MY_USERNAME}" >> $rootdir/root/.bashrc
  296. echo "SSH_PORT=${SSH_PORT}" >> $rootdir/root/.bashrc
  297. echo '# initial setup of the system' >> $rootdir/root/.bashrc
  298. echo 'if [ -f ~/.initial_setup ]; then' >> $rootdir/root/.bashrc
  299. echo ' if [ -f ~/login.txt ]; then' >> $rootdir/root/.bashrc
  300. echo ' NEW_USER_PASSWORD=$(printf `cat ~/login.txt`)' >> $rootdir/root/.bashrc
  301. echo ' else' >> $rootdir/root/.bashrc
  302. echo ' ENTROPY=$(cat /proc/sys/kernel/random/entropy_avail)' >> $rootdir/root/.bashrc
  303. echo ' if [ $ENTROPY -lt 500 ]; then' >> $rootdir/root/.bashrc
  304. ENTROPY_MESSAGE1=$'Initial setup process'
  305. ENTROPY_MESSAGE2=$'Password Generation'
  306. ENTROPY_MESSAGE3=$'WARNING: The entropy available on this system is too low to generate a password.\n\nThe installation process cannot continue.'
  307. echo " dialog --backtitle \"${ENTROPY_MESSAGE1}\" --title \"${ENTROPY_MESSAGE2}\" --msgbox \"${ENTROPY_MESSAGE3}\" 8 50" >> $rootdir/root/.bashrc
  308. echo ' exit' >> $rootdir/root/.bashrc
  309. echo ' fi' >> $rootdir/root/.bashrc
  310. echo -n ' NEW_USER_PASSWORD=$(openssl rand -base64 32 | tr -dc A-Za-z0-9 | head -c ' >> $rootdir/root/.bashrc
  311. echo "${DEFAULT_PASSWORD_LENGTH})" >> $rootdir/root/.bashrc
  312. echo ' fi' >> $rootdir/root/.bashrc
  313. echo ' echo "${NEW_USER_PASSWORD}" > ~/login.txt' >> $rootdir/root/.bashrc
  314. echo ' clear' >> $rootdir/root/.bashrc
  315. echo ' echo ""' >> $rootdir/root/.bashrc
  316. NEW_LOGIN_PASSWORD_MESSAGE1=$'Your new login password is:'
  317. NEW_LOGIN_PASSWORD_MESSAGE2=$'Use it whenever you wish to ssh into this system.'
  318. NEW_LOGIN_PASSWORD_MESSAGE3=$'IMPORTANT: Please take a moment to enter the above password into a\npassword manager or write it down somewhere.'
  319. PRESS_KEY_MESSAGE=$'Press any key to continue...'
  320. echo " echo \"${NEW_LOGIN_PASSWORD_MESSAGE1}\"" >> $rootdir/root/.bashrc
  321. echo ' echo ""' >> $rootdir/root/.bashrc
  322. echo ' echo " ${NEW_USER_PASSWORD}"' >> $rootdir/root/.bashrc
  323. echo ' echo ""' >> $rootdir/root/.bashrc
  324. echo " echo \"${NEW_LOGIN_PASSWORD_MESSAGE2}\"" >> $rootdir/root/.bashrc
  325. echo ' echo ""' >> $rootdir/root/.bashrc
  326. echo " echo \"${NEW_LOGIN_PASSWORD_MESSAGE3}\"" >> $rootdir/root/.bashrc
  327. echo ' echo ""' >> $rootdir/root/.bashrc
  328. echo " read -n1 -r -p \"${PRESS_KEY_MESSAGE}\" key" >> $rootdir/root/.bashrc
  329. # change the password for the admin user
  330. echo -n " echo \"${MY_USERNAME}:" >> $rootdir/root/.bashrc
  331. echo '$(printf `cat ~/login.txt`)"|chpasswd' >> $rootdir/root/.bashrc
  332. # update before continuing
  333. echo " cd /root/${PROJECT_NAME}" >> $rootdir/root/.bashrc
  334. echo " git stash" >> $rootdir/root/.bashrc
  335. echo " git pull" >> $rootdir/root/.bashrc
  336. echo " git checkout stretch" >> $rootdir/root/.bashrc
  337. echo " make install" >> $rootdir/root/.bashrc
  338. if [[ $VARIANT != "mesh"* && $VARIANT != "usb" ]]; then
  339. if [[ "$SOCIALINSTANCE" == "gnusocial" ]]; then
  340. echo " ${PROJECT_NAME} menuconfig-gnusocial" >> $rootdir/root/.bashrc
  341. else
  342. if [[ "$SOCIALINSTANCE" == "postactiv" ]]; then
  343. echo " ${PROJECT_NAME} menuconfig-postactiv" >> $rootdir/root/.bashrc
  344. else
  345. if [[ $ONION_ONLY == "no" ]]; then
  346. if [[ $MINIMAL_INSTALL == "no" ]]; then
  347. echo " ${PROJECT_NAME} menuconfig-full" >> $rootdir/root/.bashrc
  348. else
  349. echo " ${PROJECT_NAME} menuconfig" >> $rootdir/root/.bashrc
  350. fi
  351. else
  352. echo " ${PROJECT_NAME} menuconfig-onion" >> $rootdir/root/.bashrc
  353. fi
  354. fi
  355. fi
  356. else
  357. echo " echo ''" >> $rootdir/root/.bashrc
  358. fi
  359. echo ' if [ "$?" = "0" ]; then' >> $rootdir/root/.bashrc
  360. echo " if [ -f ~/${PROJECT_NAME}-completed.txt ]; then" >> $rootdir/root/.bashrc
  361. echo " # Check that the initial setup really did complete" >> $rootdir/root/.bashrc
  362. echo " if grep -q 'tripwire' ~/${PROJECT_NAME}-completed.txt; then" >> $rootdir/root/.bashrc
  363. # Remove the initial setup files
  364. echo ' rm /root/.initial_setup' >> $rootdir/root/.bashrc
  365. echo ' rm /home/fbone/.initial_setup' >> $rootdir/root/.bashrc
  366. echo " touch /root/.remove_${GENERIC_IMAGE_USERNAME}" >> $rootdir/root/.bashrc
  367. echo ' shred -zu ~/login.txt' >> $rootdir/root/.bashrc
  368. if [[ $VARIANT != "mesh"* && $VARIANT != "usb" ]]; then
  369. echo ' SSH_ONION_HOSTNAME=$(cat /var/lib/tor/hidden_service_ssh/hostname)' >> $rootdir/root/.bashrc
  370. echo ' if [ ${#SSH_ONION_HOSTNAME} -lt 2 ]; then' >> $rootdir/root/.bashrc
  371. echo ' exit 62392' >> $rootdir/root/.bashrc
  372. echo ' fi' >> $rootdir/root/.bashrc
  373. fi
  374. echo " if [ -f /root/${PROJECT_NAME}-wifi.cfg ]; then" >> $rootdir/root/.bashrc
  375. echo " echo '[Unit]' > /etc/systemd/system/wifistart.service" >> $rootdir/root/.bashrc
  376. echo " echo 'Description=WifiStartup (Start wifi networking)' >> /etc/systemd/system/wifistart.service" >> $rootdir/root/.bashrc
  377. echo " echo 'After=syslog.target' >> /etc/systemd/system/wifistart.service" >> $rootdir/root/.bashrc
  378. echo " echo 'After=network.target' >> /etc/systemd/system/wifistart.service" >> $rootdir/root/.bashrc
  379. echo " echo 'After=remote-fs.target' >> /etc/systemd/system/wifistart.service" >> $rootdir/root/.bashrc
  380. echo " echo '' >> /etc/systemd/system/wifistart.service" >> $rootdir/root/.bashrc
  381. echo " echo '[Service]' >> /etc/systemd/system/wifistart.service" >> $rootdir/root/.bashrc
  382. echo " echo 'Type=simple' >> /etc/systemd/system/wifistart.service" >> $rootdir/root/.bashrc
  383. echo " echo 'User=root' >> /etc/systemd/system/wifistart.service" >> $rootdir/root/.bashrc
  384. echo " echo 'Group=root' >> /etc/systemd/system/wifistart.service" >> $rootdir/root/.bashrc
  385. echo " echo 'WorkingDirectory=/root' >> /etc/systemd/system/wifistart.service" >> $rootdir/root/.bashrc
  386. echo " echo 'ExecStart=/usr/local/bin/freedombone-wifi --wait 5 2> /dev/null' >> /etc/systemd/system/wifistart.service" >> $rootdir/root/.bashrc
  387. echo " echo '' >> /etc/systemd/system/wifistart.service" >> $rootdir/root/.bashrc
  388. echo " echo '[Install]' >> /etc/systemd/system/wifistart.service" >> $rootdir/root/.bashrc
  389. echo " echo 'WantedBy=multi-user.target' >> /etc/systemd/system/wifistart.service" >> $rootdir/root/.bashrc
  390. echo " systemctl enable wifistart" >> $rootdir/root/.bashrc
  391. echo " systemctl daemon-reload" >> $rootdir/root/.bashrc
  392. echo ' fi' >> $rootdir/root/.bashrc
  393. echo ' systemctl reboot -i' >> $rootdir/root/.bashrc
  394. echo ' fi' >> $rootdir/root/.bashrc
  395. echo ' fi' >> $rootdir/root/.bashrc
  396. echo ' else' >> $rootdir/root/.bashrc
  397. echo ' key=' >> $rootdir/root/.bashrc
  398. echo ' while [[ $key != "x" ]]; do' >> $rootdir/root/.bashrc
  399. INSTALL_FAIL_MESSAGE=$"Install failed. Press x to continue..."
  400. echo " read -n1 -r -p \"${INSTALL_FAIL_MESSAGE}\" key" >> $rootdir/root/.bashrc
  401. echo ' done' >> $rootdir/root/.bashrc
  402. echo ' fi' >> $rootdir/root/.bashrc
  403. echo ' exit' >> $rootdir/root/.bashrc
  404. echo 'else' >> $rootdir/root/.bashrc
  405. echo ' # Remove default account after install' >> $rootdir/root/.bashrc
  406. echo " if [ -f /root/.remove_${GENERIC_IMAGE_USERNAME} ]; then" >> $rootdir/root/.bashrc
  407. echo " if [ -d /home/${GENERIC_IMAGE_USERNAME} ]; then" >> $rootdir/root/.bashrc
  408. echo " userdel -r ${GENERIC_IMAGE_USERNAME}" >> $rootdir/root/.bashrc
  409. echo " if [ -d /home/${GENERIC_IMAGE_USERNAME} ]; then" >> $rootdir/root/.bashrc
  410. echo " rm -rf /home/${GENERIC_IMAGE_USERNAME}" >> $rootdir/root/.bashrc
  411. echo " rm /root/.remove_${GENERIC_IMAGE_USERNAME}" >> $rootdir/root/.bashrc
  412. echo ' fi' >> $rootdir/root/.bashrc
  413. echo ' fi' >> $rootdir/root/.bashrc
  414. echo ' fi' >> $rootdir/root/.bashrc
  415. echo 'fi' >> $rootdir/root/.bashrc
  416. }
  417. continue_installation() {
  418. # If a configuration file exists then run with it
  419. # otherwise the interactive installer can be used
  420. # This is equivalent to installing freedombox-setup on freedombox
  421. if [ $CONFIG_FILENAME ]; then
  422. if [ ${#CONFIG_FILENAME} -gt 2 ]; then
  423. cp $CONFIG_FILENAME $rootdir/root/$PROJECT_NAME.cfg
  424. cat $rootdir/root/$PROJECT_NAME.cfg
  425. chroot "$rootdir" su -c "$PROJECT_NAME -c /root/$PROJECT_NAME.cfg" - root
  426. fi
  427. fi
  428. }
  429. atheros_wifi() {
  430. if [[ "$MACHINE" == "beaglebonewifi" ]]; then
  431. return
  432. fi
  433. firmware_filename="open-ath9k-htc-firmware_1.3-1_all.deb"
  434. firmware_hash='5fea58ffefdf0ef15b504db7fbe3bc078c03e0d927bba64085e4b6f2546102f5'
  435. firmware_url="http://us.archive.trisquel.info/trisquel/pool/main/o/open-ath9k-htc-firmware/$firmware_filename"
  436. firmware_tempfile="/tmp/$firmware_filename"
  437. wget "$firmware_url" -O "$rootdir$firmware_tempfile"
  438. downloaded_firmware_hash=$(sha256sum "$rootdir$firmware_tempfile" | awk -F ' ' '{print $1}')
  439. if [[ "$downloaded_firmware_hash" == "$firmware_hash" ]]; then
  440. chroot "$rootdir" dpkg -i "$firmware_tempfile"
  441. else
  442. echo 'WARNING: Atheros Wifi firmware hash does not match. The driver has not been installed.'
  443. fi
  444. }
  445. configure_wifi() {
  446. if [[ $VARIANT == "mesh"* ]]; then
  447. return
  448. fi
  449. if [ -f $WIFI_NETWORKS_FILE ]; then
  450. chroot "$rootdir" ${PROJECT_NAME}-wifi --networks $WIFI_NETWORKS_FILE
  451. return
  452. fi
  453. if [[ $WIFI_TYPE != 'none' ]]; then
  454. if [ ${#WIFI_PASSPHRASE} -lt 2 ]; then
  455. return
  456. fi
  457. chroot "$rootdir" ${PROJECT_NAME}-wifi -s $WIFI_SSID -t $WIFI_TYPE -p $WIFI_PASSPHRASE --hotspot $WIFI_HOTSPOT
  458. else
  459. chroot "$rootdir" ${PROJECT_NAME}-wifi -s $WIFI_SSID -t $WIFI_TYPE --hotspot $WIFI_HOTSPOT
  460. fi
  461. }
  462. ##############################################################################
  463. # Mesh networking
  464. ##############################################################################
  465. # for mesh installs
  466. TRACKER_PORT=6969
  467. WIFI_CHANNEL=2
  468. # B.A.T.M.A.N settings
  469. BATMAN_CELLID='02:BA:00:00:03:01'
  470. WIFI_SSID='mesh'
  471. # To avoid confusions these are obtained from the main project file
  472. #TOXID_REPO=
  473. #TOX_PORT=
  474. #TOXCORE_REPO=
  475. #TOXIC_REPO=
  476. #TOXCORE_COMMIT=
  477. #TOXIC_COMMIT=
  478. # These are some default nodes, but you can replace them with trusted nodes
  479. # as you prefer. See https://wiki.tox.im/Nodes
  480. #TOX_NODES=
  481. #TOX_NODES=(
  482. # '192.254.75.102,2607:5600:284::2,33445,951C88B7E75C867418ACDB5D273821372BB5BD652740BCDF623A4FA293E75D2F,Tox RELENG,US'
  483. # '144.76.60.215,2a01:4f8:191:64d6::1,33445,04119E835DF3E78BACF0F84235B300546AF8B936F035185E2A8E9E0A67C8924F,sonOfRa,DE'
  484. #)
  485. # To avoid confusions these are obtained from the main project file
  486. ZERONET_REPO=
  487. ZERONET_COMMIT=
  488. ZERONET_PORT=
  489. ZERONET_BLOG_REPO=
  490. ZERONET_BLOG_COMMIT=
  491. ZERONET_MAIL_REPO=
  492. ZERONET_MAIL_COMMIT=
  493. ZERONET_FORUM_REPO=
  494. ZERONET_FORUM_COMMIT=
  495. ZERONET_ID_REPO=
  496. ZERONET_ID_COMMIT=
  497. # Directory where source code is downloaded and compiled
  498. INSTALL_DIR=$HOME/build
  499. INSTALLING_MESH=
  500. initialise_mesh() {
  501. if [[ $VARIANT != "mesh"* ]]; then
  502. return
  503. fi
  504. if [[ $DEBIAN_INSTALL_ONLY != "no" ]]; then
  505. return
  506. fi
  507. if [[ $INSECURE == $'yes' ]]; then
  508. echo '*********************************************************'
  509. echo $'WARNING: non-free wifi drivers are being installed.'
  510. echo $' This may compromise the security of your system.'
  511. echo '*********************************************************'
  512. # enable non-free repo
  513. if ! grep -q "non-free" $rootdir/etc/apt/sources.list; then
  514. chroot "$rootdir" /bin/sed -i "s| main| main non-free|g" /etc/apt/sources.list
  515. fi
  516. chroot "$rootdir" apt-get update
  517. # install proprietary wifi drivers
  518. # see https://wiki.debian.org/iwlwifi
  519. chroot "$rootdir" apt-get -yq install firmware-iwlwifi firmware-b43-installer firmware-brcm80211
  520. fi
  521. INSTALLING_MESH=1
  522. chroot "$rootdir" apt-get -yq install apt-transport-https
  523. enable_predictable_device_names
  524. configure_firewall
  525. install_avahi
  526. install_batman
  527. install_tomb
  528. #install_tahoelafs
  529. #install_librevault
  530. install_ipfs
  531. install_tox
  532. install_web_server
  533. install_pelican
  534. if [ $ENABLE_ZERONET ]; then
  535. install_zeronet
  536. fi
  537. MESH_SERVICE='mesh-setup.service'
  538. MESH_SETUP_DAEMON=$rootdir/etc/systemd/system/$MESH_SERVICE
  539. MESH_STARTUP_PARAMS="${MY_USERNAME}"
  540. if [[ $AMNESIC != 'no' ]]; then
  541. MESH_STARTUP_PARAMS="${MY_USERNAME} amnesic"
  542. fi
  543. echo '[Unit]' > $MESH_SETUP_DAEMON
  544. echo 'Description=Initial mesh router configuration' >> $MESH_SETUP_DAEMON
  545. echo 'After=syslog.target' >> $MESH_SETUP_DAEMON
  546. echo 'After=network.target' >> $MESH_SETUP_DAEMON
  547. echo '' >> $MESH_SETUP_DAEMON
  548. echo '[Service]' >> $MESH_SETUP_DAEMON
  549. echo 'Type=simple' >> $MESH_SETUP_DAEMON
  550. echo 'User=root' >> $MESH_SETUP_DAEMON
  551. echo 'Group=root' >> $MESH_SETUP_DAEMON
  552. echo 'WorkingDirectory=/root' >> $MESH_SETUP_DAEMON
  553. echo "ExecStart=/usr/local/bin/${PROJECT_NAME}-image-mesh ${MESH_STARTUP_PARAMS} > /var/log/mesh-setup.log" >> $MESH_SETUP_DAEMON
  554. echo '' >> $MESH_SETUP_DAEMON
  555. echo 'TimeoutSec=99999' >> $MESH_SETUP_DAEMON
  556. echo '' >> $MESH_SETUP_DAEMON
  557. echo '[Install]' >> $MESH_SETUP_DAEMON
  558. echo 'WantedBy=multi-user.target' >> $MESH_SETUP_DAEMON
  559. chmod +x $MESH_SETUP_DAEMON
  560. chroot "$rootdir" systemctl enable $MESH_SERVICE
  561. }
  562. # User interface for USB drive installs ######################################
  563. function mesh_client_startup_applications {
  564. if [ ! -d $rootdir/home/$MY_USERNAME/Desktop ]; then
  565. mkdir -p $rootdir/home/$MY_USERNAME/Desktop
  566. fi
  567. if [ ! -d $rootdir/home/$MY_USERNAME/.config/autostart ]; then
  568. mkdir -p $rootdir/home/$MY_USERNAME/.config/autostart
  569. chroot "$rootdir" /bin/chown -R $MY_USERNAME:$MY_USERNAME /home/$MY_USERNAME/.config
  570. fi
  571. START_DESKTOP=$rootdir/home/$MY_USERNAME/mesh-desktop.sh
  572. FIRST_BOOT=/home/$MY_USERNAME/.first_boot
  573. TAHOE_COMMAND="cd /var/lib/tahoelafs && venv/bin/tahoe"
  574. echo '#!/bin/bash' > $START_DESKTOP
  575. echo "setxkbmap ${KEYBOARD_MAP}" > $START_DESKTOP
  576. echo 'dconf write /org/mate/caja/desktop/volumes-visible false' >> $START_DESKTOP
  577. echo 'dconf write /org/mate/caja/desktop/computer-icon-visible false' >> $START_DESKTOP
  578. echo 'dconf write /org/mate/caja/desktop/home-icon-visible false' >> $START_DESKTOP
  579. echo 'dconf write /org/mate/caja/desktop/network-icon-visible false' >> $START_DESKTOP
  580. echo 'dconf write /org/mate/caja/desktop/trash-icon-visible false' >> $START_DESKTOP
  581. echo 'dconf write /org/mate/caja/desktop/volumes-visible false' >> $START_DESKTOP
  582. echo 'dconf write /org/mate/desktop/media-handling/automount-open false' >> $START_DESKTOP
  583. echo 'dconf write /org/mate/screensaver/lock-enabled false' >> $START_DESKTOP
  584. echo 'dconf write /org/mate/power-manager/lock-keyring-suspend false' >> $START_DESKTOP
  585. echo 'dconf write /org/mate/power-manager/lock-suspend false' >> $START_DESKTOP
  586. echo 'dconf write /org/mate/power-manager/lock-use-screensaver false' >> $START_DESKTOP
  587. echo 'dconf write /org/mate/power-manager/lock-blank-screen false' >> $START_DESKTOP
  588. echo 'dconf write /org/mate/power-manager/lock-hibernate false' >> $START_DESKTOP
  589. echo 'dconf write /org/mate/power-manager/lock-keyring-hibernate false' >> $START_DESKTOP
  590. echo 'dconf write /org/mate/desktop/peripherals/touchpad/scroll-method 2' >> $START_DESKTOP
  591. echo "touch /home/$MY_USERNAME/.dbus/Xdbus" >> $START_DESKTOP
  592. echo "chmod 600 /home/$MY_USERNAME/.dbus/Xdbus" >> $START_DESKTOP
  593. echo "env | grep DBUS_SESSION_BUS_ADDRESS > /home/$MY_USERNAME/.dbus/Xdbus" >> $START_DESKTOP
  594. echo "echo 'export DBUS_SESSION_BUS_ADDRESS' >> /home/$MY_USERNAME/.dbus/Xdbus" >> $START_DESKTOP
  595. echo '' >> $START_DESKTOP
  596. echo "amixer set 'Master' unmute" >> $START_DESKTOP
  597. echo "amixer set 'Master' 50%" >> $START_DESKTOP
  598. echo '' >> $START_DESKTOP
  599. echo '' >> $START_DESKTOP
  600. echo "if [ ! -f $FIRST_BOOT ]; then" >> $START_DESKTOP
  601. echo " $TAHOE_COMMAND start" >> $START_DESKTOP
  602. echo ' exit 0' >> $START_DESKTOP
  603. echo 'fi' >> $START_DESKTOP
  604. echo '' >> $START_DESKTOP
  605. echo 'INITIAL_TOX_USERNAME=""' >> $START_DESKTOP
  606. echo 'while [ ${#INITIAL_TOX_USERNAME} -eq 0 ]; do' >> $START_DESKTOP
  607. echo ' data=$(tempfile 2>/dev/null)' >> $START_DESKTOP
  608. echo ' trap "rm -f $data" 0 1 2 5 15' >> $START_DESKTOP
  609. echo -n " dialog --title \"${MESH_TITLE}\" " >> $START_DESKTOP
  610. echo -n "--backtitle \"${MESH_TITLE}\" " >> $START_DESKTOP
  611. echo -n "--inputbox \"${MESH_SET_USERNAME}\" 12 60 Anon " >> $START_DESKTOP
  612. echo '2>$data' >> $START_DESKTOP
  613. echo ' sel=$?' >> $START_DESKTOP
  614. echo ' case $sel in' >> $START_DESKTOP
  615. echo ' 0)' >> $START_DESKTOP
  616. echo ' INITIAL_TOX_USERNAME=$(<$data)' >> $START_DESKTOP
  617. echo ' ;;' >> $START_DESKTOP
  618. echo ' esac' >> $START_DESKTOP
  619. echo 'done' >> $START_DESKTOP
  620. echo '' >> $START_DESKTOP
  621. echo 'toxid --setuser "$INITIAL_TOX_USERNAME"' >> $START_DESKTOP
  622. echo '' >> $START_DESKTOP
  623. echo "if [ -f /home/$MY_USERNAME/.tahoe/tahoe.cfg ]; then" >> $START_DESKTOP
  624. echo " sed -i 's|nickname =.*|nickname = \$INITIAL_TOX_USERNAME|g' /home/$MY_USERNAME/.tahoe/tahoe.cfg" >> $START_DESKTOP
  625. echo " $TAHOE_COMMAND restart" >> $START_DESKTOP
  626. echo 'fi' >> $START_DESKTOP
  627. echo '' >> $START_DESKTOP
  628. echo "rm -f $FIRST_BOOT" >> $START_DESKTOP
  629. echo '' >> $START_DESKTOP
  630. echo 'exit 0' >> $START_DESKTOP
  631. chmod +x $START_DESKTOP
  632. START_DESKTOP2=$rootdir/home/$MY_USERNAME/.config/autostart/mesh-start.desktop
  633. echo '[Desktop Entry]' > $START_DESKTOP2
  634. echo 'Type=Application' >> $START_DESKTOP2
  635. echo 'Name=Mesh start desktop script' >> $START_DESKTOP2
  636. echo "Exec=bash -c '~/mesh-desktop.sh'" >> $START_DESKTOP2
  637. echo 'X-GNOME-Autostart-enabled=true' >> $START_DESKTOP2
  638. chmod +x $START_DESKTOP2
  639. START_DESKTOP3=$rootdir/home/$MY_USERNAME/.config/autostart/set_username.desktop
  640. echo '[Desktop Entry]' > $START_DESKTOP3
  641. echo 'Version=1.0' >> $START_DESKTOP3
  642. echo 'Name=Set Username' >> $START_DESKTOP3
  643. echo 'Type=Application' >> $START_DESKTOP3
  644. echo 'Comment=Set username' >> $START_DESKTOP3
  645. echo "Exec=mate-terminal -e \"bash -c /home/${MY_USERNAME}/mesh-desktop.sh\"" >> $START_DESKTOP3
  646. echo 'Icon=user-away' >> $START_DESKTOP3
  647. echo 'Terminal=false' >> $START_DESKTOP3
  648. echo 'Categories=Application;' >> $START_DESKTOP3
  649. chmod +x $START_DESKTOP3
  650. }
  651. function mesh_desktop_icons {
  652. if [ ! -d $rootdir/home/$MY_USERNAME/Desktop ]; then
  653. mkdir -p $rootdir/home/$MY_USERNAME/Desktop
  654. fi
  655. # Terminal
  656. #echo '[Desktop Entry]' > $rootdir/home/$MY_USERNAME/Desktop/terminal.desktop
  657. #echo 'Name=MATE Terminal' >> $rootdir/home/$MY_USERNAME/Desktop/terminal.desktop
  658. #echo 'Type=Application' >> $rootdir/home/$MY_USERNAME/Desktop/terminal.desktop
  659. #echo 'Comment=Use the command line' >> $rootdir/home/$MY_USERNAME/Desktop/terminal.desktop
  660. #echo 'TryExec=mate-terminal' >> $rootdir/home/$MY_USERNAME/Desktop/terminal.desktop
  661. #echo 'Exec=mate-terminal' >> $rootdir/home/$MY_USERNAME/Desktop/terminal.desktop
  662. #echo 'Icon=terminal' >> $rootdir/home/$MY_USERNAME/Desktop/terminal.desktop
  663. #echo 'StartupNotify=true' >> $rootdir/home/$MY_USERNAME/Desktop/terminal.desktop
  664. chroot "$rootdir" /bin/chown -R $MY_USERNAME:$MY_USERNAME /home/$MY_USERNAME/Desktop
  665. }
  666. function configure_user_interface {
  667. if [[ $VARIANT != "meshclient" && $VARIANT != "meshusb" && $VARIANT != "usb" ]]; then
  668. return
  669. fi
  670. # desktop
  671. chroot "$rootdir" apt-get -yq install mate-desktop-environment
  672. # tool to change desktop settings from command line
  673. chroot "$rootdir" apt-get -yq install dconf-cli dconf-gsettings-backend dbus dbus-x11
  674. # for tomb
  675. chroot "$rootdir" apt-get -yq install pinentry-gtk2
  676. # for tox video
  677. chroot "$rootdir" apt-get -yq install ffmpeg cheese v4l-utils
  678. # to provide notifications
  679. chroot "$rootdir" apt-get -yq install libnotify-bin
  680. # for video/audio
  681. chroot "$rootdir" apt-get -yq install libtheora-bin libvorbis-dev v4l-utils
  682. # a sane editor
  683. chroot "$rootdir" apt-get -yq install emacs
  684. # for wifi monitoring
  685. chroot "$rootdir" apt-get -yq install horst
  686. # for sound level control
  687. chroot "$rootdir" apt-get -yq install alsa-utils
  688. # to play various media types
  689. chroot "$rootdir" apt-get -yq install vlc
  690. # android adb to allow phones to be connected and for example transfer photos/documents
  691. chroot "$rootdir" apt-get -yq install android-tools-adb
  692. # Produce a text file on the desktop listing users on the mesh
  693. cat <<EOF > $rootdir/usr/bin/list-tox-users
  694. #!/bin/bash
  695. users_list=\$(lstox | awk -F ' ' '{\$1=""; print \$0}' | sed -e 's/^[[:space:]]*//' | sort -d | uniq)
  696. if [ ! \$users_list ]; then
  697. no_of_users=0
  698. else
  699. no_of_users=\$(echo "\$users_list" | wc -l)
  700. fi
  701. if [ \$no_of_users -gt 0 ]; then
  702. echo "\$users_list" > /tmp/Users.txt
  703. chown $MY_USERNAME:$MY_USERNAME /tmp/Users.txt
  704. echo 'showing_users=\$(ps aux | grep $MESH_TEXT_EDITOR | grep "Users.txt")' > /home/$MY_USERNAME/showusers
  705. echo 'if [ \${#showing_users} -eq 0 ]; then' >> /home/$MY_USERNAME/showusers
  706. echo ' $MESH_TEXT_EDITOR /tmp/Users.txt' >> /home/$MY_USERNAME/showusers
  707. echo 'fi' >> /home/$MY_USERNAME/showusers
  708. echo 'exit 0' >> /home/$MY_USERNAME/showusers
  709. chmod +x /home/$MY_USERNAME/showusers
  710. chown $MY_USERNAME:$MY_USERNAME /home/$MY_USERNAME/showusers
  711. echo '[Desktop Entry]' > /home/$MY_USERNAME/Desktop/Users.desktop
  712. if [ \$no_of_users -lt 2 ]; then
  713. echo "Name=\$no_of_users Other User" >> /home/$MY_USERNAME/Desktop/Users.desktop
  714. else
  715. echo "Name=\$no_of_users Other Users" >> /home/$MY_USERNAME/Desktop/Users.desktop
  716. fi
  717. echo 'Type=Application' >> /home/$MY_USERNAME/Desktop/Users.desktop
  718. echo 'Comment=List of users' >> /home/$MY_USERNAME/Desktop/Users.desktop
  719. echo 'Exec=bash /home/$MY_USERNAME/showusers' >> /home/$MY_USERNAME/Desktop/Users.desktop
  720. echo 'Icon=/usr/share/$PROJECT_NAME/avatars/otheruser.png' >> /home/$MY_USERNAME/Desktop/Users.desktop
  721. echo 'StartupNotify=false' >> /home/$MY_USERNAME/Desktop/Users.desktop
  722. chmod +x /home/$MY_USERNAME/Desktop/Users.desktop
  723. chown $MY_USERNAME:$MY_USERNAME /home/$MY_USERNAME/Desktop/Users.desktop
  724. if [ -f /tmp/.ipfs-users ]; then
  725. echo '[Desktop Entry]' > /home/$MY_USERNAME/Desktop/sites.desktop
  726. echo 'Type=Application' >> /home/$MY_USERNAME/Desktop/sites.desktop
  727. echo "Name=Visit a site" >> /home/$MY_USERNAME/Desktop/sites.desktop
  728. echo 'Comment=Visit a site' >> /home/$MY_USERNAME/Desktop/sites.desktop
  729. echo 'Exec=mate-terminal -e /usr/local/bin/${PROJECT_NAME}-mesh-visit-site' >> /home/$MY_USERNAME/Desktop/sites.desktop
  730. echo 'Icon=/usr/share/${PROJECT_NAME}/avatars/ipfs.jpg' >> /home/$MY_USERNAME/Desktop/sites.desktop
  731. echo 'StartupNotify=false' >> /home/$MY_USERNAME/Desktop/sites.desktop
  732. chmod +x /home/$MY_USERNAME/Desktop/sites.desktop
  733. chown $MY_USERNAME:$MY_USERNAME /home/$MY_USERNAME/Desktop/sites.desktop
  734. echo '[Desktop Entry]' > /home/$MY_USERNAME/Desktop/blog.desktop
  735. echo 'Type=Application' >> /home/$MY_USERNAME/Desktop/blog.desktop
  736. echo "Name=Blog" >> /home/$MY_USERNAME/Desktop/blog.desktop
  737. echo 'Comment=View or create blog entries' >> /home/$MY_USERNAME/Desktop/blog.desktop
  738. echo 'Exec=mate-terminal -e /usr/local/bin/${PROJECT_NAME}-mesh-blog' >> /home/$MY_USERNAME/Desktop/blog.desktop
  739. echo 'Icon=/usr/share/${PROJECT_NAME}/avatars/blog.png' >> /home/$MY_USERNAME/Desktop/blog.desktop
  740. echo 'StartupNotify=false' >> /home/$MY_USERNAME/Desktop/blog.desktop
  741. chmod +x /home/$MY_USERNAME/Desktop/blog.desktop
  742. chown $MY_USERNAME:$MY_USERNAME /home/$MY_USERNAME/Desktop/blog.desktop
  743. fi
  744. if [ ! -f /home/$MY_USERNAME/runtox ]; then
  745. echo 'qtox_running=\$(ps aux | grep qtox | grep data)' > /home/$MY_USERNAME/runtox
  746. echo 'if [ \${#qtox_running} -eq 0 ]; then' >> /home/$MY_USERNAME/runtox
  747. echo ' bash -c "qtox -p data"' >> /home/$MY_USERNAME/runtox
  748. echo 'fi' >> /home/$MY_USERNAME/runtox
  749. echo 'exit 0' >> /home/$MY_USERNAME/runtox
  750. chmod +x /home/$MY_USERNAME/runtox
  751. chown $MY_USERNAME:$MY_USERNAME /home/$MY_USERNAME/runtox
  752. fi
  753. if [ ! -f /home/$MY_USERNAME/Desktop/tox.desktop ]; then
  754. echo '[Desktop Entry]' > /home/$MY_USERNAME/Desktop/tox.desktop
  755. echo 'Name=Chat' >> /home/$MY_USERNAME/Desktop/tox.desktop
  756. echo 'Type=Application' >> /home/$MY_USERNAME/Desktop/tox.desktop
  757. echo 'Comment=Chat, Voice and Video' >> /home/$MY_USERNAME/Desktop/tox.desktop
  758. echo 'Exec=bash /home/$MY_USERNAME/runtox' >> /home/$MY_USERNAME/Desktop/tox.desktop
  759. echo "Icon=/usr/share/$PROJECT_NAME/avatars/chat.png" >> /home/$MY_USERNAME/Desktop/tox.desktop
  760. echo 'StartupNotify=true' >> /home/$MY_USERNAME/Desktop/tox.desktop
  761. chmod +x /home/$MY_USERNAME/Desktop/tox.desktop
  762. chown $MY_USERNAME:$MY_USERNAME /home/$MY_USERNAME/Desktop/tox.desktop
  763. fi
  764. else
  765. if [ -f /tmp/Users.txt ]; then
  766. rm /tmp/Users.txt
  767. rm /home/$MY_USERNAME/Desktop/Users.desktop
  768. if [ -f /home/$MY_USERNAME/Desktop/Users.desktop ]; then
  769. rm /home/$MY_USERNAME/Desktop/Users.desktop
  770. fi
  771. if [ -f /home/$MY_USERNAME/Desktop/sites.desktop ]; then
  772. rm /home/$MY_USERNAME/Desktop/sites.desktop
  773. fi
  774. if [ -f /home/$MY_USERNAME/Desktop/blog.desktop ]; then
  775. rm /home/$MY_USERNAME/Desktop/blog.desktop
  776. fi
  777. if [ -f /home/$MY_USERNAME/Desktop/tox.desktop ]; then
  778. rm /home/$MY_USERNAME/Desktop/tox.desktop
  779. fi
  780. pkill qtox
  781. fi
  782. fi
  783. EOF
  784. chroot "$rootdir" /bin/chown $MY_USERNAME:$MY_USERNAME /usr/bin/list-tox-users
  785. chroot "$rootdir" /bin/chmod +x /usr/bin/list-tox-users
  786. echo "* * * * * $MY_USERNAME bash -c /usr/bin/list-tox-users > /dev/null" >> $rootdir/etc/crontab
  787. if [[ $VARIANT != "usb" ]]; then
  788. # log in automatically
  789. chroot "$rootdir" apt-get -y install nodm xinit
  790. echo 'NODM_ENABLED=true' > /etc/default/nodm
  791. echo "NODM_USER=$MY_USERNAME" >> /etc/default/nodm
  792. chroot "$rootdir" mkdir /etc/systemd/system/getty@tty1.service.d
  793. echo '[Service]' > $rootdir/etc/systemd/system/getty@tty1.service.d/override.conf
  794. echo 'ExecStart=' >> $rootdir/etc/systemd/system/getty@tty1.service.d/override.conf
  795. echo 'ExecStart=-/sbin/agetty --autologin fbone --noclear %I $TERM' >> $rootdir/etc/systemd/system/getty@tty1.service.d/override.conf
  796. echo '[[ -z $DISPLAY && $XDG_VTNR -eq 1 ]] && exec startx' >> $rootdir/home/$MY_USERNAME/.profile
  797. chroot "$rootdir" systemctl set-default multi-user.target
  798. mesh_client_startup_applications
  799. mesh_desktop_icons
  800. # Different desktop background for amnesic
  801. if [[ $AMNESIC != 'no' ]]; then
  802. MESH_DESKTOP_BACKGROUND_IMAGE=/usr/local/share/${PROJECT_NAME}_mesh_amnesic_background.png
  803. fi
  804. # change the desktop background
  805. if [ $MESH_DESKTOP_BACKGROUND_IMAGE ]; then
  806. if [ -f $MESH_DESKTOP_BACKGROUND_IMAGE ]; then
  807. if [ -d $rootdir/usr/share/images/desktop-base ]; then
  808. cp $MESH_DESKTOP_BACKGROUND_IMAGE $rootdir/usr/share/images/desktop-base/${PROJECT_NAME}_mesh_background.png
  809. chroot "$rootdir" /bin/rm /usr/share/images/desktop-base/desktop-background
  810. chroot "$rootdir" ln -s /usr/share/images/desktop-base/${PROJECT_NAME}_mesh_background.png /usr/share/images/desktop-base/desktop-background
  811. fi
  812. fi
  813. fi
  814. else
  815. chroot "$rootdir" apt-get -yq install lightdm
  816. fi
  817. # browser
  818. chroot "$rootdir" apt-get -yq install $BROWSER
  819. # help
  820. mkdir -p $rootdir/home/${MY_USERNAME}/help/images
  821. cd $rootdir/root/${PROJECT_NAME}/website
  822. ./deploy.sh EN $rootdir/home/${MY_USERNAME}/help
  823. chroot "$rootdir" /bin/chown -R ${MY_USERNAME}:${MY_USERNAME} /home/${MY_USERNAME}/help
  824. # Tox user interface
  825. enable_tox_repo
  826. mesh_tox_qtox
  827. # copy the default qtox ini file
  828. if [ ! -d ${rootdir}/home/${MY_USERNAME}/.config/tox ]; then
  829. mkdir ${rootdir}/home/${MY_USERNAME}/.config/tox
  830. cp /usr/local/bin/${PROJECT_NAME}-config-qtox ${rootdir}/home/${MY_USERNAME}/.config/tox/qtox.ini
  831. chroot "$rootdir" /bin/chown -R ${MY_USERNAME}:${MY_USERNAME} /home/${MY_USERNAME}/.config
  832. fi
  833. if [[ $VARIANT == "usb" ]]; then
  834. # tor
  835. chroot "$rootdir" apt-get -yq install tor
  836. # xmpp client
  837. chroot "$rootdir" echo "deb ftp://ftp.gajim.org/debian unstable main" > /etc/apt/sources.list.d/gajim.list
  838. chroot "$rootdir" apt-get update
  839. chroot "$rootdir" apt-get -yq install gajim-dev-keyring
  840. chroot "$rootdir" apt-get -yq install git python-dev python-pip gajim-nightly
  841. chroot "$rootdir" mkdir /home/$GENERIC_IMAGE_USERNAME/.local/share/gajim/plugins -p
  842. chroot "$rootdir" git clone https://github.com/omemo/gajim-omemo /home/$GENERIC_IMAGE_USERNAME/.local/share/gajim/plugins/gajim-omemo
  843. chroot "$rootdir" pip install protobuf==2.6.1, python-axolotl==0.1.35
  844. chroot "$rootdir" /bin/chown -R $GENERIC_IMAGE_USERNAME:$GENERIC_IMAGE_USERNAME /home/$GENERIC_IMAGE_USERNAME/.local
  845. # IRC client
  846. chroot "$rootdir" apt-get -yq install hexchat profanity
  847. fi
  848. }
  849. ##############################################################################
  850. # setup_utils
  851. ##############################################################################
  852. function image_install_inadyn {
  853. if [ $INSTALLING_MESH ]; then
  854. return
  855. fi
  856. if [ ! -d $rootdir/root/build ]; then
  857. mkdir -p $rootdir/root/build
  858. fi
  859. chroot "$rootdir" apt-get -yq install build-essential curl libgnutls28-dev automake1.11 libconfuse-dev
  860. if [ -d /repos/inadyn ]; then
  861. mkdir $rootdir/root/build/inadyn
  862. cp -r -p /repos/inadyn/. $rootdir/root/build/inadyn
  863. cd $rootdir/root/build/inadyn
  864. git pull
  865. else
  866. git clone $INADYN_REPO $rootdir/root/build/inadyn
  867. fi
  868. if [ ! -d $rootdir/root/build/inadyn ]; then
  869. echo 'Failed to clone inadyn'
  870. exit 728252
  871. fi
  872. cd $rootdir/root/build/inadyn
  873. git checkout $INADYN_COMMIT -b $INADYN_COMMIT
  874. cd $rootdir/root/build/inadyn
  875. echo '#!/bin/bash' > $rootdir/root/build/build_inadyn.sh
  876. echo 'cd ~/build/inadyn' >> $rootdir/root/build/build_inadyn.sh
  877. echo '#./autogen.sh' >> $rootdir/root/build/build_inadyn.sh
  878. echo './configure' >> $rootdir/root/build/build_inadyn.sh
  879. echo 'USE_OPENSSL=1 make' >> $rootdir/root/build/build_inadyn.sh
  880. echo 'make install' >> $rootdir/root/build/build_inadyn.sh
  881. chmod +x $rootdir/root/build/build_inadyn.sh
  882. chroot "$rootdir" /root/build/build_inadyn.sh
  883. if [ ! -f $rootdir/usr/local/sbin/inadyn ]; then
  884. echo 'Failed to build inadyn'
  885. exit 6209356
  886. fi
  887. # create a configuration file
  888. echo 'background' > $rootdir/etc/inadyn.conf
  889. echo 'verbose 1' >> $rootdir/etc/inadyn.conf
  890. echo 'period 300' >> $rootdir/etc/inadyn.conf
  891. echo 'startup-delay 60' >> $rootdir/etc/inadyn.conf
  892. echo 'cache-dir /run/inadyn' >> $rootdir/etc/inadyn.conf
  893. echo 'logfile /dev/null' >> $rootdir/etc/inadyn.conf
  894. chmod 600 $rootdir/etc/inadyn.conf
  895. echo '[Unit]' > $rootdir/etc/systemd/system/inadyn.service
  896. echo 'Description=inadyn (DynDNS updater)' >> $rootdir/etc/systemd/system/inadyn.service
  897. echo 'After=network.target' >> $rootdir/etc/systemd/system/inadyn.service
  898. echo '' >> $rootdir/etc/systemd/system/inadyn.service
  899. echo '[Service]' >> $rootdir/etc/systemd/system/inadyn.service
  900. echo 'ExecStart=/usr/local/sbin/inadyn --config /etc/inadyn.conf' >> $rootdir/etc/systemd/system/inadyn.service
  901. echo 'Restart=always' >> $rootdir/etc/systemd/system/inadyn.service
  902. echo 'Type=forking' >> $rootdir/etc/systemd/system/inadyn.service
  903. echo '' >> $rootdir/etc/systemd/system/inadyn.service
  904. echo '[Install]' >> $rootdir/etc/systemd/system/inadyn.service
  905. echo 'WantedBy=multi-user.target' >> $rootdir/etc/systemd/system/inadyn.service
  906. chroot "$rootdir" systemctl enable inadyn
  907. echo "inadyn commit:$INADYN_COMMIT" >> $rootdir/root/freedombone-completed.txt
  908. }
  909. function image_setup_utils {
  910. if [ $INSTALLING_MESH ]; then
  911. return
  912. fi
  913. chroot "$rootdir" apt-get -yq install apt-transport-https
  914. chroot "$rootdir" apt-get -yq remove --purge apache2-bin*
  915. chroot "$rootdir" apt-get -yq dist-upgrade
  916. chroot "$rootdir" apt-get -yq install ca-certificates
  917. chroot "$rootdir" apt-get -yq install apt-utils
  918. chroot "$rootdir" apt-get -yq install nfs-kernel-server
  919. if [[ $ARCHITECTURE == 'amd64' ]]; then
  920. chroot "$rootdir" apt-get -yq install linux-image-amd64
  921. fi
  922. if [[ $ARCHITECTURE == 'qemu'* || $ARCHITECTURE == 'amd64' || $ARCHITECTURE == 'x86_64' || $ARCHITECTURE == 'i686' || $ARCHITECTURE == 'i386' ]]; then
  923. chroot "$rootdir" apt-get -yq install grub2
  924. fi
  925. chroot "$rootdir" apt-get -yq install locales locales-all debconf
  926. SYSCTL_FILE=$rootdir/etc/sysctl.conf
  927. if [ ! -f $SYSCTL_FILE ]; then
  928. touch $SYSCTL_FILE
  929. fi
  930. cp $SYSCTL_FILE $rootdir/root/sysctl.conf
  931. chown $CURR_USER:$CURR_GROUP $rootdir/root/sysctl.conf
  932. if ! grep -q "tcp_challenge_ack_limit" $rootdir/root/sysctl.conf; then
  933. echo 'net.ipv4.tcp_challenge_ack_limit = 999999999' >> $rootdir/root/sysctl.conf
  934. else
  935. sed -i 's|net.ipv4.tcp_challenge_ack_limit.*|net.ipv4.tcp_challenge_ack_limit = 999999999|g' $rootdir/root/sysctl.conf
  936. fi
  937. cp $rootdir/root/sysctl.conf $SYSCTL_FILE
  938. rm $rootdir/root/sysctl.conf
  939. # all the packages
  940. chroot "$rootdir" apt-get -yq install cryptsetup libgfshare-bin obnam sshpass wget avahi-daemon
  941. chroot "$rootdir" apt-get -yq install avahi-utils avahi-discover connect-proxy openssh-server
  942. chroot "$rootdir" apt-get -yq install sudo git dialog build-essential avahi-daemon avahi-utils
  943. chroot "$rootdir" apt-get -yq install avahi-discover avahi-autoipd iptables dnsutils net-tools
  944. chroot "$rootdir" apt-get -yq install network-manager iputils-ping libnss-mdns libnss-myhostname
  945. chroot "$rootdir" apt-get -yq install libnss-gw-name nano man ntp locales locales-all debconf
  946. chroot "$rootdir" apt-get -yq install wireless-tools wpasupplicant usbutils cryptsetup zsh
  947. chroot "$rootdir" apt-get -yq install pinentry-curses eatmydata iotop bc hostapd haveged
  948. chroot "$rootdir" apt-get -yq install cpulimit screen elinks libpam-cracklib
  949. chroot "$rootdir" apt-get -yq install fail2ban vim-common python3 unattended-upgrades
  950. # Tor and ssh over tor
  951. chroot "$rootdir" apt-get -yq install tor connect-proxy
  952. chroot "$rootdir" connect-proxy
  953. sed -i 's|#Log notice file.*|Log notice file /dev/null|g' $rootdir/etc/tor/torrc
  954. sed -i 's|Log notice file.*|Log notice file /dev/null|g' $rootdir/etc/tor/torrc
  955. sed -i "s|#AccountingMax.*|AccountingMax $TOR_MAX_TRAFFIC_PER_DAY_GB GBytes|g" $rootdir/etc/tor/torrc
  956. sed -i "s|AccountingMax.*|AccountingMax $TOR_MAX_TRAFFIC_PER_DAY_GB GBytes|g" $rootdir/etc/tor/torrc
  957. if ! grep -q 'Host *.onion' $rootdir/root/.ssh/config; then
  958. if [ ! -d $rootdir/root/.ssh ]; then
  959. mkdir $rootdir/root/.ssh
  960. fi
  961. echo 'Host *.onion' >> $rootdir/root/.ssh/config
  962. echo 'ProxyCommand connect -R remote -5 -S 127.0.0.1:9050 %h %p' >> $rootdir/root/.ssh/config
  963. fi
  964. if ! grep -q 'Host *.onion' $rootdir/etc/skel/.ssh/config; then
  965. if [ ! -d $rootdir/etc/skel/.ssh ]; then
  966. mkdir $rootdir/etc/skel/.ssh
  967. fi
  968. echo 'Host *.onion' >> $rootdir/etc/skel/.ssh/config
  969. echo 'ProxyCommand connect -R remote -5 -S 127.0.0.1:9050 %h %p' >> $rootdir/etc/skel/.ssh/config
  970. fi
  971. # Install golang
  972. chroot "$rootdir" adduser --disabled-login --gecos 'go' go
  973. GOARCH=
  974. if [[ $ARCHITECTURE == *"386" || $ARCHITECTURE == *"686" ]]; then
  975. GOARCH=386
  976. fi
  977. if [[ $ARCHITECTURE == *"amd64" || $ARCHITECTURE == "x86_64" ]]; then
  978. GOARCH=amd64
  979. fi
  980. if [[ $ARCHITECTURE == *"arm"* ]]; then
  981. GOARCH=armv6l
  982. fi
  983. GO_SOURCE=https://storage.googleapis.com/golang/go${GO_VERSION}.linux-${GOARCH}.tar.gz
  984. if [ ! -d ${rootdir}/root/build ]; then
  985. mkdir -p $rootdir/root/build
  986. fi
  987. cd $rootdir/root/build
  988. wget ${GO_SOURCE}
  989. if [ ! -f ${rootdir}/root/build/go${GO_VERSION}.linux-${GOARCH}.tar.gz ]; then
  990. exit 26524
  991. fi
  992. chroot "$rootdir" tar -C /home/go -xzf ${INSTALL_DIR}/go${GO_VERSION}.linux-${GOARCH}.tar.gz
  993. if [ ! -d ${rootdir}/home/go/go/bin ]; then
  994. echo 'Go binary not installed'
  995. exit 763562
  996. fi
  997. mv ${rootdir}/home/go/go ${rootdir}/home/go/go${GO_VERSION}
  998. echo "export GOROOT=/home/go" >> ${rootdir}/root/.bashrc
  999. echo "export GOROOT=/home/go" >> ${rootdir}/etc/skel/.bashrc
  1000. echo "export GOROOT=/home/go" >> ${rootdir}/home/go/.bashrc
  1001. echo "export GOPATH=\$GOROOT/go${GO_VERSION}/bin" >> ${rootdir}/root/.bashrc
  1002. echo "export GOPATH=\$GOROOT/go${GO_VERSION}/bin" >> ${rootdir}/etc/skel/.bashrc
  1003. echo "export GOPATH=\$GOROOT/go${GO_VERSION}/bin" >> ${rootdir}/home/go/.bashrc
  1004. echo 'export PATH=$PATH:$GOPATH' >> ${rootdir}/root/.bashrc
  1005. echo 'export PATH=$PATH:$GOPATH' >> ${rootdir}/etc/skel/.bashrc
  1006. echo 'export PATH=$PATH:$GOPATH' >> ${rootdir}/home/go/.bashrc
  1007. chroot "$rootdir" chown -R go:go /home/go
  1008. cp ${rootdir}/home/go/go${GO_VERSION}/bin/* ${rootdir}/usr/bin
  1009. # Tomb
  1010. chroot "$rootdir" apt-get -yq install zsh pinentry-curses
  1011. git clone $TOMB_REPO $rootdir/root/build/tomb
  1012. cd $rootdir/root/build/tomb
  1013. git checkout $TOMB_COMMIT -b $TOMB_COMMIT
  1014. chroot "$rootdir" cd /root/build/tomb && make install
  1015. echo "tomb commit:$TOMB_COMMIT" >> $rootdir/root/freedombone-completed.txt
  1016. if ! grep '* hard maxsyslogins' $rootdir/etc/security/limits.conf; then
  1017. echo '* hard maxsyslogins 10' >> $rootdir/etc/security/limits.conf
  1018. else
  1019. sed -i 's|hard maxsyslogins.*|hard maxsyslogins 10|g' $rootdir/etc/security/limits.conf
  1020. fi
  1021. # Max logins for each user
  1022. if ! grep '* hard maxlogins' $rootdir/etc/security/limits.conf; then
  1023. echo '* hard maxlogins 2' >> $rootdir/etc/security/limits.conf
  1024. else
  1025. sed -i 's|hard maxlogins.*|hard maxlogins 2|g' $rootdir/etc/security/limits.conf
  1026. fi
  1027. # Email
  1028. chroot "$rootdir" apt-get -yq remove postfix
  1029. chroot "$rootdir" apt-get -yq install exim4 exim4-daemon-heavy sasl2-bin swaks libnet-ssleay-perl procmail
  1030. chroot "$rootdir" apt-get -yq install spamassassin
  1031. chroot "$rootdir" apt-get -yq install dovecot-imapd
  1032. #backup
  1033. chroot "$rootdir" apt-get -yq install obnam gnupg
  1034. # monkeysphere
  1035. #chroot "$rootdir" apt-get -yq install monkeysphere msva-perl
  1036. # encrypting email
  1037. chroot "$rootdir" apt-get -yq install libmail-gnupg-perl
  1038. git clone $GPGIT_REPO $rootdir/root/build/gpgit
  1039. cd $rootdir/root/build/gpgit
  1040. git checkout $GPGIT_COMMIT -b $GPGIT_COMMIT
  1041. cp $rootdir/root/build/gpgit/gpgit.pl $rootdir/usr/bin
  1042. echo "gpgit commit:$GPGIT_COMMIT" >> $rootdir/root/freedombone-completed.txt
  1043. # email client
  1044. chroot "$rootdir" apt-get -yq install lynx abook urlview mutt
  1045. git clone $CLEANUP_MAILDIR_REPO $rootdir/root/build/cleanup-maildir
  1046. cd $rootdir/root/build/cleanup-maildir
  1047. git checkout $CLEANUP_MAILDIR_COMMIT -b $CLEANUP_MAILDIR_COMMIT
  1048. cp $rootdir/root/build/cleanup-maildir/cleanup-maildir $rootdir/usr/bin
  1049. echo "cleanup-maildir commit:$CLEANUP_MAILDIR_COMMIT" >> $rootdir/root/freedombone-completed.txt
  1050. # web server
  1051. chroot "$rootdir" apt-get -yq remove --purge apache2
  1052. chroot "$rootdir" apt-get -yq install nginx php-fpm
  1053. git clone $NGINX_ENSITE_REPO $rootdir/root/build/nginx_ensite
  1054. cd $rootdir/root/build/nginx_ensite
  1055. git checkout $NGINX_ENSITE_COMMIT -b $NGINX_ENSITE_COMMIT
  1056. echo "nginx-ensite commit:$NGINX_ENSITE_COMMIT" >> $rootdir/root/freedombone-completed.txt
  1057. chroot "$rootdir" cd /root/build/nginx_ensite && make install
  1058. if [ ! -f $rootdir/etc/pam.d/nginx ]; then
  1059. echo '#%PAM-1.0' > $rootdir/etc/pam.d/nginx
  1060. echo '@include common-auth' >> $rootdir/etc/pam.d/nginx
  1061. echo '@include common-account' >> $rootdir/etc/pam.d/nginx
  1062. echo '@include common-session' >> $rootdir/etc/pam.d/nginx
  1063. fi
  1064. chroot "$rootdir" apt-get -yq install tripwire
  1065. # filesystem optimisations
  1066. sed -i 's|btrfs subvol=@|btrfs defaults,subvol=@,compress=lzo,ssd|g' $rootdir/etc/fstab
  1067. }
  1068. function image_install_nodejs {
  1069. mesh_install_nodejs
  1070. #echo 'install_nodejs' >> ${rootdir}/root/${PROJECT_NAME}-completed.txt
  1071. }
  1072. function image_preinstall_repos {
  1073. if [[ $VARIANT == "mesh"* ]]; then
  1074. return
  1075. fi
  1076. if [ ! -d $rootdir/repos ]; then
  1077. mkdir $rootdir/repos
  1078. fi
  1079. git clone $CMAKE_REPO $rootdir/repos/cmake
  1080. git clone $INADYN_REPO $rootdir/repos/inadyn
  1081. git clone $TOMB_REPO $rootdir/repos/tomb
  1082. if [[ $SOCIALINSTANCE == "gnusocial" ]]; then
  1083. git clone $GNUSOCIAL_REPO $rootdir/repos/gnusocial
  1084. git clone $GNUSOCIAL_MARKDOWN_REPO $rootdir/repos/gnusocial-markdown
  1085. git clone $QVITTER_THEME_REPO $rootdir/repos/qvitter
  1086. git clone $PLEROMA_REPO $rootdir/repos/pleroma
  1087. return
  1088. fi
  1089. if [[ $SOCIALINSTANCE == "postactiv" ]]; then
  1090. git clone $GNUSOCIAL_MARKDOWN_REPO $rootdir/repos/gnusocial-markdown
  1091. git clone $QVITTER_THEME_REPO $rootdir/repos/qvitter
  1092. git clone $PLEROMA_REPO $rootdir/repos/pleroma
  1093. git clone $POSTACTIV_REPO $rootdir/repos/postactiv
  1094. return
  1095. fi
  1096. git clone $CRYPTPAD_REPO $rootdir/repos/cryptpad
  1097. git clone $DOKUWIKI_REPO $rootdir/repos/dokuwiki
  1098. git clone $ETHERPAD_REPO $rootdir/repos/etherpad
  1099. git clone $FRIENDICA_REPO $rootdir/repos/friendica
  1100. git clone $GNUSOCIAL_REPO $rootdir/repos/gnusocial
  1101. git clone $GNUSOCIAL_MARKDOWN_REPO $rootdir/repos/gnusocial-markdown
  1102. git clone $QVITTER_THEME_REPO $rootdir/repos/qvitter
  1103. git clone $PLEROMA_REPO $rootdir/repos/pleroma
  1104. git clone $POSTACTIV_REPO $rootdir/repos/postactiv
  1105. git clone $SHARINGS_REPO $rootdir/repos/sharings
  1106. git clone $HTMLY_REPO $rootdir/repos/htmly
  1107. git clone $HUBZILLA_REPO $rootdir/repos/hubzilla
  1108. git clone $HUBZILLA_ADDONS_REPO $rootdir/repos/hubzilla-addons
  1109. git clone $KOEL_REPO $rootdir/repos/koel
  1110. #git clone $LIBREVAULT_REPO $rootdir/repos/librevault
  1111. git clone $LYCHEE_REPO $rootdir/repos/lychee
  1112. git clone $MAILPILE_REPO $rootdir/repos/mailpile
  1113. git clone $MATRIX_REPO $rootdir/repos/matrix
  1114. git clone $MEDIAGOBLIN_REPO $rootdir/repos/mediagoblin
  1115. #git clone $MOVIM_REPO $rootdir/repos/movim
  1116. git clone $NEXTCLOUD_REPO $rootdir/repos/nextcloud
  1117. git clone $PIHOLE_REPO $rootdir/repos/pihole
  1118. git clone $PROFANITY_REPO $rootdir/repos/profanity
  1119. git clone $LIBMESODE_REPO $rootdir/repos/libmesode
  1120. git clone $PROFANITY_OMEMO_PLUGIN_REPO $rootdir/repos/profanity-omemo
  1121. git clone $RSS_READER_REPO $rootdir/repos/rss
  1122. git clone $RSS_MOBILE_READER_REPO $rootdir/repos/rss-mobile
  1123. git clone $SEARX_REPO $rootdir/repos/searx
  1124. git clone $TOXCORE_REPO $rootdir/repos/toxcore
  1125. git clone $TOXID_REPO $rootdir/repos/toxid
  1126. git clone $TOXIC_REPO $rootdir/repos/toxic
  1127. git clone $TURTL_REPO $rootdir/repos/turtl
  1128. #git clone $ZERONET_REPO $rootdir/repos/zeronet
  1129. #git clone $QTOX_REPO $rootdir/repos/qtox
  1130. }
  1131. ##############################################################################
  1132. # Set to true/false to control if eatmydata is used during build
  1133. use_eatmydata=true
  1134. rootdir="$1"
  1135. fmdir="$(pwd)"
  1136. image="$fmdir"/"$2"
  1137. cd "$rootdir"
  1138. echo info: building $MACHINE for $ARCHITECTURE
  1139. export DEBIAN_FRONTEND=noninteractive DEBCONF_NONINTERACTIVE_SEEN=true
  1140. export LC_ALL=C LANGUAGE=C LANG=C
  1141. # Override libpam-tmpdir setting during build, as the directories
  1142. # are not created yet.
  1143. export TMP=/tmp/ TMPDIR=/tmp/
  1144. if [ ! $MY_USERNAME ]; then
  1145. echo $'No username was specified'
  1146. exit 52825
  1147. fi
  1148. username=$MY_USERNAME
  1149. echo $"warning: creating initial user $username with well known password!"
  1150. password=$MY_PASSWORD
  1151. chroot "$rootdir" /usr/bin/env -i \
  1152. HOME=/root \
  1153. PATH=/usr/local/bin:/usr/local/sbin:/usr/bin:/usr/sbin:/bin:/sbin
  1154. echo "export PATH=/usr/local/bin:/usr/local/sbin:/usr/bin:/usr/sbin:/bin:/sbin:" >> $rootdir/root/.bashrc
  1155. chroot "$rootdir" adduser --gecos $username --disabled-password $username
  1156. echo $username:$password | chroot "$rootdir" /usr/sbin/chpasswd
  1157. chroot "$rootdir" adduser $username sudo
  1158. if [ ! $DEBIAN_REPO ]; then
  1159. DEBIAN_REPO='ftp.de.debian.org'
  1160. fi
  1161. if [ ! $DEBIAN_VERSION ]; then
  1162. DEBIAN_VERSION='stretch'
  1163. fi
  1164. set_apt_sources $BUILD_MIRROR
  1165. chroot "$rootdir" apt-get clean
  1166. chroot "$rootdir" /bin/rm -rf /var/lib/apt/lists/*
  1167. chroot "$rootdir" apt-get clean
  1168. set_apt_sources $MIRROR
  1169. configure_backports
  1170. configure_contrib_repo
  1171. chroot "$rootdir" apt-get update
  1172. chroot "$rootdir" apt-get install -y apt-utils
  1173. cat > $rootdir/usr/sbin/policy-rc.d <<EOF
  1174. #!/bin/sh
  1175. exit 101
  1176. EOF
  1177. chmod a+rx $rootdir/usr/sbin/policy-rc.d
  1178. if $use_eatmydata ; then
  1179. enable_eatmydata_override
  1180. fi
  1181. if [ -n "$CUSTOM_SETUP" ]; then
  1182. cp "$CUSTOM_SETUP" "$rootdir"/tmp
  1183. chroot "$rootdir" apt-get install -y gdebi-core
  1184. chroot "$rootdir" gdebi -n /tmp/"$(basename $CUSTOM_SETUP)"
  1185. fi
  1186. if [[ $VARIANT != "mesh"* ]]; then
  1187. chroot "$rootdir" apt-get install -y openssh-server
  1188. fi
  1189. chroot "$rootdir" apt-get install -y sudo git dialog build-essential
  1190. chroot "$rootdir" apt-get install -y avahi-daemon avahi-utils avahi-discover avahi-autoipd
  1191. chroot "$rootdir" apt-get install -y iptables dnsutils net-tools network-manager iputils-ping
  1192. chroot "$rootdir" apt-get install -y libnss-mdns libnss-myhostname libnss-gw-name nano man ntp
  1193. chroot "$rootdir" apt-get install -y locales locales-all debconf wireless-tools wpasupplicant usbutils
  1194. if [[ $ARCHITECTURE == 'qemu'* || $ARCHITECTURE == 'i386' || $ARCHITECTURE == 'i686' || $ARCHITECTURE == 'amd64' || $ARCHITECTURE == 'x86_64' ]]; then
  1195. chroot "$rootdir" apt-get install -y cryptsetup zsh pinentry-curses iotop bc
  1196. chroot "$rootdir" apt-get install -y grub2 hostapd
  1197. fi
  1198. sed -i "s|#host-name=.*|host-name=${PROJECT_NAME}|g" $rootdir/etc/avahi/avahi-daemon.conf
  1199. sed -i "s|host-name=.*|host-name=${PROJECT_NAME}|g" $rootdir/etc/avahi/avahi-daemon.conf
  1200. sed -i "s|use-ipv4=.*|use-ipv4=yes|g" $rootdir/etc/avahi/avahi-daemon.conf
  1201. sed -i "s|use-ipv6=.*|use-ipv6=no|g" $rootdir/etc/avahi/avahi-daemon.conf
  1202. sed -i "s|#disallow-other-stacks=.*|disallow-other-stacks=yes|g" $rootdir/etc/avahi/avahi-daemon.conf
  1203. sed -i "s|hosts:.*|hosts: files mdns4_minimal dns mdns4 mdns|g" $rootdir/etc/nsswitch.conf
  1204. # Add an ssh avahi service
  1205. echo '<?xml version="1.0" standalone="no"?><!--*-nxml-*-->' > $rootdir/etc/avahi/services/ssh.service
  1206. echo '<!DOCTYPE service-group SYSTEM "avahi-service.dtd">' >> $rootdir/etc/avahi/services/ssh.service
  1207. echo '<service-group>' >> $rootdir/etc/avahi/services/ssh.service
  1208. echo ' <name replace-wildcards="yes">%h SSH</name>' >> $rootdir/etc/avahi/services/ssh.service
  1209. echo ' <service>' >> $rootdir/etc/avahi/services/ssh.service
  1210. echo ' <type>_ssh._tcp</type>' >> $rootdir/etc/avahi/services/ssh.service
  1211. echo " <port>$SSH_PORT</port>" >> $rootdir/etc/avahi/services/ssh.service
  1212. echo ' </service>' >> $rootdir/etc/avahi/services/ssh.service
  1213. echo '</service-group>' >> $rootdir/etc/avahi/services/ssh.service
  1214. # Ensure that the avahi daemon keeps running
  1215. WATCHDOG_SCRIPT_NAME="keepon"
  1216. echo '#!/bin/bash' > $rootdir/usr/bin/$WATCHDOG_SCRIPT_NAME
  1217. echo 'LOGFILE=/var/log/keepon.log' >> $rootdir/usr/bin/$WATCHDOG_SCRIPT_NAME
  1218. echo 'CURRENT_DATE=$(date)' >> $rootdir/usr/bin/$WATCHDOG_SCRIPT_NAME
  1219. echo '' >> $rootdir/usr/bin/$WATCHDOG_SCRIPT_NAME
  1220. echo "# keep avahi-daemon daemon running" >> $rootdir/usr/bin/$WATCHDOG_SCRIPT_NAME
  1221. echo "RUNNING=$(pgrep avahi-daemon > /dev/null && echo Running)" >> $rootdir/usr/bin/$WATCHDOG_SCRIPT_NAME
  1222. echo 'if [ ! $RUNNING ]; then' >> $rootdir/usr/bin/$WATCHDOG_SCRIPT_NAME
  1223. echo " systemctl start avahi-daemon" >> $rootdir/usr/bin/$WATCHDOG_SCRIPT_NAME
  1224. echo ' echo -n $CURRENT_DATE >> $LOGFILE' >> $rootdir/usr/bin/$WATCHDOG_SCRIPT_NAME
  1225. echo " echo \"avahi-daemon daemon restarted\" >> \$LOGFILE" >> $rootdir/usr/bin/$WATCHDOG_SCRIPT_NAME
  1226. echo 'fi' >> $rootdir/usr/bin/$WATCHDOG_SCRIPT_NAME
  1227. echo "# End of avahi-daemon" >> $rootdir/usr/bin/$WATCHDOG_SCRIPT_NAME
  1228. chmod +x $rootdir/usr/bin/$WATCHDOG_SCRIPT_NAME
  1229. echo "*/1 * * * * root /usr/bin/$WATCHDOG_SCRIPT_NAME" >> $rootdir/etc/crontab
  1230. chroot "$rootdir" /bin/bash -x <<EOF
  1231. git clone $PROJECT_REPO /root/$PROJECT_NAME
  1232. cd /root/$PROJECT_NAME
  1233. git checkout stretch
  1234. make install
  1235. cp image_build/bbb-4.9.0.tar.gz /boot/bbb.tar.gz
  1236. EOF
  1237. chroot "$rootdir" ${PROJECT_NAME}-image-hardware-setup 2>&1 | \
  1238. tee $rootdir/var/log/${PROJECT_NAME}-image-hardware-setup.log
  1239. rm $rootdir/usr/sbin/policy-rc.d
  1240. # Set up HRNG for systems known to have one
  1241. # Otherwise install haveged
  1242. if [[ "$MACHINE" != "beaglebone"* ]]; then
  1243. chroot $rootdir apt-get -yq install haveged
  1244. else
  1245. chroot $rootdir apt-get -yq install rng-tools
  1246. sed -i 's|#HRNGDEVICE=/dev/hwrng|HRNGDEVICE=/dev/hwrng|g' $rootdir/etc/default/rng-tools
  1247. fi
  1248. # copy u-boot to beginning of image
  1249. case "$MACHINE" in
  1250. beaglebone)
  1251. dd if=$rootdir/usr/lib/u-boot/am335x_boneblack/MLO of="$image" \
  1252. count=1 seek=1 conv=notrunc bs=128k
  1253. dd if=$rootdir/usr/lib/u-boot/am335x_boneblack/u-boot.img of="$image" \
  1254. count=2 seek=1 conv=notrunc bs=384k
  1255. ;;
  1256. beaglebonewifi)
  1257. touch $rootdir/root/.wifi-only
  1258. dd if=$rootdir/usr/lib/u-boot/am335x_boneblack/MLO of="$image" \
  1259. count=1 seek=1 conv=notrunc bs=128k
  1260. dd if=$rootdir/usr/lib/u-boot/am335x_boneblack/u-boot.img of="$image" \
  1261. count=2 seek=1 conv=notrunc bs=384k
  1262. ;;
  1263. cubieboard2)
  1264. dd if=$rootdir/usr/lib/u-boot/Cubieboard2/u-boot-sunxi-with-spl.bin of="$image" \
  1265. seek=8 conv=notrunc bs=1k
  1266. ;;
  1267. a20-olinuxino-lime)
  1268. dd if=$rootdir/usr/lib/u-boot/A20-OLinuXino-Lime/u-boot-sunxi-with-spl.bin \
  1269. of="$image" seek=8 conv=notrunc bs=1k
  1270. ;;
  1271. esac
  1272. if $use_eatmydata ; then
  1273. disable_eatmydata_override
  1274. fi
  1275. configure_ssh
  1276. configure_networking
  1277. admin_user_sudo
  1278. create_generic_image
  1279. atheros_wifi
  1280. continue_installation
  1281. initialise_mesh
  1282. configure_wifi
  1283. configure_user_interface
  1284. image_setup_utils
  1285. image_install_inadyn
  1286. image_install_nodejs
  1287. image_preinstall_repos
  1288. # remove downloaded packages
  1289. chroot $rootdir apt-get -y autoremove
  1290. chroot $rootdir apt-get clean
  1291. cd /
  1292. echo $"info: killing leftover processes in chroot"
  1293. fuser -mvk $rootdir/. || true
  1294. exit 0