freedombone-image-customise 61KB

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