freedombone-image-customise 55KB

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