freedombone-image-customise 62KB

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