freedombone-prep 8.7KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267
  1. #!/bin/bash
  2. # This script installs the Debian image to the microSD card, and should
  3. # be run on your laptop/desktop with the microSD card plugged in.
  4. # License
  5. # =======
  6. #
  7. # Copyright (C) 2014-2015 Bob Mottram <bob@robotics.uk.to>
  8. #
  9. # This program is free software: you can redistribute it and/or modify
  10. # it under the terms of the GNU General Public License as published by
  11. # the Free Software Foundation, either version 3 of the License, or
  12. # (at your option) any later version.
  13. #
  14. # This program is distributed in the hope that it will be useful,
  15. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  16. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  17. # GNU General Public License for more details.
  18. #
  19. # You should have received a copy of the GNU General Public License
  20. # along with this program. If not, see <http://www.gnu.org/licenses/>.
  21. # The number of arguments
  22. NO_OF_ARGS=$#
  23. # Version number of this script
  24. VERSION="1.00"
  25. # typically /dev/sdb or /dev/sdc, depending upon how
  26. # many drives there are on your system
  27. MICROSD_DRIVE=
  28. # IP address of the router (gateway)
  29. ROUTER_IP_ADDRESS="192.168.1.254"
  30. # The fixed IP address of the Beaglebone Black on your local network
  31. BBB_FIXED_IP_ADDRESS="192.168.1.55"
  32. # DNS
  33. NAMESERVER1='213.73.91.35'
  34. NAMESERVER2='85.214.20.141'
  35. MICROSD_MOUNT_POINT="/media/$USER"
  36. DEBIAN_FILE_NAME="debian-jessie-console-armhf-2014-08-13"
  37. # Downloads for the Debian installer
  38. DOWNLOAD_LINK1="https://rcn-ee.net/deb/rootfs/jessie/$DEBIAN_FILE_NAME.tar.xz"
  39. DOWNLOAD_LINK2="http://ynezz.ibawizard.net/beagleboard/jessie/$DEBIAN_FILE_NAME.tar.xz"
  40. ROOTFS='rootfs'
  41. BOOT='BOOT'
  42. function show_help {
  43. echo ''
  44. echo 'freedombone-prep -d [microSD device] --ip [BBB LAN IP address] --iprouter [Router LAN IP address] --mount [mount directory]'
  45. echo ''
  46. echo 'See the manpage for more details'
  47. echo ''
  48. }
  49. # if no arguments are given
  50. if [[ $NO_OF_ARGS == 0 ]]; then
  51. show_help
  52. exit 0
  53. fi
  54. if [ ! -d $MICROSD_MOUNT_POINT ]; then
  55. if [ -d /media ]; then
  56. # different directories for Debian
  57. if [ -d /media/usb1 ]; then
  58. MICROSD_MOUNT_POINT=/media
  59. ROOTFS=usb1
  60. fi
  61. if [ -d /media/usb0 ]; then
  62. MICROSD_MOUNT_POINT=/media
  63. BOOT=usb0
  64. fi
  65. fi
  66. if [ ! -d $MICROSD_MOUNT_POINT ]; then
  67. echo "The mount directory $MICROSD_MOUNT_POINT does not exist."
  68. echo 'Use the --mount option to specify where the microSD gets mounted to.'
  69. exit 67563
  70. fi
  71. fi
  72. while [[ $# > 1 ]]
  73. do
  74. key="$1"
  75. case $key in
  76. -h|--help)
  77. show_help
  78. ;;
  79. # Drive path for the microSD
  80. -d|--drive)
  81. shift
  82. MICROSD_DRIVE="$1"
  83. ;;
  84. # BBB static IP address on the LAN
  85. --ip)
  86. shift
  87. BBB_FIXED_IP_ADDRESS="$1"
  88. ;;
  89. # Router IP address on the LAN
  90. --iprouter)
  91. shift
  92. ROUTER_IP_ADDRESS="$1"
  93. ;;
  94. # mount point
  95. --mount)
  96. shift
  97. MICROSD_MOUNT_POINT="$1"
  98. ;;
  99. # nameserver 1
  100. --ns1)
  101. shift
  102. NAMESERVER1="$1"
  103. ;;
  104. # nameserver 2
  105. --ns2)
  106. shift
  107. NAMESERVER2="$1"
  108. ;;
  109. *)
  110. # unknown option
  111. ;;
  112. esac
  113. shift
  114. done
  115. if [ ! $MICROSD_DRIVE ]; then
  116. echo 'You need to specify a drive for the connected microSD.'
  117. echo 'This can most easily be found by removing the microSD, then'
  118. echo 'running:'
  119. echo ''
  120. echo ' ls /dev/sd*'
  121. echo ''
  122. echo 'Then plugging the microSD back in and entering the same command again'
  123. exit 1
  124. fi
  125. if [ ! -b ${MICROSD_DRIVE}1 ]; then
  126. echo "The microSD drive could not be found at ${MICROSD_DRIVE}1"
  127. exit 2
  128. fi
  129. if [ ! -d ~/freedombone ]; then
  130. mkdir ~/freedombone
  131. fi
  132. cd ~/freedombone
  133. if [ ! -f ~/freedombone/$DEBIAN_FILE_NAME.tar.xz ]; then
  134. wget $DOWNLOAD_LINK1
  135. fi
  136. if [ ! -f ~/freedombone/$DEBIAN_FILE_NAME.tar.xz ]; then
  137. # try another site
  138. wget $DOWNLOAD_LINK2
  139. if [ ! -f ~/freedombone/$DEBIAN_FILE_NAME.tar.xz ]; then
  140. echo 'The Debian installer could not be downloaded'
  141. exit 3
  142. fi
  143. fi
  144. echo 'Extracting files...'
  145. tar xJf $DEBIAN_FILE_NAME.tar.xz
  146. if [ ! -d ~/freedombone/$DEBIAN_FILE_NAME ]; then
  147. echo "Couldn't extract files"
  148. exit 4
  149. fi
  150. cd $DEBIAN_FILE_NAME
  151. SUDO=
  152. if [ -f /usr/bin/sudo ]; then
  153. SUDO='sudo'
  154. fi
  155. $SUDO ./setup_sdcard.sh --mmc $MICROSD_DRIVE --dtb beaglebone
  156. echo ''
  157. echo ''
  158. read -p "Eject the microSD card, re-insert it and wait a minute for it to mount, then press any key to continue... " -n1 -s
  159. if [ ! -b ${MICROSD_DRIVE}1 ]; then
  160. echo ''
  161. echo "The microSD drive could not be found at ${MICROSD_DRIVE}1"
  162. read -p "Wait for the drive to mount then press any key... " -n1 -s
  163. if [ ! -b ${MICROSD_DRIVE}1 ]; then
  164. echo "microSD drive not found at ${MICROSD_DRIVE}1"
  165. exit 5
  166. fi
  167. fi
  168. if [ ! -d $MICROSD_MOUNT_POINT/$BOOT ]; then
  169. echo ''
  170. echo "The boot partition $MICROSD_MOUNT_POINT/$BOOT was not found."
  171. ls $MICROSD_MOUNT_POINT
  172. exit 67857
  173. fi
  174. if [ ! -d $MICROSD_MOUNT_POINT/$ROOTFS ]; then
  175. echo ''
  176. echo "The rootfs partition $MICROSD_MOUNT_POINT/$ROOTFS was not found."
  177. ls $MICROSD_MOUNT_POINT
  178. exit 65688
  179. fi
  180. if [ ! -d $MICROSD_MOUNT_POINT/$ROOTFS/home ]; then
  181. echo ''
  182. echo "The rootfs partition was not written correctly."
  183. ls $MICROSD_MOUNT_POINT/$ROOTFS
  184. exit 65688
  185. fi
  186. $SUDO cp $MICROSD_MOUNT_POINT/$BOOT/bbb-uEnv.txt $MICROSD_MOUNT_POINT/$BOOT/uEnv.txt
  187. $SUDO sed -i 's/iface eth0 inet dhcp/iface eth0 inet static/g' $MICROSD_MOUNT_POINT/$ROOTFS/etc/network/interfaces
  188. $SUDO sed -i '/iface eth0 inet static/a\ dns-nameservers 213.73.91.35 85.214.20.141' $MICROSD_MOUNT_POINT/$ROOTFS/etc/network/interfaces
  189. $SUDO sed -i "/iface eth0 inet static/a\ gateway $ROUTER_IP_ADDRESS" $MICROSD_MOUNT_POINT/$ROOTFS/etc/network/interfaces
  190. $SUDO sed -i '/iface eth0 inet static/a\ netmask 255.255.255.0' $MICROSD_MOUNT_POINT/$ROOTFS/etc/network/interfaces
  191. $SUDO sed -i "/iface eth0 inet static/a\ address $BBB_FIXED_IP_ADDRESS" $MICROSD_MOUNT_POINT/$ROOTFS/etc/network/interfaces
  192. $SUDO sed -i '/iface usb0 inet static/,/ gateway 192.168.7.1/ s/^/#/' $MICROSD_MOUNT_POINT/$ROOTFS/etc/network/interfaces
  193. $SUDO sed -i "s/nameserver.*/nameserver $NAMESERVER1/g" $MICROSD_MOUNT_POINT/$ROOTFS/etc/resolv.conf
  194. $SUDO sed -i "/nameserver $NAMESERVER1/a\nameserver $NAMESERVER2" $MICROSD_MOUNT_POINT/$ROOTFS/etc/resolv.conf
  195. # change the motd to show further install instructions
  196. echo 'Become the root user by typing:' > $MICROSD_MOUNT_POINT/$ROOTFS/etc/motd
  197. echo '' >> $MICROSD_MOUNT_POINT/$ROOTFS/etc/motd
  198. echo ' su' >> $MICROSD_MOUNT_POINT/$ROOTFS/etc/motd
  199. echo '' >> $MICROSD_MOUNT_POINT/$ROOTFS/etc/motd
  200. echo 'Using the password "root". Change the root user password by typing:' >> $MICROSD_MOUNT_POINT/$ROOTFS/etc/motd
  201. echo '' >> $MICROSD_MOUNT_POINT/$ROOTFS/etc/motd
  202. echo ' passwd' >> $MICROSD_MOUNT_POINT/$ROOTFS/etc/motd
  203. echo '' >> $MICROSD_MOUNT_POINT/$ROOTFS/etc/motd
  204. echo 'Then create a user for the system with:' >> $MICROSD_MOUNT_POINT/$ROOTFS/etc/motd
  205. echo '' >> $MICROSD_MOUNT_POINT/$ROOTFS/etc/motd
  206. echo ' adduser [username]' >> $MICROSD_MOUNT_POINT/$ROOTFS/etc/motd
  207. echo '' >> $MICROSD_MOUNT_POINT/$ROOTFS/etc/motd
  208. echo 'Enter the command "exit" a couple of times to get back to your main system' >> $MICROSD_MOUNT_POINT/$ROOTFS/etc/motd
  209. echo 'then log back in as the user you just created with:' >> $MICROSD_MOUNT_POINT/$ROOTFS/etc/motd
  210. echo '' >> $MICROSD_MOUNT_POINT/$ROOTFS/etc/motd
  211. echo ' ssh [username]@$BBB_FIXED_IP_ADDRESS' >> $MICROSD_MOUNT_POINT/$ROOTFS/etc/motd
  212. echo '' >> $MICROSD_MOUNT_POINT/$ROOTFS/etc/motd
  213. echo 'and use the "su" command to become the root user again. You can then load' >> $MICROSD_MOUNT_POINT/$ROOTFS/etc/motd
  214. echo 'the freedombone main installation script with:' >> $MICROSD_MOUNT_POINT/$ROOTFS/etc/motd
  215. echo '' >> $MICROSD_MOUNT_POINT/$ROOTFS/etc/motd
  216. echo ' apt-get update' >> $MICROSD_MOUNT_POINT/$ROOTFS/etc/motd
  217. echo ' apt-get -y install git dialog build-essential' >> $MICROSD_MOUNT_POINT/$ROOTFS/etc/motd
  218. echo ' git clone https://github.com/bashrc/freedombone.git' >> $MICROSD_MOUNT_POINT/$ROOTFS/etc/motd
  219. echo ' cd freedombone' >> $MICROSD_MOUNT_POINT/$ROOTFS/etc/motd
  220. echo ' make install' >> $MICROSD_MOUNT_POINT/$ROOTFS/etc/motd
  221. echo '' >> $MICROSD_MOUNT_POINT/$ROOTFS/etc/motd
  222. echo 'Finally you can use the freedombone command to install a server configuration:' >> $MICROSD_MOUNT_POINT/$ROOTFS/etc/motd
  223. echo '' >> $MICROSD_MOUNT_POINT/$ROOTFS/etc/motd
  224. echo ' freedombone menuconfig' >> $MICROSD_MOUNT_POINT/$ROOTFS/etc/motd
  225. clear
  226. echo '*** Initial microSD card setup is complete ***'
  227. echo ''
  228. echo 'The microSD card can now be removed and inserted into the Beaglebone Black.'
  229. echo 'Once the Beaglebone has booted then you can log in with:'
  230. echo ''
  231. echo " ssh debian@$BBB_FIXED_IP_ADDRESS"
  232. echo ''
  233. echo 'The password is "temppwd".'
  234. cat $MICROSD_MOUNT_POINT/$ROOTFS/etc/motd
  235. exit 0