freedombone-prep 8.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253
  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. MICROSD_MOUNT_POINT="/media/$USER"
  33. DEBIAN_FILE_NAME="debian-jessie-console-armhf-2014-08-13"
  34. # Downloads for the Debian installer
  35. DOWNLOAD_LINK1="https://rcn-ee.net/deb/rootfs/jessie/$DEBIAN_FILE_NAME.tar.xz"
  36. DOWNLOAD_LINK2="http://ynezz.ibawizard.net/beagleboard/jessie/$DEBIAN_FILE_NAME.tar.xz"
  37. ROOTFS='rootfs'
  38. BOOT='BOOT'
  39. function show_help {
  40. echo ''
  41. echo 'freedombone-prep -d [microSD device] --ip [BBB LAN IP address] --iprouter [Router LAN IP address] --mount [mount directory]'
  42. echo ''
  43. echo 'See the manpage for more details'
  44. echo ''
  45. }
  46. # if no arguments are given
  47. if [[ $NO_OF_ARGS == 0 ]]; then
  48. show_help
  49. exit 0
  50. fi
  51. if [ ! -d $MICROSD_MOUNT_POINT ]; then
  52. if [ -d /media ]; then
  53. # different directories for Debian
  54. if [ -d /media/usb1 ]; then
  55. MICROSD_MOUNT_POINT=/media
  56. ROOTFS=usb1
  57. fi
  58. if [ -d /media/usb0 ]; then
  59. MICROSD_MOUNT_POINT=/media
  60. BOOT=usb0
  61. fi
  62. fi
  63. if [ ! -d $MICROSD_MOUNT_POINT ]; then
  64. echo "The mount directory $MICROSD_MOUNT_POINT does not exist."
  65. echo 'Use the --mount option to specify where the microSD gets mounted to.'
  66. exit 67563
  67. fi
  68. fi
  69. while [[ $# > 1 ]]
  70. do
  71. key="$1"
  72. case $key in
  73. -h|--help)
  74. show_help
  75. ;;
  76. # Drive path for the microSD
  77. -d|--drive)
  78. shift
  79. MICROSD_DRIVE="$1"
  80. ;;
  81. # BBB static IP address on the LAN
  82. --ip)
  83. shift
  84. BBB_FIXED_IP_ADDRESS="$1"
  85. ;;
  86. # Router IP address on the LAN
  87. --iprouter)
  88. shift
  89. ROUTER_IP_ADDRESS="$1"
  90. ;;
  91. # mount point
  92. --mount)
  93. shift
  94. MICROSD_MOUNT_POINT="$1"
  95. ;;
  96. *)
  97. # unknown option
  98. ;;
  99. esac
  100. shift
  101. done
  102. if [ ! $MICROSD_DRIVE ]; then
  103. echo 'You need to specify a drive for the connected microSD.'
  104. echo 'This can most easily be found by removing the microSD, then'
  105. echo 'running:'
  106. echo ''
  107. echo ' ls /dev/sd*'
  108. echo ''
  109. echo 'Then plugging the microSD back in and entering the same command again'
  110. exit 1
  111. fi
  112. if [ ! -b ${MICROSD_DRIVE}1 ]; then
  113. echo "The microSD drive could not be found at ${MICROSD_DRIVE}1"
  114. exit 2
  115. fi
  116. if [ ! -d ~/freedombone ]; then
  117. mkdir ~/freedombone
  118. fi
  119. cd ~/freedombone
  120. if [ ! -f ~/freedombone/$DEBIAN_FILE_NAME.tar.xz ]; then
  121. wget $DOWNLOAD_LINK1
  122. fi
  123. if [ ! -f ~/freedombone/$DEBIAN_FILE_NAME.tar.xz ]; then
  124. # try another site
  125. wget $DOWNLOAD_LINK2
  126. if [ ! -f ~/freedombone/$DEBIAN_FILE_NAME.tar.xz ]; then
  127. echo 'The Debian installer could not be downloaded'
  128. exit 3
  129. fi
  130. fi
  131. echo 'Extracting files...'
  132. tar xJf $DEBIAN_FILE_NAME.tar.xz
  133. if [ ! -d ~/freedombone/$DEBIAN_FILE_NAME ]; then
  134. echo "Couldn't extract files"
  135. exit 4
  136. fi
  137. cd $DEBIAN_FILE_NAME
  138. SUDO=
  139. if [ -f /usr/bin/sudo ]; then
  140. SUDO='sudo'
  141. fi
  142. $SUDO ./setup_sdcard.sh --mmc $MICROSD_DRIVE --dtb beaglebone
  143. echo ''
  144. echo ''
  145. 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
  146. if [ ! -b ${MICROSD_DRIVE}1 ]; then
  147. echo ''
  148. echo "The microSD drive could not be found at ${MICROSD_DRIVE}1"
  149. read -p "Wait for the drive to mount then press any key... " -n1 -s
  150. if [ ! -b ${MICROSD_DRIVE}1 ]; then
  151. echo "microSD drive not found at ${MICROSD_DRIVE}1"
  152. exit 5
  153. fi
  154. fi
  155. if [ ! -d $MICROSD_MOUNT_POINT/$BOOT ]; then
  156. echo ''
  157. echo "The boot partition $MICROSD_MOUNT_POINT/$BOOT was not found."
  158. ls $MICROSD_MOUNT_POINT
  159. exit 67857
  160. fi
  161. if [ ! -d $MICROSD_MOUNT_POINT/$ROOTFS ]; then
  162. echo ''
  163. echo "The rootfs partition $MICROSD_MOUNT_POINT/$ROOTFS was not found."
  164. ls $MICROSD_MOUNT_POINT
  165. exit 65688
  166. fi
  167. if [ ! -d $MICROSD_MOUNT_POINT/$ROOTFS/home ]; then
  168. echo ''
  169. echo "The rootfs partition was not written correctly."
  170. ls $MICROSD_MOUNT_POINT/$ROOTFS
  171. exit 65688
  172. fi
  173. $SUDO cp $MICROSD_MOUNT_POINT/$BOOT/bbb-uEnv.txt $MICROSD_MOUNT_POINT/$BOOT/uEnv.txt
  174. $SUDO sed -i 's/iface eth0 inet dhcp/iface eth0 inet static/g' $MICROSD_MOUNT_POINT/$ROOTFS/etc/network/interfaces
  175. $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
  176. $SUDO sed -i "/iface eth0 inet static/a\ gateway $ROUTER_IP_ADDRESS" $MICROSD_MOUNT_POINT/$ROOTFS/etc/network/interfaces
  177. $SUDO sed -i '/iface eth0 inet static/a\ netmask 255.255.255.0' $MICROSD_MOUNT_POINT/$ROOTFS/etc/network/interfaces
  178. $SUDO sed -i "/iface eth0 inet static/a\ address $BBB_FIXED_IP_ADDRESS" $MICROSD_MOUNT_POINT/$ROOTFS/etc/network/interfaces
  179. $SUDO sed -i '/iface usb0 inet static/,/ gateway 192.168.7.1/ s/^/#/' $MICROSD_MOUNT_POINT/$ROOTFS/etc/network/interfaces
  180. $SUDO sed -i 's/nameserver.*/nameserver 213.73.91.35/g' $MICROSD_MOUNT_POINT/$ROOTFS/etc/resolv.conf
  181. $SUDO sed -i '/nameserver 213.73.91.35/a\nameserver 85.214.20.141' $MICROSD_MOUNT_POINT/$ROOTFS/etc/resolv.conf
  182. # change the motd to show further install instructions
  183. echo 'Become the root user by typing:' > $MICROSD_MOUNT_POINT/$ROOTFS/etc/motd
  184. echo '' >> $MICROSD_MOUNT_POINT/$ROOTFS/etc/motd
  185. echo ' su' >> $MICROSD_MOUNT_POINT/$ROOTFS/etc/motd
  186. echo '' >> $MICROSD_MOUNT_POINT/$ROOTFS/etc/motd
  187. echo 'Using the password "root". Change the root user password by typing:' >> $MICROSD_MOUNT_POINT/$ROOTFS/etc/motd
  188. echo '' >> $MICROSD_MOUNT_POINT/$ROOTFS/etc/motd
  189. echo ' passwd' >> $MICROSD_MOUNT_POINT/$ROOTFS/etc/motd
  190. echo '' >> $MICROSD_MOUNT_POINT/$ROOTFS/etc/motd
  191. echo 'Then create a user for the system with:' >> $MICROSD_MOUNT_POINT/$ROOTFS/etc/motd
  192. echo '' >> $MICROSD_MOUNT_POINT/$ROOTFS/etc/motd
  193. echo ' adduser [username]' >> $MICROSD_MOUNT_POINT/$ROOTFS/etc/motd
  194. echo '' >> $MICROSD_MOUNT_POINT/$ROOTFS/etc/motd
  195. echo 'Enter the command "exit" a couple of times to get back to your main system' >> $MICROSD_MOUNT_POINT/$ROOTFS/etc/motd
  196. echo 'then log back in as the user you just created with:' >> $MICROSD_MOUNT_POINT/$ROOTFS/etc/motd
  197. echo '' >> $MICROSD_MOUNT_POINT/$ROOTFS/etc/motd
  198. echo ' ssh [username]@$BBB_FIXED_IP_ADDRESS' >> $MICROSD_MOUNT_POINT/$ROOTFS/etc/motd
  199. echo '' >> $MICROSD_MOUNT_POINT/$ROOTFS/etc/motd
  200. echo 'and use the "su" command to become the root user again. You can then load' >> $MICROSD_MOUNT_POINT/$ROOTFS/etc/motd
  201. echo 'the freedombone main installation script with:' >> $MICROSD_MOUNT_POINT/$ROOTFS/etc/motd
  202. echo '' >> $MICROSD_MOUNT_POINT/$ROOTFS/etc/motd
  203. echo ' apt-get update' >> $MICROSD_MOUNT_POINT/$ROOTFS/etc/motd
  204. echo ' apt-get -y install git dialog build-essential' >> $MICROSD_MOUNT_POINT/$ROOTFS/etc/motd
  205. echo ' git clone https://github.com/bashrc/freedombone.git' >> $MICROSD_MOUNT_POINT/$ROOTFS/etc/motd
  206. echo ' cd freedombone' >> $MICROSD_MOUNT_POINT/$ROOTFS/etc/motd
  207. echo ' make install' >> $MICROSD_MOUNT_POINT/$ROOTFS/etc/motd
  208. echo '' >> $MICROSD_MOUNT_POINT/$ROOTFS/etc/motd
  209. echo 'Finally you can use the freedombone command to install a server configuration:' >> $MICROSD_MOUNT_POINT/$ROOTFS/etc/motd
  210. echo '' >> $MICROSD_MOUNT_POINT/$ROOTFS/etc/motd
  211. echo ' freedombone menuconfig' >> $MICROSD_MOUNT_POINT/$ROOTFS/etc/motd
  212. clear
  213. echo '*** Initial microSD card setup is complete ***'
  214. echo ''
  215. echo 'The microSD card can now be removed and inserted into the Beaglebone Black.'
  216. echo 'Once the Beaglebone has booted then you can log in with:'
  217. echo ''
  218. echo " ssh debian@$BBB_FIXED_IP_ADDRESS"
  219. echo ''
  220. echo 'The password is "temppwd".'
  221. cat $MICROSD_MOUNT_POINT/$ROOTFS/etc/motd
  222. exit 0