freedombone-image-customise 29KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854
  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_background.png
  77. # The browser application to use
  78. BROWSER=iceweasel
  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. enable_eatmydata_override() {
  84. chroot $rootdir apt-get install --no-install-recommends -y eatmydata
  85. if [ -x $rootdir/usr/bin/eatmydata ] && \
  86. [ ! -f $rootdir/etc/apt/apt.conf.d/95debian-edu-install-dpkg-eatmydata ]; then
  87. echo $"info: Adding apt config to call dpkg via eatmydata"
  88. printf "#!/bin/sh\nexec eatmydata dpkg \"\$@\"\n" \
  89. > $rootdir/var/tmp/dpkg-eatmydata
  90. chmod 755 $rootdir/var/tmp/dpkg-eatmydata
  91. cat > $rootdir/etc/apt/apt.conf.d/95debian-edu-install-dpkg-eatmydata <<EOF
  92. Dir::Bin::dpkg "/var/tmp/dpkg-eatmydata";
  93. EOF
  94. else
  95. echo $"error: unable to find /usr/bin/eatmydata after installing the eatmydata package"
  96. fi
  97. }
  98. disable_eatmydata_override() {
  99. for override in \
  100. /etc/apt/apt.conf.d/95debian-edu-install-dpkg-eatmydata \
  101. /var/tmp/dpkg-eatmydata ; do
  102. echo $"info: Removing apt config to call dpkg via eatmydata"
  103. if [ -f $rootdir$override ] ; then
  104. rm -f $rootdir$override
  105. else
  106. echo $"warning: missing $rootdir$override"
  107. fi
  108. done
  109. sync # Flush file buffers before continuing
  110. }
  111. set_apt_sources() {
  112. NEW_MIRROR="$1"
  113. COMPONENTS="main"
  114. cat <<EOF > etc/apt/sources.list
  115. deb $NEW_MIRROR $SUITE $COMPONENTS
  116. deb-src $NEW_MIRROR $SUITE $COMPONENTS
  117. #deb http://security.debian.org/ $SUITE/updates main
  118. #deb-src http://security.debian.org/ $SUITE/updates main
  119. EOF
  120. }
  121. configure_networking() {
  122. if [[ $DEBIAN_INSTALL_ONLY != "no" ]]; then
  123. return
  124. fi
  125. if [[ $GENERIC_IMAGE == "no" ]]; then
  126. echo "# This file describes the network interfaces available on your system
  127. # and how to activate them. For more information, see interfaces(5).
  128. # The loopback network interface
  129. auto lo
  130. iface lo inet loopback
  131. # The primary network interface
  132. auto eth0
  133. iface eth0 inet static
  134. address $BOX_IP_ADDRESS
  135. netmask 255.255.255.0
  136. gateway $ROUTER_IP_ADDRESS
  137. dns-nameservers $NAMESERVER1 $NAMESERVER2
  138. # Example to keep MAC address between reboots
  139. #hwaddress ether B5:A2:BE:3F:1A:FE
  140. # The secondary network interface
  141. #auto eth1
  142. #iface eth1 inet dhcp
  143. # WiFi Example
  144. #auto wlan0
  145. #iface wlan0 inet dhcp
  146. # wpa-ssid \"essid\"
  147. # wpa-psk \"password\"
  148. # Ethernet/RNDIS gadget (g_ether)
  149. # ... or on host side, usbnet and random hwaddr
  150. # Note on some boards, usb0 is automaticly setup with an init script
  151. #iface usb0 inet static
  152. # address 192.168.7.2
  153. # netmask 255.255.255.0
  154. # network 192.168.7.0
  155. # gateway 192.168.7.1" > $rootdir/etc/network/interfaces
  156. hexarray=( 1 2 3 4 5 6 7 8 9 0 a b c d e f )
  157. a=${hexarray[$RANDOM%16]}${hexarray[$RANDOM%16]}
  158. b=${hexarray[$RANDOM%16]}${hexarray[$RANDOM%16]}
  159. c=${hexarray[$RANDOM%16]}${hexarray[$RANDOM%16]}
  160. d=${hexarray[$RANDOM%16]}${hexarray[$RANDOM%16]}
  161. e=${hexarray[$RANDOM%16]}${hexarray[$RANDOM%16]}
  162. sed -i "s|#hwaddress ether.*|hwaddress ether de:$a:$b:$c:$d:$e|g" \
  163. $rootdir/etc/network/interfaces
  164. fi
  165. sed -i "s/nameserver.*/nameserver $NAMESERVER1/g" $rootdir/etc/resolv.conf
  166. sed -i "/nameserver $NAMESERVER1/a\nameserver $NAMESERVER2" $rootdir/etc/resolv.conf
  167. if [[ $VARIANT != "meshclient" && $VARIANT != "meshusb" ]]; then
  168. # change the motd to show further install instructions
  169. echo $"
  170. .---. . .
  171. | | |
  172. |--- .--. .-. .-. .-.| .-. .--.--. |.-. .-. .--. .-.
  173. | | (.-' (.-' ( | ( )| | | | )( )| | (.-'
  174. ' ' --' --' -' - -' ' ' -' -' -' ' - --'
  175. Initial base install
  176. Your system is not yet installed. To complete the process run the
  177. following commands, then enter your details.
  178. sudo su
  179. ${PROJECT_NAME} menuconfig
  180. " > $rootdir/etc/motd
  181. else
  182. echo $"
  183. .---. . .
  184. | | |
  185. |--- .--. .-. .-. .-.| .-. .--.--. |.-. .-. .--. .-.
  186. | | (.-' (.-' ( | ( )| | | | )( )| | (.-'
  187. ' ' --' --' -' - -' ' ' -' -' -' ' - --'
  188. Freedom in the Mesh
  189. " > $rootdir/etc/motd
  190. fi
  191. }
  192. configure_ssh() {
  193. sed -i "s/Port .*/Port ${SSH_PORT}/g" $rootdir/etc/ssh/sshd_config
  194. if [[ "$SSH_PUBKEY" != "no" ]]; then
  195. if [ ! -d $rootdir/home/$MY_USERNAME/.ssh ]; then
  196. mkdir $rootdir/home/$MY_USERNAME/.ssh
  197. fi
  198. echo "$SSH_PUBKEY" > $rootdir/home/$MY_USERNAME/.ssh/authorized_keys
  199. chroot $rootdir chown -R $MY_USERNAME:$MY_USERNAME /home/$MY_USERNAME/.ssh
  200. sed -i 's|PasswordAuthentication.*|PasswordAuthentication no|g' $rootdir/etc/ssh/sshd_config
  201. echo $"Using ssh public key:"
  202. echo $SSH_PUBKEY
  203. echo $'Password ssh authentication turned off'
  204. fi
  205. }
  206. admin_user_sudo() {
  207. echo "$MY_USERNAME ALL=(ALL) ALL" >> $rootdir/etc/sudoers
  208. }
  209. create_generic_image() {
  210. if [[ $DEBIAN_INSTALL_ONLY != "no" ]]; then
  211. return
  212. fi
  213. if [[ $GENERIC_IMAGE == "no" ]]; then
  214. return
  215. fi
  216. if [ $CONFIG_FILENAME ]; then
  217. if [[ "$CONFIG_FILENAME" == *"mesh.cfg"* ]]; then
  218. VARIANT="mesh"
  219. fi
  220. fi
  221. # Don't install any configuration. This will be a base system
  222. if [[ $VARIANT != "mesh" && $VARIANT != "meshclient" && $VARIANT != "meshusb" ]]; then
  223. CONFIG_FILENAME=
  224. else
  225. touch $rootdir/root/.initial_mesh_setup
  226. fi
  227. # Stick with the existing login for mesh clients
  228. if [[ $VARIANT == "meshclient" || $VARIANT == "meshusb" ]]; then
  229. return
  230. fi
  231. # The presence of this file indicates that the initial
  232. # setup has not yet been completed
  233. touch $rootdir/home/$MY_USERNAME/.initial_setup
  234. chroot $rootdir chown $MY_USERNAME:$MY_USERNAME /home/$MY_USERNAME/.initial_setup
  235. touch $rootdir/root/.initial_setup
  236. cat >> $rootdir/home/$MY_USERNAME/.bashrc <<EOF
  237. # initial setup of the system
  238. if [ -f ~/.initial_setup ]; then
  239. clear
  240. echo "
  241. .---. . .
  242. | | |
  243. |--- .--. .-. .-. .-.| .-. .--.--. |.-. .-. .--. .-.
  244. | | (.-' (.-' ( | ( )| | | | )( )| | (.-'
  245. ' ' --' --' -' - -' ' ' -' -' -' ' - --'
  246. Initial setup process
  247. Please enter your password a second time.
  248. "
  249. sudo su
  250. fi
  251. EOF
  252. echo '# initial setup of the system' >> $rootdir/root/.bashrc
  253. echo 'if [ -f ~/.initial_setup ]; then' >> $rootdir/root/.bashrc
  254. echo ' if [ -f ~/login.txt ]; then' >> $rootdir/root/.bashrc
  255. echo ' NEW_USER_PASSWORD=$(printf `cat ~/login.txt`)' >> $rootdir/root/.bashrc
  256. echo ' else' >> $rootdir/root/.bashrc
  257. echo ' ENTROPY=$(cat /proc/sys/kernel/random/entropy_avail)' >> $rootdir/root/.bashrc
  258. echo ' if [ $ENTROPY -lt 500 ]; then' >> $rootdir/root/.bashrc
  259. ENTROPY_MESSAGE1=$'Initial setup process'
  260. ENTROPY_MESSAGE2=$'Password Generation'
  261. ENTROPY_MESSAGE3=$'WARNING: The entropy available on this system is too low to generate a password.\n\nThe installation process cannot continue.'
  262. echo " dialog --backtitle \"${ENTROPY_MESSAGE1}\" --title \"${ENTROPY_MESSAGE2}\" --msgbox \"${ENTROPY_MESSAGE3}\" 8 50" >> $rootdir/root/.bashrc
  263. echo ' exit' >> $rootdir/root/.bashrc
  264. echo ' fi' >> $rootdir/root/.bashrc
  265. echo -n ' NEW_USER_PASSWORD="$(openssl rand -base64 30 | cut -c1-' >> $rootdir/root/.bashrc
  266. echo "${MINIMUM_PASSWORD_LENGTH})\"" >> $rootdir/root/.bashrc
  267. echo ' fi' >> $rootdir/root/.bashrc
  268. echo ' echo "${NEW_USER_PASSWORD}" > ~/login.txt' >> $rootdir/root/.bashrc
  269. echo ' clear' >> $rootdir/root/.bashrc
  270. echo ' echo ""' >> $rootdir/root/.bashrc
  271. NEW_LOGIN_PASSWORD_MESSAGE1=$'Your new login password is:'
  272. NEW_LOGIN_PASSWORD_MESSAGE2=$'Use it whenever you wish to ssh into this system.'
  273. NEW_LOGIN_PASSWORD_MESSAGE3=$'IMPORTANT: Please take a moment to enter the above password into a\npassword manager or write it down somewhere.'
  274. PRESS_KEY_MESSAGE=$'Press any key to continue...'
  275. echo " echo \"${NEW_LOGIN_PASSWORD_MESSAGE1}\"" >> $rootdir/root/.bashrc
  276. echo ' echo ""' >> $rootdir/root/.bashrc
  277. echo ' toilet "${NEW_USER_PASSWORD}"' >> $rootdir/root/.bashrc
  278. echo ' echo ""' >> $rootdir/root/.bashrc
  279. echo ' echo " ${NEW_USER_PASSWORD}"' >> $rootdir/root/.bashrc
  280. echo ' echo ""' >> $rootdir/root/.bashrc
  281. echo " echo \"${NEW_LOGIN_PASSWORD_MESSAGE2}\"" >> $rootdir/root/.bashrc
  282. echo ' echo ""' >> $rootdir/root/.bashrc
  283. echo " echo \"${NEW_LOGIN_PASSWORD_MESSAGE3}\"" >> $rootdir/root/.bashrc
  284. echo ' echo ""' >> $rootdir/root/.bashrc
  285. echo " read -n1 -r -p \"${PRESS_KEY_MESSAGE}\" key" >> $rootdir/root/.bashrc
  286. # change the password for the admin user
  287. echo -n " echo \"${MY_USERNAME}:" >> $rootdir/root/.bashrc
  288. echo '$(printf `cat ~/login.txt`)"|chpasswd' >> $rootdir/root/.bashrc
  289. # update before continuing
  290. echo " cd /root/${PROJECT_NAME}" >> $rootdir/root/.bashrc
  291. echo " git stash" >> $rootdir/root/.bashrc
  292. echo " git pull" >> $rootdir/root/.bashrc
  293. echo " make install" >> $rootdir/root/.bashrc
  294. if [[ $VARIANT != "mesh" && $VARIANT != "meshclient" && $VARIANT != "meshusb" && $VARIANT != "usb" ]]; then
  295. if [[ $ONION_ONLY == "no" ]]; then
  296. if [[ $MINIMAL_INSTALL == "no" ]]; then
  297. echo " ${PROJECT_NAME} menuconfig-full" >> $rootdir/root/.bashrc
  298. else
  299. echo " ${PROJECT_NAME} menuconfig" >> $rootdir/root/.bashrc
  300. fi
  301. else
  302. echo " ${PROJECT_NAME} menuconfig-onion" >> $rootdir/root/.bashrc
  303. fi
  304. else
  305. echo " echo ''" >> $rootdir/root/.bashrc
  306. fi
  307. echo ' if [ "$?" = "0" ]; then' >> $rootdir/root/.bashrc
  308. echo " if [ -f ~/${PROJECT_NAME}-completed.txt ]; then" >> $rootdir/root/.bashrc
  309. # Remove the initial setup files
  310. echo ' rm /root/.initial_setup' >> $rootdir/root/.bashrc
  311. echo " rm /home/${MY_USERNAME}/.initial_setup" >> $rootdir/root/.bashrc
  312. echo " touch /root/.remove_${GENERIC_IMAGE_USERNAME}" >> $rootdir/root/.bashrc
  313. echo ' shred -zu ~/login.txt' >> $rootdir/root/.bashrc
  314. END_MESSAGE1=$'Congratulations!'
  315. if [[ $VARIANT != "mesh" && $VARIANT != "meshclient" && $VARIANT != "meshusb" && $VARIANT != "usb" ]]; then
  316. END_MESSAGE2=$'\nYour system has now installed\n\nThe onion ssh service is at $SSH_ONION_HOSTNAME\n\nPress any key to reboot and begin using it'
  317. echo ' SSH_ONION_HOSTNAME=$(cat /var/lib/tor/hidden_service_ssh/hostname)' >> $rootdir/root/.bashrc
  318. else
  319. END_MESSAGE2=$'\nYour system has now installed\n\nPress any key to reboot and begin using it'
  320. fi
  321. echo " dialog --title '$END_MESSAGE1' --msgbox \"$END_MESSAGE2\" 9 50" >> $rootdir/root/.bashrc
  322. echo ' reboot' >> $rootdir/root/.bashrc
  323. echo ' fi' >> $rootdir/root/.bashrc
  324. echo ' else' >> $rootdir/root/.bashrc
  325. echo ' key=' >> $rootdir/root/.bashrc
  326. echo ' while [[ $key != "x" ]]; do' >> $rootdir/root/.bashrc
  327. INSTALL_FAIL_MESSAGE=$"Install failed. Press x to continue..."
  328. echo " read -n1 -r -p \"${INSTALL_FAIL_MESSAGE}\" key" >> $rootdir/root/.bashrc
  329. echo ' done' >> $rootdir/root/.bashrc
  330. echo ' fi' >> $rootdir/root/.bashrc
  331. echo ' exit' >> $rootdir/root/.bashrc
  332. echo 'else' >> $rootdir/root/.bashrc
  333. echo ' # Remove default account after install' >> $rootdir/root/.bashrc
  334. echo " if [ -f /root/.remove_${GENERIC_IMAGE_USERNAME} ]; then" >> $rootdir/root/.bashrc
  335. echo " if [ -d /home/${GENERIC_IMAGE_USERNAME} ]; then" >> $rootdir/root/.bashrc
  336. echo " userdel -r ${GENERIC_IMAGE_USERNAME}" >> $rootdir/root/.bashrc
  337. echo " if [ -d /home/${GENERIC_IMAGE_USERNAME} ]; then" >> $rootdir/root/.bashrc
  338. echo " rm -rf /home/${GENERIC_IMAGE_USERNAME}" >> $rootdir/root/.bashrc
  339. echo " rm /root/.remove_${GENERIC_IMAGE_USERNAME}" >> $rootdir/root/.bashrc
  340. echo ' fi' >> $rootdir/root/.bashrc
  341. echo ' fi' >> $rootdir/root/.bashrc
  342. echo ' fi' >> $rootdir/root/.bashrc
  343. echo 'fi' >> $rootdir/root/.bashrc
  344. }
  345. continue_installation() {
  346. # If a configuration file exists then run with it
  347. # otherwise the interactive installer can be used
  348. # This is equivalent to installing freedombox-setup on freedombox
  349. if [ $CONFIG_FILENAME ]; then
  350. if [ ${#CONFIG_FILENAME} -gt 2 ]; then
  351. cp $CONFIG_FILENAME $rootdir/root/$PROJECT_NAME.cfg
  352. cat $rootdir/root/$PROJECT_NAME.cfg
  353. chroot "$rootdir" su -c "$PROJECT_NAME -c /root/$PROJECT_NAME.cfg" - root
  354. fi
  355. fi
  356. }
  357. atheros_wifi() {
  358. firmware_filename="open-ath9k-htc-firmware_1.3-1_all.deb"
  359. firmware_hash='5fea58ffefdf0ef15b504db7fbe3bc078c03e0d927bba64085e4b6f2546102f5'
  360. firmware_url="http://us.archive.trisquel.info/trisquel/pool/main/o/open-ath9k-htc-firmware/$firmware_filename"
  361. firmware_tempfile="/tmp/$firmware_filename"
  362. wget "$firmware_url" -O "$rootdir$firmware_tempfile"
  363. downloaded_firmware_hash=$(sha256sum "$rootdir$firmware_tempfile" | awk -F ' ' '{print $1}')
  364. if [[ "$downloaded_firmware_hash" == "$firmware_hash" ]]; then
  365. chroot "$rootdir" dpkg -i "$firmware_tempfile"
  366. else
  367. echo 'WARNING: Atheros Wifi firmware hash does not match. The driver has not been installed.'
  368. fi
  369. }
  370. configure_wifi() {
  371. if [[ $VARIANT == "mesh" || $VARIANT == "meshclient" || $VARIANT == "meshusb" ]]; then
  372. return
  373. fi
  374. if [ -f $WIFI_NETWORKS_FILE ]; then
  375. chroot "$rootdir" ${PROJECT_NAME}-wifi -i $WIFI_INTERFACE --networks $WIFI_NETWORKS_FILE
  376. return
  377. fi
  378. if [[ $WIFI_TYPE != 'none' ]]; then
  379. if [ ${#WIFI_PASSPHRASE} -lt 2 ]; then
  380. return
  381. fi
  382. chroot "$rootdir" ${PROJECT_NAME}-wifi -i $WIFI_INTERFACE -s $WIFI_SSID -t $WIFI_TYPE -p $WIFI_PASSPHRASE --hotspot $WIFI_HOTSPOT
  383. else
  384. chroot "$rootdir" ${PROJECT_NAME}-wifi -i $WIFI_INTERFACE -s $WIFI_SSID -t $WIFI_TYPE --hotspot $WIFI_HOTSPOT
  385. fi
  386. }
  387. ##############################################################################
  388. # Mesh networking
  389. ##############################################################################
  390. # for mesh installs
  391. TRACKER_PORT=6969
  392. WIFI_CHANNEL=2
  393. # B.A.T.M.A.N settings
  394. BATMAN_CELLID='02:BA:00:00:03:01'
  395. WIFI_SSID='mesh'
  396. # To avoid confusions these are obtained from the main project file
  397. TOXID_REPO=
  398. TOX_PORT=
  399. TOXCORE_REPO=
  400. TOXIC_REPO=
  401. TOXCORE_COMMIT=
  402. TOXIC_COMMIT=
  403. # These are some default nodes, but you can replace them with trusted nodes
  404. # as you prefer. See https://wiki.tox.im/Nodes
  405. TOX_NODES=
  406. #TOX_NODES=(
  407. # '192.254.75.102,2607:5600:284::2,33445,951C88B7E75C867418ACDB5D273821372BB5BD652740BCDF623A4FA293E75D2F,Tox RELENG,US'
  408. # '144.76.60.215,2a01:4f8:191:64d6::1,33445,04119E835DF3E78BACF0F84235B300546AF8B936F035185E2A8E9E0A67C8924F,sonOfRa,DE'
  409. #)
  410. # To avoid confusions these are obtained from the main project file
  411. ZERONET_REPO=
  412. ZERONET_COMMIT=
  413. ZERONET_PORT=
  414. ZERONET_BLOG_REPO=
  415. ZERONET_BLOG_COMMIT=
  416. ZERONET_MAIL_REPO=
  417. ZERONET_MAIL_COMMIT=
  418. ZERONET_FORUM_REPO=
  419. ZERONET_FORUM_COMMIT=
  420. ZERONET_ID_REPO=
  421. ZERONET_ID_COMMIT=
  422. # Directory where source code is downloaded and compiled
  423. INSTALL_DIR=$HOME/build
  424. INSTALLING_MESH=
  425. initialise_mesh() {
  426. if [[ $VARIANT != "mesh" && $VARIANT != "meshclient" && $VARIANT != "meshusb" ]]; then
  427. return
  428. fi
  429. if [[ $DEBIAN_INSTALL_ONLY != "no" ]]; then
  430. return
  431. fi
  432. if [[ $INSECURE == $'yes' ]]; then
  433. echo '*********************************************************'
  434. echo $'WARNING: non-free wifi drivers are being installed.'
  435. echo $' This may compromise the security of your system.'
  436. echo '*********************************************************'
  437. # enable non-free repo
  438. if ! grep -q "non-free" $rootdir/etc/apt/sources.list; then
  439. chroot "$rootdir" sed -i "s| main| main non-free|g" /etc/apt/sources.list
  440. fi
  441. # enable contrib repo
  442. if ! grep -q "contrib" $rootdir/etc/apt/sources.list; then
  443. chroot "$rootdir" sed -i "s| main| main contrib|g" /etc/apt/sources.list
  444. fi
  445. chroot "$rootdir" apt-get update
  446. # install proprietary wifi drivers
  447. # see https://wiki.debian.org/iwlwifi
  448. chroot "$rootdir" apt-get -y install firmware-iwlwifi firmware-b43-installer firmware-brcm80211
  449. fi
  450. INSTALLING_MESH=1
  451. configure_firewall
  452. install_avahi
  453. install_batman
  454. install_tomb
  455. install_tox
  456. install_web_server
  457. install_zeronet
  458. MESH_SERVICE='mesh-setup.service'
  459. MESH_SETUP_DAEMON=$rootdir/etc/systemd/system/$MESH_SERVICE
  460. MESH_STARTUP_PARAMS="${MY_USERNAME}"
  461. if [[ $AMNESIC != 'no' ]]; then
  462. MESH_STARTUP_PARAMS="${MY_USERNAME} amnesic"
  463. fi
  464. echo '[Unit]' > $MESH_SETUP_DAEMON
  465. echo 'Description=Initial mesh router configuration' >> $MESH_SETUP_DAEMON
  466. echo 'After=syslog.target' >> $MESH_SETUP_DAEMON
  467. echo 'After=network.target' >> $MESH_SETUP_DAEMON
  468. echo '[Service]' >> $MESH_SETUP_DAEMON
  469. echo 'Type=simple' >> $MESH_SETUP_DAEMON
  470. echo 'User=root' >> $MESH_SETUP_DAEMON
  471. echo 'Group=root' >> $MESH_SETUP_DAEMON
  472. echo 'WorkingDirectory=/root' >> $MESH_SETUP_DAEMON
  473. echo "ExecStart=/usr/local/bin/${PROJECT_NAME}-image-mesh ${MESH_STARTUP_PARAMS} > /var/log/mesh-setup.log" >> $MESH_SETUP_DAEMON
  474. echo '' >> $MESH_SETUP_DAEMON
  475. echo 'TimeoutSec=99999' >> $MESH_SETUP_DAEMON
  476. echo '' >> $MESH_SETUP_DAEMON
  477. echo '[Install]' >> $MESH_SETUP_DAEMON
  478. echo 'WantedBy=multi-user.target' >> $MESH_SETUP_DAEMON
  479. chroot "$rootdir" systemctl enable $MESH_SERVICE
  480. }
  481. # User interface for USB drive installs ######################################
  482. function mesh_client_startup_applications {
  483. if [ ! -d $rootdir/home/$MY_USERNAME/Desktop ]; then
  484. mkdir -p $rootdir/home/$MY_USERNAME/Desktop
  485. fi
  486. if [ ! -d $rootdir/home/$MY_USERNAME/.config/autostart ]; then
  487. mkdir -p $rootdir/home/$MY_USERNAME/.config/autostart
  488. chroot "$rootdir" chown -R $MY_USERNAME:$MY_USERNAME /home/$MY_USERNAME/.config
  489. fi
  490. START_DESKTOP=$rootdir/home/$MY_USERNAME/mesh-desktop.sh
  491. echo '#!/bin/bash' > $START_DESKTOP
  492. echo 'dconf write /org/mate/caja/desktop/volumes-visible false' >> $START_DESKTOP
  493. echo 'dconf write /org/mate/caja/desktop/computer-icon-visible false' >> $START_DESKTOP
  494. echo 'dconf write /org/mate/caja/desktop/home-icon-visible false' >> $START_DESKTOP
  495. echo 'dconf write /org/mate/caja/desktop/network-icon-visible false' >> $START_DESKTOP
  496. echo 'dconf write /org/mate/caja/desktop/trash-icon-visible false' >> $START_DESKTOP
  497. echo 'dconf write /org/mate/caja/desktop/volumes-visible false' >> $START_DESKTOP
  498. echo 'dconf write /org/mate/desktop/media-handling/automount-open false' >> $START_DESKTOP
  499. echo 'dconf write /org/mate/desktop/screensaver/lock-enabled false' >> $START_DESKTOP
  500. chmod +x $START_DESKTOP
  501. START_DESKTOP2=$rootdir/home/$MY_USERNAME/.config/autostart/mesh-start.desktop
  502. echo '[Desktop Entry]' > $START_DESKTOP2
  503. echo 'Type=Application' >> $START_DESKTOP2
  504. echo 'Name=Mesh start desktop script' >> $START_DESKTOP2
  505. echo "Exec=bash -c '~/mesh-desktop.sh'" >> $START_DESKTOP2
  506. echo 'X-GNOME-Autostart-enabled=true' >> $START_DESKTOP2
  507. chmod +x $START_DESKTOP2
  508. }
  509. function mesh_desktop_icons {
  510. if [ ! -d $rootdir/home/$MY_USERNAME/Desktop ]; then
  511. mkdir -p $rootdir/home/$MY_USERNAME/Desktop
  512. fi
  513. # Terminal
  514. echo '[Desktop Entry]' > $rootdir/home/$MY_USERNAME/Desktop/terminal.desktop
  515. echo 'Name=MATE Terminal' >> $rootdir/home/$MY_USERNAME/Desktop/terminal.desktop
  516. echo 'Type=Application' >> $rootdir/home/$MY_USERNAME/Desktop/terminal.desktop
  517. echo 'Comment=Use the command line' >> $rootdir/home/$MY_USERNAME/Desktop/terminal.desktop
  518. echo 'TryExec=mate-terminal' >> $rootdir/home/$MY_USERNAME/Desktop/terminal.desktop
  519. echo 'Exec=mate-terminal' >> $rootdir/home/$MY_USERNAME/Desktop/terminal.desktop
  520. echo 'Icon=terminal' >> $rootdir/home/$MY_USERNAME/Desktop/terminal.desktop
  521. echo 'StartupNotify=true' >> $rootdir/home/$MY_USERNAME/Desktop/terminal.desktop
  522. chroot "$rootdir" chown -R $MY_USERNAME:$MY_USERNAME /home/$MY_USERNAME/Desktop
  523. }
  524. function configure_user_interface {
  525. if [[ $VARIANT != "meshclient" && $VARIANT != "meshusb" && $VARIANT != "usb" ]]; then
  526. return
  527. fi
  528. if [ ! $DEBIAN_REPO ]; then
  529. DEBIAN_REPO='ftp.de.debian.org'
  530. fi
  531. if [ ! $DEBIAN_VERSION ]; then
  532. DEBIAN_VERSION='jessie'
  533. fi
  534. # install backports
  535. echo "deb http://${DEBIAN_REPO}/debian/ ${DEBIAN_VERSION}-backports main" >> $rootdir/etc/apt/sources.list
  536. chroot "$rootdir" apt-get -y update
  537. # desktop
  538. chroot "$rootdir" apt-get -y install mate-desktop-environment
  539. # tool to change desktop settings from command line
  540. chroot "$rootdir" apt-get -y install dconf-cli dconf-gsettings-backend dbus dbus-x11
  541. # for tomb
  542. chroot "$rootdir" apt-get -y install pinentry-gtk2
  543. # for tox video
  544. chroot "$rootdir" apt-get -y install ffmpeg cheese v4l-utils
  545. if [[ $VARIANT != "usb" ]]; then
  546. # log in automatically
  547. chroot "$rootdir" apt-get -y install nodm xinit
  548. echo 'NODM_ENABLED=true' > /etc/default/nodm
  549. echo "NODM_USER=$MY_USERNAME" >> /etc/default/nodm
  550. chroot "$rootdir" mkdir /etc/systemd/system/getty@tty1.service.d
  551. echo '[Service]' > $rootdir/etc/systemd/system/getty@tty1.service.d/override.conf
  552. echo 'ExecStart=' >> $rootdir/etc/systemd/system/getty@tty1.service.d/override.conf
  553. echo 'ExecStart=-/sbin/agetty --autologin fbone --noclear %I $TERM' >> $rootdir/etc/systemd/system/getty@tty1.service.d/override.conf
  554. echo '[[ -z $DISPLAY && $XDG_VTNR -eq 1 ]] && exec startx' >> $rootdir/home/$MY_USERNAME/.profile
  555. chroot "$rootdir" systemctl set-default multi-user.target
  556. mesh_client_startup_applications
  557. mesh_desktop_icons
  558. # Different desktop background for amnesic
  559. if [[ $AMNESIC != 'no' ]]; then
  560. MESH_DESKTOP_BACKGROUND_IMAGE=/usr/local/share/${PROJECT_NAME}_mesh_amnesic_background.png
  561. fi
  562. # change the desktop background
  563. if [ $MESH_DESKTOP_BACKGROUND_IMAGE ]; then
  564. if [ -f $MESH_DESKTOP_BACKGROUND_IMAGE ]; then
  565. if [ -d $rootdir/usr/share/images/desktop-base ]; then
  566. cp $MESH_DESKTOP_BACKGROUND_IMAGE $rootdir/usr/share/images/desktop-base/${PROJECT_NAME}_mesh_background.png
  567. chroot "$rootdir" rm /usr/share/images/desktop-base/desktop-background
  568. chroot "$rootdir" ln -s /usr/share/images/desktop-base/${PROJECT_NAME}_mesh_background.png /usr/share/images/desktop-base/desktop-background
  569. fi
  570. fi
  571. fi
  572. else
  573. chroot "$rootdir" apt-get -y install lightdm
  574. fi
  575. # browser
  576. chroot "$rootdir" apt-get -y install $BROWSER
  577. # Tox user interface
  578. enable_tox_repo
  579. mesh_tox_qtox
  580. # copy the default qtox ini file
  581. if [ ! -d ${rootdir}/home/${MY_USERNAME}/.config/tox ]; then
  582. mkdir ${rootdir}/home/${MY_USERNAME}/.config/tox
  583. cp /usr/local/bin/freedombone-config-qtox ${rootdir}/home/${MY_USERNAME}/.config/tox/qtox.ini
  584. chroot "$rootdir" chown -R ${MY_USERNAME}:${MY_USERNAME} /home/${MY_USERNAME}/.config
  585. fi
  586. # Syncthing
  587. install_syncthing
  588. if [[ $VARIANT == "usb" ]]; then
  589. # tor
  590. chroot "$rootdir" apt-get -y install tor
  591. # xmpp client
  592. chroot "$rootdir" echo "deb ftp://ftp.gajim.org/debian unstable main" > /etc/apt/sources.list.d/gajim.list
  593. chroot "$rootdir" apt-get update
  594. chroot "$rootdir" apt-get -y install gajim-dev-keyring
  595. chroot "$rootdir" apt-get -y install git python-dev python-pip gajim-nightly
  596. chroot "$rootdir" mkdir /home/$GENERIC_IMAGE_USERNAME/.local/share/gajim/plugins -p
  597. chroot "$rootdir" git clone https://github.com/omemo/gajim-omemo /home/$GENERIC_IMAGE_USERNAME/.local/share/gajim/plugins/gajim-omemo
  598. chroot "$rootdir" pip install protobuf==2.6.1, python-axolotl==0.1.35
  599. chroot "$rootdir" chown -R $GENERIC_IMAGE_USERNAME:$GENERIC_IMAGE_USERNAME /home/$GENERIC_IMAGE_USERNAME/.local
  600. # IRC client
  601. chroot "$rootdir" apt-get -y install hexchat profanity
  602. fi
  603. }
  604. ##############################################################################
  605. # Set to true/false to control if eatmydata is used during build
  606. use_eatmydata=true
  607. rootdir="$1"
  608. fmdir="$(pwd)"
  609. image="$fmdir"/"$2"
  610. cd "$rootdir"
  611. echo info: building $MACHINE for $ARCHITECTURE
  612. export DEBIAN_FRONTEND=noninteractive DEBCONF_NONINTERACTIVE_SEEN=true
  613. export LC_ALL=C LANGUAGE=C LANG=C
  614. # Override libpam-tmpdir setting during build, as the directories
  615. # are not created yet.
  616. export TMP=/tmp/ TMPDIR=/tmp/
  617. if [ ! $MY_USERNAME ]; then
  618. echo $'No username was specified'
  619. exit 52825
  620. fi
  621. username=$MY_USERNAME
  622. echo $"warning: creating initial user $username with well known password!"
  623. password=$MY_PASSWORD
  624. chroot "$rootdir" adduser --gecos $username --disabled-password $username
  625. echo $username:$password | chroot $rootdir /usr/sbin/chpasswd
  626. chroot "$rootdir" adduser $username sudo
  627. case "$MACHINE" in
  628. virtualbox)
  629. # hide irrelevant console keyboard messages.
  630. echo "echo \"4 4 1 7\" > /proc/sys/kernel/printk" \
  631. >> /etc/init.d/rc.local
  632. ;;
  633. qemu)
  634. # hide irrelevant console keyboard messages.
  635. echo "echo \"4 4 1 7\" > /proc/sys/kernel/printk" \
  636. >> /etc/init.d/rc.local
  637. ;;
  638. esac
  639. set_apt_sources $BUILD_MIRROR
  640. chroot "$rootdir" apt-get clean
  641. chroot "$rootdir" rm -rf /var/lib/apt/lists/*
  642. chroot "$rootdir" apt-get clean
  643. chroot "$rootdir" apt-get update
  644. cat > $rootdir/usr/sbin/policy-rc.d <<EOF
  645. #!/bin/sh
  646. exit 101
  647. EOF
  648. chmod a+rx $rootdir/usr/sbin/policy-rc.d
  649. if $use_eatmydata ; then
  650. enable_eatmydata_override
  651. fi
  652. if [ -n "$CUSTOM_SETUP" ]; then
  653. cp "$CUSTOM_SETUP" "$rootdir"/tmp
  654. chroot "$rootdir" apt-get install -y gdebi-core
  655. chroot "$rootdir" gdebi -n /tmp/"$(basename $CUSTOM_SETUP)"
  656. fi
  657. chroot "$rootdir" apt-get install -y sudo git dialog toilet build-essential openssh-server
  658. chroot "$rootdir" apt-get install -y avahi-daemon avahi-utils avahi-discover avahi-autoipd
  659. chroot "$rootdir" apt-get install -y iptables dnsutils net-tools network-manager iputils-ping
  660. chroot "$rootdir" apt-get install -y libnss-mdns libnss-myhostname libnss-gw-name nano man ntp
  661. chroot "$rootdir" apt-get install -y locales locales-all debconf wireless-tools wpasupplicant
  662. chroot "$rootdir" apt-get install -y usbutils cryptsetup zsh pinentry-curses
  663. sed -i "s|#host-name=.*|host-name=${PROJECT_NAME}|g" $rootdir/etc/avahi/avahi-daemon.conf
  664. sed -i "s|host-name=.*|host-name=${PROJECT_NAME}|g" $rootdir/etc/avahi/avahi-daemon.conf
  665. chroot "$rootdir" /bin/bash -x <<EOF
  666. git clone $PROJECT_REPO /root/$PROJECT_NAME
  667. cd /root/$PROJECT_NAME
  668. git checkout origin/stockholm -b stockholm
  669. make install
  670. EOF
  671. chroot "$rootdir" ${PROJECT_NAME}-image-hardware-setup 2>&1 | \
  672. tee $rootdir/var/log/${PROJECT_NAME}-image-hardware-setup.log
  673. rm $rootdir/usr/sbin/policy-rc.d
  674. # Set up HRNG for systems known to have one
  675. # Otherwise install haveged
  676. if [[ "$MACHINE" != "beaglebone" ]]; then
  677. chroot $rootdir apt-get -y install haveged
  678. else
  679. chroot $rootdir apt-get -y install rng-tools
  680. sed -i 's|#HRNGDEVICE=/dev/hwrng|HRNGDEVICE=/dev/hwrng|g' $rootdir/etc/default/rng-tools
  681. fi
  682. # copy u-boot to beginning of image
  683. case "$MACHINE" in
  684. beaglebone)
  685. dd if=$rootdir/usr/lib/u-boot/am335x_boneblack/MLO of="$image" \
  686. count=1 seek=1 conv=notrunc bs=128k
  687. dd if=$rootdir/usr/lib/u-boot/am335x_boneblack/u-boot.img of="$image" \
  688. count=2 seek=1 conv=notrunc bs=384k
  689. ;;
  690. cubieboard2)
  691. dd if=$rootdir/usr/lib/u-boot/Cubieboard2/u-boot-sunxi-with-spl.bin of="$image" \
  692. seek=8 conv=notrunc bs=1k
  693. ;;
  694. a20-olinuxino-lime)
  695. dd if=$rootdir/usr/lib/u-boot/A20-OLinuXino-Lime/u-boot-sunxi-with-spl.bin \
  696. of="$image" seek=8 conv=notrunc bs=1k
  697. ;;
  698. esac
  699. if $use_eatmydata ; then
  700. disable_eatmydata_override
  701. fi
  702. set_apt_sources $MIRROR
  703. chroot "$rootdir" apt-get update
  704. configure_ssh
  705. configure_networking
  706. admin_user_sudo
  707. create_generic_image
  708. atheros_wifi
  709. continue_installation
  710. initialise_mesh
  711. configure_wifi
  712. configure_user_interface
  713. cd /
  714. echo $"info: killing leftover processes in chroot"
  715. fuser -mvk $rootdir/. || true
  716. exit 0