freedombone-image-customise 44KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085
  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 [[ $DEBIAN_INSTALL_ONLY != "no" ]]; then
  140. return
  141. fi
  142. if [[ $GENERIC_IMAGE == "no" ]]; then
  143. echo "# This file describes the network interfaces available on your system
  144. # and how to activate them. For more information, see interfaces(5).
  145. # The loopback network interface
  146. auto lo
  147. iface lo inet loopback
  148. # The primary network interface
  149. auto eth0
  150. iface eth0 inet static
  151. address $BOX_IP_ADDRESS
  152. netmask 255.255.255.0
  153. gateway $ROUTER_IP_ADDRESS
  154. dns-nameservers $NAMESERVER1 $NAMESERVER2
  155. # Example to keep MAC address between reboots
  156. #hwaddress ether B5:A2:BE:3F:1A:FE
  157. # The secondary network interface
  158. #auto eth1
  159. #iface eth1 inet dhcp
  160. # WiFi Example
  161. #auto wlan0
  162. #iface wlan0 inet dhcp
  163. # wpa-ssid \"essid\"
  164. # wpa-psk \"password\"
  165. # Ethernet/RNDIS gadget (g_ether)
  166. # ... or on host side, usbnet and random hwaddr
  167. # Note on some boards, usb0 is automaticly setup with an init script
  168. #iface usb0 inet static
  169. # address 192.168.7.2
  170. # netmask 255.255.255.0
  171. # network 192.168.7.0
  172. # gateway 192.168.7.1" > $rootdir/etc/network/interfaces
  173. hexarray=( 1 2 3 4 5 6 7 8 9 0 a b c d e f )
  174. a=${hexarray[$RANDOM%16]}${hexarray[$RANDOM%16]}
  175. b=${hexarray[$RANDOM%16]}${hexarray[$RANDOM%16]}
  176. c=${hexarray[$RANDOM%16]}${hexarray[$RANDOM%16]}
  177. d=${hexarray[$RANDOM%16]}${hexarray[$RANDOM%16]}
  178. e=${hexarray[$RANDOM%16]}${hexarray[$RANDOM%16]}
  179. sed -i "s|#hwaddress ether.*|hwaddress ether de:$a:$b:$c:$d:$e|g" \
  180. $rootdir/etc/network/interfaces
  181. fi
  182. sed -i "s/nameserver.*/nameserver $NAMESERVER1/g" $rootdir/etc/resolv.conf
  183. sed -i "/nameserver $NAMESERVER1/a\nameserver $NAMESERVER2" $rootdir/etc/resolv.conf
  184. if [[ $VARIANT != "meshclient" && $VARIANT != "meshusb" ]]; then
  185. # change the motd to show further install instructions
  186. echo $"
  187. .---. . .
  188. | | |
  189. |--- .--. .-. .-. .-.| .-. .--.--. |.-. .-. .--. .-.
  190. | | (.-' (.-' ( | ( )| | | | )( )| | (.-'
  191. ' ' --' --' -' - -' ' ' -' -' -' ' - --'
  192. Initial base install
  193. Your system is not yet installed. To complete the process run the
  194. following commands, then enter your details.
  195. sudo su
  196. ${PROJECT_NAME} menuconfig
  197. " > $rootdir/etc/motd
  198. else
  199. echo $"
  200. .---. . .
  201. | | |
  202. |--- .--. .-. .-. .-.| .-. .--.--. |.-. .-. .--. .-.
  203. | | (.-' (.-' ( | ( )| | | | )( )| | (.-'
  204. ' ' --' --' -' - -' ' ' -' -' -' ' - --'
  205. Freedom in the Mesh
  206. " > $rootdir/etc/motd
  207. fi
  208. }
  209. configure_ssh() {
  210. if [[ $VARIANT == "mesh" || $VARIANT == "meshclient" || $VARIANT == "meshusb" ]]; then
  211. return
  212. fi
  213. sed -i "s/Port .*/Port ${SSH_PORT}/g" $rootdir/etc/ssh/sshd_config
  214. if [[ "$SSH_PUBKEY" != "no" ]]; then
  215. if [ ! -d $rootdir/home/$MY_USERNAME/.ssh ]; then
  216. mkdir $rootdir/home/$MY_USERNAME/.ssh
  217. fi
  218. echo "$SSH_PUBKEY" > $rootdir/home/$MY_USERNAME/.ssh/authorized_keys
  219. chroot $rootdir /bin/chown -R $MY_USERNAME:$MY_USERNAME /home/$MY_USERNAME/.ssh
  220. sed -i 's|PasswordAuthentication.*|PasswordAuthentication no|g' $rootdir/etc/ssh/sshd_config
  221. echo $"Using ssh public key:"
  222. echo $SSH_PUBKEY
  223. echo $'Password ssh authentication turned off'
  224. fi
  225. }
  226. create_generic_image() {
  227. if [[ $DEBIAN_INSTALL_ONLY != "no" ]]; then
  228. return
  229. fi
  230. if [[ $GENERIC_IMAGE == "no" ]]; then
  231. return
  232. fi
  233. if [ $CONFIG_FILENAME ]; then
  234. if [[ "$CONFIG_FILENAME" == *"mesh.cfg"* ]]; then
  235. VARIANT="mesh"
  236. fi
  237. fi
  238. # Don't install any configuration. This will be a base system
  239. if [[ $VARIANT != "mesh" && $VARIANT != "meshclient" && $VARIANT != "meshusb" ]]; then
  240. CONFIG_FILENAME=
  241. else
  242. touch $rootdir/root/.initial_mesh_setup
  243. fi
  244. # Stick with the existing login for mesh clients
  245. if [[ $VARIANT == "meshclient" || $VARIANT == "meshusb" ]]; then
  246. return
  247. fi
  248. # The presence of this file indicates that the initial
  249. # setup has not yet been completed
  250. touch $rootdir/home/$MY_USERNAME/.initial_setup
  251. chroot $rootdir /bin/chown $MY_USERNAME:$MY_USERNAME /home/$MY_USERNAME/.initial_setup
  252. touch $rootdir/root/.initial_setup
  253. cat >> $rootdir/home/$MY_USERNAME/.bashrc <<EOF
  254. # initial setup of the system
  255. if [ -f ~/.initial_setup ]; then
  256. clear
  257. echo "
  258. .---. . .
  259. | | |
  260. |--- .--. .-. .-. .-.| .-. .--.--. |.-. .-. .--. .-.
  261. | | (.-' (.-' ( | ( )| | | | )( )| | (.-'
  262. ' ' --' --' -' - -' ' ' -' -' -' ' - --'
  263. Initial setup process
  264. Please enter your password a second time.
  265. "
  266. sudo su
  267. fi
  268. EOF
  269. echo "MY_USERNAME=${MY_USERNAME}" >> $rootdir/root/.bashrc
  270. echo "SSH_PORT=${SSH_PORT}" >> $rootdir/root/.bashrc
  271. echo '# initial setup of the system' >> $rootdir/root/.bashrc
  272. echo 'if [ -f ~/.initial_setup ]; then' >> $rootdir/root/.bashrc
  273. echo ' if [ -f ~/login.txt ]; then' >> $rootdir/root/.bashrc
  274. echo ' NEW_USER_PASSWORD=$(printf `cat ~/login.txt`)' >> $rootdir/root/.bashrc
  275. echo ' else' >> $rootdir/root/.bashrc
  276. echo ' ENTROPY=$(cat /proc/sys/kernel/random/entropy_avail)' >> $rootdir/root/.bashrc
  277. echo ' if [ $ENTROPY -lt 500 ]; then' >> $rootdir/root/.bashrc
  278. ENTROPY_MESSAGE1=$'Initial setup process'
  279. ENTROPY_MESSAGE2=$'Password Generation'
  280. ENTROPY_MESSAGE3=$'WARNING: The entropy available on this system is too low to generate a password.\n\nThe installation process cannot continue.'
  281. echo " dialog --backtitle \"${ENTROPY_MESSAGE1}\" --title \"${ENTROPY_MESSAGE2}\" --msgbox \"${ENTROPY_MESSAGE3}\" 8 50" >> $rootdir/root/.bashrc
  282. echo ' exit' >> $rootdir/root/.bashrc
  283. echo ' fi' >> $rootdir/root/.bashrc
  284. echo -n ' NEW_USER_PASSWORD="$(openssl rand -base64 30 | cut -c1-' >> $rootdir/root/.bashrc
  285. echo "${DEFAULT_PASSWORD_LENGTH})\"" >> $rootdir/root/.bashrc
  286. echo ' fi' >> $rootdir/root/.bashrc
  287. echo ' echo "${NEW_USER_PASSWORD}" > ~/login.txt' >> $rootdir/root/.bashrc
  288. echo ' clear' >> $rootdir/root/.bashrc
  289. echo ' echo ""' >> $rootdir/root/.bashrc
  290. NEW_LOGIN_PASSWORD_MESSAGE1=$'Your new login password is:'
  291. NEW_LOGIN_PASSWORD_MESSAGE2=$'Use it whenever you wish to ssh into this system.'
  292. NEW_LOGIN_PASSWORD_MESSAGE3=$'IMPORTANT: Please take a moment to enter the above password into a\npassword manager or write it down somewhere.'
  293. PRESS_KEY_MESSAGE=$'Press any key to continue...'
  294. echo " echo \"${NEW_LOGIN_PASSWORD_MESSAGE1}\"" >> $rootdir/root/.bashrc
  295. echo ' echo ""' >> $rootdir/root/.bashrc
  296. echo ' echo " ${NEW_USER_PASSWORD}"' >> $rootdir/root/.bashrc
  297. echo ' echo ""' >> $rootdir/root/.bashrc
  298. echo " echo \"${NEW_LOGIN_PASSWORD_MESSAGE2}\"" >> $rootdir/root/.bashrc
  299. echo ' echo ""' >> $rootdir/root/.bashrc
  300. echo " echo \"${NEW_LOGIN_PASSWORD_MESSAGE3}\"" >> $rootdir/root/.bashrc
  301. echo ' echo ""' >> $rootdir/root/.bashrc
  302. echo " read -n1 -r -p \"${PRESS_KEY_MESSAGE}\" key" >> $rootdir/root/.bashrc
  303. # change the password for the admin user
  304. echo -n " echo \"${MY_USERNAME}:" >> $rootdir/root/.bashrc
  305. echo '$(printf `cat ~/login.txt`)"|chpasswd' >> $rootdir/root/.bashrc
  306. # update before continuing
  307. echo " cd /root/${PROJECT_NAME}" >> $rootdir/root/.bashrc
  308. echo " git stash" >> $rootdir/root/.bashrc
  309. echo " git pull" >> $rootdir/root/.bashrc
  310. echo " make install" >> $rootdir/root/.bashrc
  311. if [[ $VARIANT != "mesh" && $VARIANT != "meshclient" && $VARIANT != "meshusb" && $VARIANT != "usb" ]]; then
  312. if [[ $ONION_ONLY == "no" ]]; then
  313. if [[ $MINIMAL_INSTALL == "no" ]]; then
  314. echo " ${PROJECT_NAME} menuconfig-full" >> $rootdir/root/.bashrc
  315. else
  316. echo " ${PROJECT_NAME} menuconfig" >> $rootdir/root/.bashrc
  317. fi
  318. else
  319. echo " ${PROJECT_NAME} menuconfig-onion" >> $rootdir/root/.bashrc
  320. fi
  321. else
  322. echo " echo ''" >> $rootdir/root/.bashrc
  323. fi
  324. echo ' if [ "$?" = "0" ]; then' >> $rootdir/root/.bashrc
  325. echo " if [ -f ~/${PROJECT_NAME}-completed.txt ]; then" >> $rootdir/root/.bashrc
  326. # Remove the initial setup files
  327. echo ' rm /root/.initial_setup' >> $rootdir/root/.bashrc
  328. echo ' rm /home/fbone/.initial_setup' >> $rootdir/root/.bashrc
  329. echo " touch /root/.remove_${GENERIC_IMAGE_USERNAME}" >> $rootdir/root/.bashrc
  330. echo ' shred -zu ~/login.txt' >> $rootdir/root/.bashrc
  331. if [[ $VARIANT != "mesh" && $VARIANT != "meshclient" && $VARIANT != "meshusb" && $VARIANT != "usb" ]]; then
  332. echo ' SSH_ONION_HOSTNAME=$(cat /var/lib/tor/hidden_service_ssh/hostname)' >> $rootdir/root/.bashrc
  333. echo ' if [ ${#SSH_ONION_HOSTNAME} -lt 2 ]; then' >> $rootdir/root/.bashrc
  334. echo ' exit 62392' >> $rootdir/root/.bashrc
  335. echo ' fi' >> $rootdir/root/.bashrc
  336. fi
  337. echo " if [ -f /root/${PROJECT_NAME}-wifi.cfg ]; then" >> $rootdir/root/.bashrc
  338. echo " echo '[Unit]' > /etc/systemd/system/wifistart.service" >> $rootdir/root/.bashrc
  339. echo " echo 'Description=WifiStartup (Start wifi networking)' >> /etc/systemd/system/wifistart.service" >> $rootdir/root/.bashrc
  340. echo " echo 'After=syslog.target' >> /etc/systemd/system/wifistart.service" >> $rootdir/root/.bashrc
  341. echo " echo 'After=network.target' >> /etc/systemd/system/wifistart.service" >> $rootdir/root/.bashrc
  342. echo " echo 'After=remote-fs.target' >> /etc/systemd/system/wifistart.service" >> $rootdir/root/.bashrc
  343. echo " echo '' >> /etc/systemd/system/wifistart.service" >> $rootdir/root/.bashrc
  344. echo " echo '[Service]' >> /etc/systemd/system/wifistart.service" >> $rootdir/root/.bashrc
  345. echo " echo 'Type=simple' >> /etc/systemd/system/wifistart.service" >> $rootdir/root/.bashrc
  346. echo " echo 'User=root' >> /etc/systemd/system/wifistart.service" >> $rootdir/root/.bashrc
  347. echo " echo 'Group=root' >> /etc/systemd/system/wifistart.service" >> $rootdir/root/.bashrc
  348. echo " echo 'WorkingDirectory=/root' >> /etc/systemd/system/wifistart.service" >> $rootdir/root/.bashrc
  349. echo " echo 'ExecStart=/usr/local/bin/freedombone-wifi --wait 5 2> /dev/null' >> /etc/systemd/system/wifistart.service" >> $rootdir/root/.bashrc
  350. echo " echo '' >> /etc/systemd/system/wifistart.service" >> $rootdir/root/.bashrc
  351. echo " echo '[Install]' >> /etc/systemd/system/wifistart.service" >> $rootdir/root/.bashrc
  352. echo " echo 'WantedBy=multi-user.target' >> /etc/systemd/system/wifistart.service" >> $rootdir/root/.bashrc
  353. echo " systemctl enable wifistart" >> $rootdir/root/.bashrc
  354. echo " systemctl daemon-reload" >> $rootdir/root/.bashrc
  355. echo ' fi' >> $rootdir/root/.bashrc
  356. echo ' reboot' >> $rootdir/root/.bashrc
  357. echo ' fi' >> $rootdir/root/.bashrc
  358. echo ' else' >> $rootdir/root/.bashrc
  359. echo ' key=' >> $rootdir/root/.bashrc
  360. echo ' while [[ $key != "x" ]]; do' >> $rootdir/root/.bashrc
  361. INSTALL_FAIL_MESSAGE=$"Install failed. Press x to continue..."
  362. echo " read -n1 -r -p \"${INSTALL_FAIL_MESSAGE}\" key" >> $rootdir/root/.bashrc
  363. echo ' done' >> $rootdir/root/.bashrc
  364. echo ' fi' >> $rootdir/root/.bashrc
  365. echo ' exit' >> $rootdir/root/.bashrc
  366. echo 'else' >> $rootdir/root/.bashrc
  367. echo ' # Remove default account after install' >> $rootdir/root/.bashrc
  368. echo " if [ -f /root/.remove_${GENERIC_IMAGE_USERNAME} ]; then" >> $rootdir/root/.bashrc
  369. echo " if [ -d /home/${GENERIC_IMAGE_USERNAME} ]; then" >> $rootdir/root/.bashrc
  370. echo " userdel -r ${GENERIC_IMAGE_USERNAME}" >> $rootdir/root/.bashrc
  371. echo " if [ -d /home/${GENERIC_IMAGE_USERNAME} ]; then" >> $rootdir/root/.bashrc
  372. echo " rm -rf /home/${GENERIC_IMAGE_USERNAME}" >> $rootdir/root/.bashrc
  373. echo " rm /root/.remove_${GENERIC_IMAGE_USERNAME}" >> $rootdir/root/.bashrc
  374. echo ' fi' >> $rootdir/root/.bashrc
  375. echo ' fi' >> $rootdir/root/.bashrc
  376. echo ' fi' >> $rootdir/root/.bashrc
  377. echo 'fi' >> $rootdir/root/.bashrc
  378. }
  379. continue_installation() {
  380. # If a configuration file exists then run with it
  381. # otherwise the interactive installer can be used
  382. # This is equivalent to installing freedombox-setup on freedombox
  383. if [ $CONFIG_FILENAME ]; then
  384. if [ ${#CONFIG_FILENAME} -gt 2 ]; then
  385. cp $CONFIG_FILENAME $rootdir/root/$PROJECT_NAME.cfg
  386. cat $rootdir/root/$PROJECT_NAME.cfg
  387. chroot "$rootdir" su -c "$PROJECT_NAME -c /root/$PROJECT_NAME.cfg" - root
  388. fi
  389. fi
  390. }
  391. atheros_wifi() {
  392. firmware_filename="open-ath9k-htc-firmware_1.3-1_all.deb"
  393. firmware_hash='5fea58ffefdf0ef15b504db7fbe3bc078c03e0d927bba64085e4b6f2546102f5'
  394. firmware_url="http://us.archive.trisquel.info/trisquel/pool/main/o/open-ath9k-htc-firmware/$firmware_filename"
  395. firmware_tempfile="/tmp/$firmware_filename"
  396. wget "$firmware_url" -O "$rootdir$firmware_tempfile"
  397. downloaded_firmware_hash=$(sha256sum "$rootdir$firmware_tempfile" | awk -F ' ' '{print $1}')
  398. if [[ "$downloaded_firmware_hash" == "$firmware_hash" ]]; then
  399. chroot "$rootdir" dpkg -i "$firmware_tempfile"
  400. else
  401. echo 'WARNING: Atheros Wifi firmware hash does not match. The driver has not been installed.'
  402. fi
  403. }
  404. configure_wifi() {
  405. if [[ $VARIANT == "mesh"* ]]; then
  406. return
  407. fi
  408. if [ -f $WIFI_NETWORKS_FILE ]; then
  409. chroot "$rootdir" ${PROJECT_NAME}-wifi --networks $WIFI_NETWORKS_FILE
  410. return
  411. fi
  412. if [[ $WIFI_TYPE != 'none' ]]; then
  413. if [ ${#WIFI_PASSPHRASE} -lt 2 ]; then
  414. return
  415. fi
  416. chroot "$rootdir" ${PROJECT_NAME}-wifi -s $WIFI_SSID -t $WIFI_TYPE -p $WIFI_PASSPHRASE --hotspot $WIFI_HOTSPOT
  417. else
  418. chroot "$rootdir" ${PROJECT_NAME}-wifi -s $WIFI_SSID -t $WIFI_TYPE --hotspot $WIFI_HOTSPOT
  419. fi
  420. }
  421. ##############################################################################
  422. # Mesh networking
  423. ##############################################################################
  424. # for mesh installs
  425. TRACKER_PORT=6969
  426. WIFI_CHANNEL=2
  427. # B.A.T.M.A.N settings
  428. BATMAN_CELLID='02:BA:00:00:03:01'
  429. WIFI_SSID='mesh'
  430. # To avoid confusions these are obtained from the main project file
  431. TOXID_REPO=
  432. TOX_PORT=
  433. TOXCORE_REPO=
  434. TOXIC_REPO=
  435. TOXCORE_COMMIT=
  436. TOXIC_COMMIT=
  437. # These are some default nodes, but you can replace them with trusted nodes
  438. # as you prefer. See https://wiki.tox.im/Nodes
  439. TOX_NODES=
  440. #TOX_NODES=(
  441. # '192.254.75.102,2607:5600:284::2,33445,951C88B7E75C867418ACDB5D273821372BB5BD652740BCDF623A4FA293E75D2F,Tox RELENG,US'
  442. # '144.76.60.215,2a01:4f8:191:64d6::1,33445,04119E835DF3E78BACF0F84235B300546AF8B936F035185E2A8E9E0A67C8924F,sonOfRa,DE'
  443. #)
  444. # To avoid confusions these are obtained from the main project file
  445. ZERONET_REPO=
  446. ZERONET_COMMIT=
  447. ZERONET_PORT=
  448. ZERONET_BLOG_REPO=
  449. ZERONET_BLOG_COMMIT=
  450. ZERONET_MAIL_REPO=
  451. ZERONET_MAIL_COMMIT=
  452. ZERONET_FORUM_REPO=
  453. ZERONET_FORUM_COMMIT=
  454. ZERONET_ID_REPO=
  455. ZERONET_ID_COMMIT=
  456. # Directory where source code is downloaded and compiled
  457. INSTALL_DIR=$HOME/build
  458. INSTALLING_MESH=
  459. initialise_mesh() {
  460. if [[ $VARIANT != "mesh" && $VARIANT != "meshclient" && $VARIANT != "meshusb" ]]; then
  461. return
  462. fi
  463. if [[ $DEBIAN_INSTALL_ONLY != "no" ]]; then
  464. return
  465. fi
  466. if [[ $INSECURE == $'yes' ]]; then
  467. echo '*********************************************************'
  468. echo $'WARNING: non-free wifi drivers are being installed.'
  469. echo $' This may compromise the security of your system.'
  470. echo '*********************************************************'
  471. # enable non-free repo
  472. if ! grep -q "non-free" $rootdir/etc/apt/sources.list; then
  473. chroot "$rootdir" /bin/sed -i "s| main| main non-free|g" /etc/apt/sources.list
  474. fi
  475. chroot "$rootdir" apt-get update
  476. # install proprietary wifi drivers
  477. # see https://wiki.debian.org/iwlwifi
  478. chroot "$rootdir" apt-get -yq install firmware-iwlwifi firmware-b43-installer firmware-brcm80211
  479. fi
  480. INSTALLING_MESH=1
  481. configure_firewall
  482. install_avahi
  483. install_batman
  484. install_tomb
  485. #install_tahoelafs
  486. #install_librevault
  487. install_ipfs
  488. install_tox
  489. install_web_server
  490. install_pelican
  491. if [ $ENABLE_ZERONET ]; then
  492. install_zeronet
  493. fi
  494. MESH_SERVICE='mesh-setup.service'
  495. MESH_SETUP_DAEMON=$rootdir/etc/systemd/system/$MESH_SERVICE
  496. MESH_STARTUP_PARAMS="${MY_USERNAME}"
  497. if [[ $AMNESIC != 'no' ]]; then
  498. MESH_STARTUP_PARAMS="${MY_USERNAME} amnesic"
  499. fi
  500. echo '[Unit]' > $MESH_SETUP_DAEMON
  501. echo 'Description=Initial mesh router configuration' >> $MESH_SETUP_DAEMON
  502. echo 'After=syslog.target' >> $MESH_SETUP_DAEMON
  503. echo 'After=network.target' >> $MESH_SETUP_DAEMON
  504. echo '' >> $MESH_SETUP_DAEMON
  505. echo '[Service]' >> $MESH_SETUP_DAEMON
  506. echo 'Type=simple' >> $MESH_SETUP_DAEMON
  507. echo 'User=root' >> $MESH_SETUP_DAEMON
  508. echo 'Group=root' >> $MESH_SETUP_DAEMON
  509. echo 'WorkingDirectory=/root' >> $MESH_SETUP_DAEMON
  510. echo "ExecStart=/usr/local/bin/${PROJECT_NAME}-image-mesh ${MESH_STARTUP_PARAMS} > /var/log/mesh-setup.log" >> $MESH_SETUP_DAEMON
  511. echo '' >> $MESH_SETUP_DAEMON
  512. echo 'TimeoutSec=99999' >> $MESH_SETUP_DAEMON
  513. echo '' >> $MESH_SETUP_DAEMON
  514. echo '[Install]' >> $MESH_SETUP_DAEMON
  515. echo 'WantedBy=multi-user.target' >> $MESH_SETUP_DAEMON
  516. chmod +x $MESH_SETUP_DAEMON
  517. chroot "$rootdir" systemctl enable $MESH_SERVICE
  518. }
  519. # User interface for USB drive installs ######################################
  520. function mesh_client_startup_applications {
  521. if [ ! -d $rootdir/home/$MY_USERNAME/Desktop ]; then
  522. mkdir -p $rootdir/home/$MY_USERNAME/Desktop
  523. fi
  524. if [ ! -d $rootdir/home/$MY_USERNAME/.config/autostart ]; then
  525. mkdir -p $rootdir/home/$MY_USERNAME/.config/autostart
  526. chroot "$rootdir" /bin/chown -R $MY_USERNAME:$MY_USERNAME /home/$MY_USERNAME/.config
  527. fi
  528. START_DESKTOP=$rootdir/home/$MY_USERNAME/mesh-desktop.sh
  529. FIRST_BOOT=/home/$MY_USERNAME/.first_boot
  530. TAHOE_COMMAND="cd /var/lib/tahoelafs && venv/bin/tahoe"
  531. echo '#!/bin/bash' > $START_DESKTOP
  532. echo "setxkbmap ${KEYBOARD_MAP}" > $START_DESKTOP
  533. echo 'dconf write /org/mate/caja/desktop/volumes-visible false' >> $START_DESKTOP
  534. echo 'dconf write /org/mate/caja/desktop/computer-icon-visible false' >> $START_DESKTOP
  535. echo 'dconf write /org/mate/caja/desktop/home-icon-visible false' >> $START_DESKTOP
  536. echo 'dconf write /org/mate/caja/desktop/network-icon-visible false' >> $START_DESKTOP
  537. echo 'dconf write /org/mate/caja/desktop/trash-icon-visible false' >> $START_DESKTOP
  538. echo 'dconf write /org/mate/caja/desktop/volumes-visible false' >> $START_DESKTOP
  539. echo 'dconf write /org/mate/desktop/media-handling/automount-open false' >> $START_DESKTOP
  540. echo 'dconf write /org/mate/screensaver/lock-enabled false' >> $START_DESKTOP
  541. echo 'dconf write /org/mate/power-manager/lock-keyring-suspend false' >> $START_DESKTOP
  542. echo 'dconf write /org/mate/power-manager/lock-suspend false' >> $START_DESKTOP
  543. echo 'dconf write /org/mate/power-manager/lock-use-screensaver false' >> $START_DESKTOP
  544. echo 'dconf write /org/mate/power-manager/lock-blank-screen false' >> $START_DESKTOP
  545. echo 'dconf write /org/mate/power-manager/lock-hibernate false' >> $START_DESKTOP
  546. echo 'dconf write /org/mate/power-manager/lock-keyring-hibernate false' >> $START_DESKTOP
  547. echo 'dconf write /org/mate/desktop/peripherals/touchpad/scroll-method 2' >> $START_DESKTOP
  548. echo "touch /home/$MY_USERNAME/.dbus/Xdbus" >> $START_DESKTOP
  549. echo "chmod 600 /home/$MY_USERNAME/.dbus/Xdbus" >> $START_DESKTOP
  550. echo "env | grep DBUS_SESSION_BUS_ADDRESS > /home/$MY_USERNAME/.dbus/Xdbus" >> $START_DESKTOP
  551. echo "echo 'export DBUS_SESSION_BUS_ADDRESS' >> /home/$MY_USERNAME/.dbus/Xdbus" >> $START_DESKTOP
  552. echo '' >> $START_DESKTOP
  553. echo "amixer set 'Master' unmute" >> $START_DESKTOP
  554. echo "amixer set 'Master' 50%" >> $START_DESKTOP
  555. echo '' >> $START_DESKTOP
  556. echo '' >> $START_DESKTOP
  557. echo "if [ ! -f $FIRST_BOOT ]; then" >> $START_DESKTOP
  558. echo " $TAHOE_COMMAND start" >> $START_DESKTOP
  559. echo ' exit 0' >> $START_DESKTOP
  560. echo 'fi' >> $START_DESKTOP
  561. echo '' >> $START_DESKTOP
  562. echo 'INITIAL_TOX_USERNAME=""' >> $START_DESKTOP
  563. echo 'while [ ${#INITIAL_TOX_USERNAME} -eq 0 ]; do' >> $START_DESKTOP
  564. echo ' data=$(tempfile 2>/dev/null)' >> $START_DESKTOP
  565. echo ' trap "rm -f $data" 0 1 2 5 15' >> $START_DESKTOP
  566. echo -n " dialog --title \"${MESH_TITLE}\" " >> $START_DESKTOP
  567. echo -n "--backtitle \"${MESH_TITLE}\" " >> $START_DESKTOP
  568. echo -n "--inputbox \"${MESH_SET_USERNAME}\" 12 60 Anon " >> $START_DESKTOP
  569. echo '2>$data' >> $START_DESKTOP
  570. echo ' sel=$?' >> $START_DESKTOP
  571. echo ' case $sel in' >> $START_DESKTOP
  572. echo ' 0)' >> $START_DESKTOP
  573. echo ' INITIAL_TOX_USERNAME=$(<$data)' >> $START_DESKTOP
  574. echo ' ;;' >> $START_DESKTOP
  575. echo ' esac' >> $START_DESKTOP
  576. echo 'done' >> $START_DESKTOP
  577. echo '' >> $START_DESKTOP
  578. echo 'toxid --setuser "$INITIAL_TOX_USERNAME"' >> $START_DESKTOP
  579. echo '' >> $START_DESKTOP
  580. echo "if [ -f /home/$MY_USERNAME/.tahoe/tahoe.cfg ]; then" >> $START_DESKTOP
  581. echo " sed -i 's|nickname =.*|nickname = \$INITIAL_TOX_USERNAME|g' /home/$MY_USERNAME/.tahoe/tahoe.cfg" >> $START_DESKTOP
  582. echo " $TAHOE_COMMAND restart" >> $START_DESKTOP
  583. echo 'fi' >> $START_DESKTOP
  584. echo '' >> $START_DESKTOP
  585. echo "rm -f $FIRST_BOOT" >> $START_DESKTOP
  586. echo '' >> $START_DESKTOP
  587. echo 'exit 0' >> $START_DESKTOP
  588. chmod +x $START_DESKTOP
  589. START_DESKTOP2=$rootdir/home/$MY_USERNAME/.config/autostart/mesh-start.desktop
  590. echo '[Desktop Entry]' > $START_DESKTOP2
  591. echo 'Type=Application' >> $START_DESKTOP2
  592. echo 'Name=Mesh start desktop script' >> $START_DESKTOP2
  593. echo "Exec=bash -c '~/mesh-desktop.sh'" >> $START_DESKTOP2
  594. echo 'X-GNOME-Autostart-enabled=true' >> $START_DESKTOP2
  595. chmod +x $START_DESKTOP2
  596. START_DESKTOP3=$rootdir/home/$MY_USERNAME/.config/autostart/set_username.desktop
  597. echo '[Desktop Entry]' > $START_DESKTOP3
  598. echo 'Version=1.0' >> $START_DESKTOP3
  599. echo 'Name=Set Username' >> $START_DESKTOP3
  600. echo 'Type=Application' >> $START_DESKTOP3
  601. echo 'Comment=Set username' >> $START_DESKTOP3
  602. echo "Exec=mate-terminal -e \"bash -c /home/${MY_USERNAME}/mesh-desktop.sh\"" >> $START_DESKTOP3
  603. echo 'Icon=user-away' >> $START_DESKTOP3
  604. echo 'Terminal=false' >> $START_DESKTOP3
  605. echo 'Categories=Application;' >> $START_DESKTOP3
  606. chmod +x $START_DESKTOP3
  607. }
  608. function mesh_desktop_icons {
  609. if [ ! -d $rootdir/home/$MY_USERNAME/Desktop ]; then
  610. mkdir -p $rootdir/home/$MY_USERNAME/Desktop
  611. fi
  612. # Terminal
  613. #echo '[Desktop Entry]' > $rootdir/home/$MY_USERNAME/Desktop/terminal.desktop
  614. #echo 'Name=MATE Terminal' >> $rootdir/home/$MY_USERNAME/Desktop/terminal.desktop
  615. #echo 'Type=Application' >> $rootdir/home/$MY_USERNAME/Desktop/terminal.desktop
  616. #echo 'Comment=Use the command line' >> $rootdir/home/$MY_USERNAME/Desktop/terminal.desktop
  617. #echo 'TryExec=mate-terminal' >> $rootdir/home/$MY_USERNAME/Desktop/terminal.desktop
  618. #echo 'Exec=mate-terminal' >> $rootdir/home/$MY_USERNAME/Desktop/terminal.desktop
  619. #echo 'Icon=terminal' >> $rootdir/home/$MY_USERNAME/Desktop/terminal.desktop
  620. #echo 'StartupNotify=true' >> $rootdir/home/$MY_USERNAME/Desktop/terminal.desktop
  621. chroot "$rootdir" /bin/chown -R $MY_USERNAME:$MY_USERNAME /home/$MY_USERNAME/Desktop
  622. }
  623. function configure_user_interface {
  624. if [[ $VARIANT != "meshclient" && $VARIANT != "meshusb" && $VARIANT != "usb" ]]; then
  625. return
  626. fi
  627. # desktop
  628. chroot "$rootdir" apt-get -yq install mate-desktop-environment
  629. # tool to change desktop settings from command line
  630. chroot "$rootdir" apt-get -yq install dconf-cli dconf-gsettings-backend dbus dbus-x11
  631. # for tomb
  632. chroot "$rootdir" apt-get -yq install pinentry-gtk2
  633. # for tox video
  634. chroot "$rootdir" apt-get -yq install ffmpeg cheese v4l-utils
  635. # to provide notifications
  636. chroot "$rootdir" apt-get -yq install libnotify-bin
  637. # for video/audio
  638. chroot "$rootdir" apt-get -yq install libtheora-bin libvorbis-dev v4l-utils
  639. # a sane editor
  640. chroot "$rootdir" apt-get -yq install emacs24
  641. # for wifi monitoring
  642. chroot "$rootdir" apt-get -yq install horst
  643. # for sound level control
  644. chroot "$rootdir" apt-get -yq install alsa-utils
  645. # to play various media types
  646. chroot "$rootdir" apt-get -yq install vlc
  647. # android adb to allow phones to be connected and for example transfer photos/documents
  648. chroot "$rootdir" apt-get -yq install android-tools-adb
  649. # Produce a text file on the desktop listing users on the mesh
  650. cat <<EOF > $rootdir/usr/bin/list-tox-users
  651. #!/bin/bash
  652. users_list=\$(lstox | awk -F ' ' '{\$1=""; print \$0}' | sed -e 's/^[[:space:]]*//' | sort -d | uniq)
  653. if [ ! \$users_list ]; then
  654. no_of_users=0
  655. else
  656. no_of_users=\$(echo "\$users_list" | wc -l)
  657. fi
  658. if [ \$no_of_users -gt 0 ]; then
  659. echo "\$users_list" > /tmp/Users.txt
  660. chown $MY_USERNAME:$MY_USERNAME /tmp/Users.txt
  661. echo 'showing_users=\$(ps aux | grep $MESH_TEXT_EDITOR | grep "Users.txt")' > /home/$MY_USERNAME/showusers
  662. echo 'if [ \${#showing_users} -eq 0 ]; then' >> /home/$MY_USERNAME/showusers
  663. echo ' $MESH_TEXT_EDITOR /tmp/Users.txt' >> /home/$MY_USERNAME/showusers
  664. echo 'fi' >> /home/$MY_USERNAME/showusers
  665. echo 'exit 0' >> /home/$MY_USERNAME/showusers
  666. chmod +x /home/$MY_USERNAME/showusers
  667. chown $MY_USERNAME:$MY_USERNAME /home/$MY_USERNAME/showusers
  668. echo '[Desktop Entry]' > /home/$MY_USERNAME/Desktop/Users.desktop
  669. if [ \$no_of_users -lt 2 ]; then
  670. echo "Name=\$no_of_users Other User" >> /home/$MY_USERNAME/Desktop/Users.desktop
  671. else
  672. echo "Name=\$no_of_users Other Users" >> /home/$MY_USERNAME/Desktop/Users.desktop
  673. fi
  674. echo 'Type=Application' >> /home/$MY_USERNAME/Desktop/Users.desktop
  675. echo 'Comment=List of users' >> /home/$MY_USERNAME/Desktop/Users.desktop
  676. echo 'Exec=bash /home/$MY_USERNAME/showusers' >> /home/$MY_USERNAME/Desktop/Users.desktop
  677. echo 'Icon=/usr/share/$PROJECT_NAME/avatars/otheruser.png' >> /home/$MY_USERNAME/Desktop/Users.desktop
  678. echo 'StartupNotify=false' >> /home/$MY_USERNAME/Desktop/Users.desktop
  679. chmod +x /home/$MY_USERNAME/Desktop/Users.desktop
  680. chown $MY_USERNAME:$MY_USERNAME /home/$MY_USERNAME/Desktop/Users.desktop
  681. if [ -f /tmp/.ipfs-users ]; then
  682. echo '[Desktop Entry]' > /home/$MY_USERNAME/Desktop/sites.desktop
  683. echo 'Type=Application' >> /home/$MY_USERNAME/Desktop/sites.desktop
  684. echo "Name=Visit a site" >> /home/$MY_USERNAME/Desktop/sites.desktop
  685. echo 'Comment=Visit a site' >> /home/$MY_USERNAME/Desktop/sites.desktop
  686. echo 'Exec=mate-terminal -e /usr/local/bin/${PROJECT_NAME}-mesh-visit-site' >> /home/$MY_USERNAME/Desktop/sites.desktop
  687. echo 'Icon=/usr/share/${PROJECT_NAME}/avatars/ipfs.jpg' >> /home/$MY_USERNAME/Desktop/sites.desktop
  688. echo 'StartupNotify=false' >> /home/$MY_USERNAME/Desktop/sites.desktop
  689. chmod +x /home/$MY_USERNAME/Desktop/sites.desktop
  690. chown $MY_USERNAME:$MY_USERNAME /home/$MY_USERNAME/Desktop/sites.desktop
  691. echo '[Desktop Entry]' > /home/$MY_USERNAME/Desktop/blog.desktop
  692. echo 'Type=Application' >> /home/$MY_USERNAME/Desktop/blog.desktop
  693. echo "Name=Blog" >> /home/$MY_USERNAME/Desktop/blog.desktop
  694. echo 'Comment=View or create blog entries' >> /home/$MY_USERNAME/Desktop/blog.desktop
  695. echo 'Exec=mate-terminal -e /usr/local/bin/${PROJECT_NAME}-mesh-blog' >> /home/$MY_USERNAME/Desktop/blog.desktop
  696. echo 'Icon=/usr/share/${PROJECT_NAME}/avatars/blog.png' >> /home/$MY_USERNAME/Desktop/blog.desktop
  697. echo 'StartupNotify=false' >> /home/$MY_USERNAME/Desktop/blog.desktop
  698. chmod +x /home/$MY_USERNAME/Desktop/blog.desktop
  699. chown $MY_USERNAME:$MY_USERNAME /home/$MY_USERNAME/Desktop/blog.desktop
  700. fi
  701. if [ ! -f /home/$MY_USERNAME/runtox ]; then
  702. echo 'qtox_running=\$(ps aux | grep qtox | grep data)' > /home/$MY_USERNAME/runtox
  703. echo 'if [ \${#qtox_running} -eq 0 ]; then' >> /home/$MY_USERNAME/runtox
  704. echo ' bash -c "qtox -p data"' >> /home/$MY_USERNAME/runtox
  705. echo 'fi' >> /home/$MY_USERNAME/runtox
  706. echo 'exit 0' >> /home/$MY_USERNAME/runtox
  707. chmod +x /home/$MY_USERNAME/runtox
  708. chown $MY_USERNAME:$MY_USERNAME /home/$MY_USERNAME/runtox
  709. fi
  710. if [ ! -f /home/$MY_USERNAME/Desktop/tox.desktop ]; then
  711. echo '[Desktop Entry]' > /home/$MY_USERNAME/Desktop/tox.desktop
  712. echo 'Name=Chat' >> /home/$MY_USERNAME/Desktop/tox.desktop
  713. echo 'Type=Application' >> /home/$MY_USERNAME/Desktop/tox.desktop
  714. echo 'Comment=Chat, Voice and Video' >> /home/$MY_USERNAME/Desktop/tox.desktop
  715. echo 'Exec=bash /home/$MY_USERNAME/runtox' >> /home/$MY_USERNAME/Desktop/tox.desktop
  716. echo "Icon=/usr/share/$PROJECT_NAME/avatars/chat.png" >> /home/$MY_USERNAME/Desktop/tox.desktop
  717. echo 'StartupNotify=true' >> /home/$MY_USERNAME/Desktop/tox.desktop
  718. chmod +x /home/$MY_USERNAME/Desktop/tox.desktop
  719. chown $MY_USERNAME:$MY_USERNAME /home/$MY_USERNAME/Desktop/tox.desktop
  720. fi
  721. else
  722. if [ -f /tmp/Users.txt ]; then
  723. rm /tmp/Users.txt
  724. rm /home/$MY_USERNAME/Desktop/Users.desktop
  725. if [ -f /home/$MY_USERNAME/Desktop/Users.desktop ]; then
  726. rm /home/$MY_USERNAME/Desktop/Users.desktop
  727. fi
  728. if [ -f /home/$MY_USERNAME/Desktop/sites.desktop ]; then
  729. rm /home/$MY_USERNAME/Desktop/sites.desktop
  730. fi
  731. if [ -f /home/$MY_USERNAME/Desktop/blog.desktop ]; then
  732. rm /home/$MY_USERNAME/Desktop/blog.desktop
  733. fi
  734. if [ -f /home/$MY_USERNAME/Desktop/tox.desktop ]; then
  735. rm /home/$MY_USERNAME/Desktop/tox.desktop
  736. fi
  737. pkill qtox
  738. fi
  739. fi
  740. EOF
  741. chroot "$rootdir" /bin/chown $MY_USERNAME:$MY_USERNAME /usr/bin/list-tox-users
  742. chroot "$rootdir" /bin/chmod +x /usr/bin/list-tox-users
  743. echo "* * * * * $MY_USERNAME bash -c /usr/bin/list-tox-users > /dev/null" >> $rootdir/etc/crontab
  744. if [[ $VARIANT != "usb" ]]; then
  745. # log in automatically
  746. chroot "$rootdir" apt-get -y install nodm xinit
  747. echo 'NODM_ENABLED=true' > /etc/default/nodm
  748. echo "NODM_USER=$MY_USERNAME" >> /etc/default/nodm
  749. chroot "$rootdir" mkdir /etc/systemd/system/getty@tty1.service.d
  750. echo '[Service]' > $rootdir/etc/systemd/system/getty@tty1.service.d/override.conf
  751. echo 'ExecStart=' >> $rootdir/etc/systemd/system/getty@tty1.service.d/override.conf
  752. echo 'ExecStart=-/sbin/agetty --autologin fbone --noclear %I $TERM' >> $rootdir/etc/systemd/system/getty@tty1.service.d/override.conf
  753. echo '[[ -z $DISPLAY && $XDG_VTNR -eq 1 ]] && exec startx' >> $rootdir/home/$MY_USERNAME/.profile
  754. chroot "$rootdir" systemctl set-default multi-user.target
  755. mesh_client_startup_applications
  756. mesh_desktop_icons
  757. # Different desktop background for amnesic
  758. if [[ $AMNESIC != 'no' ]]; then
  759. MESH_DESKTOP_BACKGROUND_IMAGE=/usr/local/share/${PROJECT_NAME}_mesh_amnesic_background.png
  760. fi
  761. # change the desktop background
  762. if [ $MESH_DESKTOP_BACKGROUND_IMAGE ]; then
  763. if [ -f $MESH_DESKTOP_BACKGROUND_IMAGE ]; then
  764. if [ -d $rootdir/usr/share/images/desktop-base ]; then
  765. cp $MESH_DESKTOP_BACKGROUND_IMAGE $rootdir/usr/share/images/desktop-base/${PROJECT_NAME}_mesh_background.png
  766. chroot "$rootdir" /bin/rm /usr/share/images/desktop-base/desktop-background
  767. chroot "$rootdir" ln -s /usr/share/images/desktop-base/${PROJECT_NAME}_mesh_background.png /usr/share/images/desktop-base/desktop-background
  768. fi
  769. fi
  770. fi
  771. else
  772. chroot "$rootdir" apt-get -yq install lightdm
  773. fi
  774. # browser
  775. chroot "$rootdir" apt-get -yq install $BROWSER
  776. # help
  777. mkdir -p $rootdir/home/${MY_USERNAME}/help/images
  778. cd $rootdir/root/${PROJECT_NAME}/website
  779. ./deploy.sh EN $rootdir/home/${MY_USERNAME}/help
  780. chroot "$rootdir" /bin/chown -R ${MY_USERNAME}:${MY_USERNAME} /home/${MY_USERNAME}/help
  781. # Tox user interface
  782. enable_tox_repo
  783. mesh_tox_qtox
  784. # copy the default qtox ini file
  785. if [ ! -d ${rootdir}/home/${MY_USERNAME}/.config/tox ]; then
  786. mkdir ${rootdir}/home/${MY_USERNAME}/.config/tox
  787. cp /usr/local/bin/${PROJECT_NAME}-config-qtox ${rootdir}/home/${MY_USERNAME}/.config/tox/qtox.ini
  788. chroot "$rootdir" /bin/chown -R ${MY_USERNAME}:${MY_USERNAME} /home/${MY_USERNAME}/.config
  789. fi
  790. if [[ $VARIANT == "usb" ]]; then
  791. # tor
  792. chroot "$rootdir" apt-get -y install tor
  793. # xmpp client
  794. chroot "$rootdir" echo "deb ftp://ftp.gajim.org/debian unstable main" > /etc/apt/sources.list.d/gajim.list
  795. chroot "$rootdir" apt-get update
  796. chroot "$rootdir" apt-get -yq install gajim-dev-keyring
  797. chroot "$rootdir" apt-get -yq install git python-dev python-pip gajim-nightly
  798. chroot "$rootdir" mkdir /home/$GENERIC_IMAGE_USERNAME/.local/share/gajim/plugins -p
  799. chroot "$rootdir" git clone https://github.com/omemo/gajim-omemo /home/$GENERIC_IMAGE_USERNAME/.local/share/gajim/plugins/gajim-omemo
  800. chroot "$rootdir" pip install protobuf==2.6.1, python-axolotl==0.1.35
  801. chroot "$rootdir" /bin/chown -R $GENERIC_IMAGE_USERNAME:$GENERIC_IMAGE_USERNAME /home/$GENERIC_IMAGE_USERNAME/.local
  802. # IRC client
  803. chroot "$rootdir" apt-get -yq install hexchat profanity
  804. fi
  805. }
  806. ##############################################################################
  807. # Set to true/false to control if eatmydata is used during build
  808. use_eatmydata=true
  809. rootdir="$1"
  810. fmdir="$(pwd)"
  811. image="$fmdir"/"$2"
  812. cd "$rootdir"
  813. echo info: building $MACHINE for $ARCHITECTURE
  814. export DEBIAN_FRONTEND=noninteractive DEBCONF_NONINTERACTIVE_SEEN=true
  815. export LC_ALL=C LANGUAGE=C LANG=C
  816. # Override libpam-tmpdir setting during build, as the directories
  817. # are not created yet.
  818. export TMP=/tmp/ TMPDIR=/tmp/
  819. if [ ! $MY_USERNAME ]; then
  820. echo $'No username was specified'
  821. exit 52825
  822. fi
  823. username=$MY_USERNAME
  824. echo $"warning: creating initial user $username with well known password!"
  825. password=$MY_PASSWORD
  826. chroot "$rootdir" /usr/bin/env -i \
  827. HOME=/root \
  828. PATH=/usr/local/bin:/usr/local/sbin:/usr/bin:/usr/sbin:/bin:/sbin
  829. echo "export PATH=/usr/local/bin:/usr/local/sbin:/usr/bin:/usr/sbin:/bin:/sbin:" >> $rootdir/root/.bashrc
  830. chroot "$rootdir" adduser --gecos $username --disabled-password $username
  831. echo $username:$password | chroot "$rootdir" /usr/sbin/chpasswd
  832. chroot "$rootdir" adduser $username sudo
  833. if [ ! $DEBIAN_REPO ]; then
  834. DEBIAN_REPO='ftp.de.debian.org'
  835. fi
  836. if [ ! $DEBIAN_VERSION ]; then
  837. DEBIAN_VERSION='jessie'
  838. fi
  839. set_apt_sources $BUILD_MIRROR
  840. chroot "$rootdir" apt-get clean
  841. chroot "$rootdir" /bin/rm -rf /var/lib/apt/lists/*
  842. chroot "$rootdir" apt-get clean
  843. set_apt_sources $MIRROR
  844. configure_backports
  845. configure_contrib_repo
  846. chroot "$rootdir" apt-get update
  847. chroot "$rootdir" apt-get install -y apt-utils
  848. cat > $rootdir/usr/sbin/policy-rc.d <<EOF
  849. #!/bin/sh
  850. exit 101
  851. EOF
  852. chmod a+rx $rootdir/usr/sbin/policy-rc.d
  853. if $use_eatmydata ; then
  854. enable_eatmydata_override
  855. fi
  856. if [ -n "$CUSTOM_SETUP" ]; then
  857. cp "$CUSTOM_SETUP" "$rootdir"/tmp
  858. chroot "$rootdir" apt-get install -y gdebi-core
  859. chroot "$rootdir" gdebi -n /tmp/"$(basename $CUSTOM_SETUP)"
  860. fi
  861. if [[ $VARIANT != "meshclient" && $VARIANT != "meshusb" && $VARIANT != "mesh" ]]; then
  862. chroot "$rootdir" apt-get install -y openssh-server
  863. fi
  864. chroot "$rootdir" apt-get install -y sudo git dialog build-essential
  865. chroot "$rootdir" apt-get install -y avahi-daemon avahi-utils avahi-discover avahi-autoipd
  866. chroot "$rootdir" apt-get install -y iptables dnsutils net-tools network-manager iputils-ping
  867. chroot "$rootdir" apt-get install -y libnss-mdns libnss-myhostname libnss-gw-name nano man ntp
  868. chroot "$rootdir" apt-get install -y locales locales-all debconf wireless-tools wpasupplicant usbutils
  869. if [[ $ARCHITECTURE == 'qemu'* || $ARCHITECTURE == 'i386' || $ARCHITECTURE == 'i686' || $ARCHITECTURE == 'amd64' || $ARCHITECTURE == 'x86_64' ]]; then
  870. chroot "$rootdir" apt-get install -y cryptsetup zsh pinentry-curses iotop bc
  871. chroot "$rootdir" apt-get install -y grub2 hostapd
  872. fi
  873. sed -i "s|#host-name=.*|host-name=${PROJECT_NAME}|g" $rootdir/etc/avahi/avahi-daemon.conf
  874. sed -i "s|host-name=.*|host-name=${PROJECT_NAME}|g" $rootdir/etc/avahi/avahi-daemon.conf
  875. chroot "$rootdir" /bin/bash -x <<EOF
  876. git clone $PROJECT_REPO /root/$PROJECT_NAME
  877. cd /root/$PROJECT_NAME
  878. make install
  879. EOF
  880. chroot "$rootdir" ${PROJECT_NAME}-image-hardware-setup 2>&1 | \
  881. tee $rootdir/var/log/${PROJECT_NAME}-image-hardware-setup.log
  882. rm $rootdir/usr/sbin/policy-rc.d
  883. # Set up HRNG for systems known to have one
  884. # Otherwise install haveged
  885. if [[ "$MACHINE" != "beaglebone" ]]; then
  886. chroot $rootdir apt-get -yq install haveged
  887. else
  888. chroot $rootdir apt-get -yq install rng-tools
  889. sed -i 's|#HRNGDEVICE=/dev/hwrng|HRNGDEVICE=/dev/hwrng|g' $rootdir/etc/default/rng-tools
  890. fi
  891. # copy u-boot to beginning of image
  892. case "$MACHINE" in
  893. beaglebone)
  894. dd if=$rootdir/usr/lib/u-boot/am335x_boneblack/MLO of="$image" \
  895. count=1 seek=1 conv=notrunc bs=128k
  896. dd if=$rootdir/usr/lib/u-boot/am335x_boneblack/u-boot.img of="$image" \
  897. count=2 seek=1 conv=notrunc bs=384k
  898. ;;
  899. cubieboard2)
  900. dd if=$rootdir/usr/lib/u-boot/Cubieboard2/u-boot-sunxi-with-spl.bin of="$image" \
  901. seek=8 conv=notrunc bs=1k
  902. ;;
  903. a20-olinuxino-lime)
  904. dd if=$rootdir/usr/lib/u-boot/A20-OLinuXino-Lime/u-boot-sunxi-with-spl.bin \
  905. of="$image" seek=8 conv=notrunc bs=1k
  906. ;;
  907. esac
  908. if $use_eatmydata ; then
  909. disable_eatmydata_override
  910. fi
  911. configure_ssh
  912. configure_networking
  913. admin_user_sudo
  914. create_generic_image
  915. atheros_wifi
  916. continue_installation
  917. initialise_mesh
  918. configure_wifi
  919. configure_user_interface
  920. # remove downloaded packages
  921. chroot $rootdir apt-get clean
  922. cd /
  923. echo $"info: killing leftover processes in chroot"
  924. fuser -mvk $rootdir/. || true
  925. exit 0