freedombone-image-customise 38KB

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