freedombone-image-customise 62KB

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