freedombone-image-customise 63KB

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