freedombone-image-customise 62KB

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