freedombone-prep 5.9KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189
  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. # Version number of this script
  22. VERSION="1.00"
  23. # typically /dev/sdb or /dev/sdc, depending upon how
  24. # many drives there are on your system
  25. MICROSD_DRIVE=
  26. # IP address of the router (gateway)
  27. ROUTER_IP_ADDRESS="192.168.1.254"
  28. # The fixed IP address of the Beaglebone Black on your local network
  29. BBB_FIXED_IP_ADDRESS="192.168.1.55"
  30. MICROSD_MOUNT_POINT="/media/$USER"
  31. DEBIAN_FILE_NAME="debian-jessie-console-armhf-2014-08-13"
  32. # Downloads for the Debian installer
  33. DOWNLOAD_LINK1="https://rcn-ee.net/deb/rootfs/jessie/$DEBIAN_FILE_NAME.tar.xz"
  34. DOWNLOAD_LINK2="http://ynezz.ibawizard.net/beagleboard/jessie/$DEBIAN_FILE_NAME.tar.xz"
  35. function show_help {
  36. echo ''
  37. echo 'freedombone-prep -d [microSD device] --ip [BBB LAN IP address] --iprouter [Router LAN IP address]'
  38. echo ''
  39. }
  40. while [[ $# > 1 ]]
  41. do
  42. key="$1"
  43. case $key in
  44. -h|--help)
  45. show_help
  46. ;;
  47. # Drive path for the microSD
  48. -d|--drive)
  49. shift
  50. MICROSD_DRIVE="$1"
  51. ;;
  52. # BBB static IP address on the LAN
  53. --ip)
  54. shift
  55. BBB_FIXED_IP_ADDRESS="$1"
  56. ;;
  57. # Router IP address on the LAN
  58. --iprouter)
  59. shift
  60. ROUTER_IP_ADDRESS="$1"
  61. ;;
  62. *)
  63. # unknown option
  64. ;;
  65. esac
  66. shift
  67. done
  68. if [ ! $MICROSD_DRIVE ]; then
  69. echo 'You need to specify a drive for the connected microSD.'
  70. echo 'This can most easily be found by removing the microSD, then'
  71. echo 'running:'
  72. echo ''
  73. echo ' ls /dev/sd*'
  74. echo ''
  75. echo 'Then plugging the microSD back in and entering the same command again'
  76. exit 1
  77. fi
  78. if [ ! -b ${MICROSD_DRIVE}1 ]; then
  79. echo "The microSD drive could not be found at ${MICROSD_DRIVE}1"
  80. exit 2
  81. fi
  82. if [ ! -d ~/freedombone ]; then
  83. mkdir ~/freedombone
  84. fi
  85. cd ~/freedombone
  86. if [ ! -f ~/freedombone/$DEBIAN_FILE_NAME.tar.xz ]; then
  87. wget $DOWNLOAD_LINK1
  88. fi
  89. if [ ! -f ~/freedombone/$DEBIAN_FILE_NAME.tar.xz ]; then
  90. # try another site
  91. wget $DOWNLOAD_LINK2
  92. if [ ! -f ~/freedombone/$DEBIAN_FILE_NAME.tar.xz ]; then
  93. echo 'The Debian installer could not be downloaded'
  94. exit 3
  95. fi
  96. fi
  97. echo 'Extracting files...'
  98. tar xJf $DEBIAN_FILE_NAME.tar.xz
  99. if [ ! -d ~/freedombone/$DEBIAN_FILE_NAME ]; then
  100. echo "Couldn't extract files"
  101. exit 4
  102. fi
  103. cd $DEBIAN_FILE_NAME
  104. sudo ./setup_sdcard.sh --mmc $MICROSD_DRIVE --dtb beaglebone
  105. echo ''
  106. echo ''
  107. 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
  108. if [ ! -b ${MICROSD_DRIVE}1 ]; then
  109. echo ''
  110. echo "The microSD drive could not be found at ${MICROSD_DRIVE}1"
  111. read -p "Wait for the drive to mount then press any key... " -n1 -s
  112. if [ ! -b ${MICROSD_DRIVE}1 ]; then
  113. echo "microSD drive not found at ${MICROSD_DRIVE}1"
  114. exit 5
  115. fi
  116. fi
  117. sudo cp $MICROSD_MOUNT_POINT/BOOT/bbb-uEnv.txt $MICROSD_MOUNT_POINT/BOOT/uEnv.txt
  118. sudo sed -i 's/iface eth0 inet dhcp/iface eth0 inet static/g' $MICROSD_MOUNT_POINT/rootfs/etc/network/interfaces
  119. 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
  120. sudo sed -i "/iface eth0 inet static/a\ gateway $ROUTER_IP_ADDRESS" $MICROSD_MOUNT_POINT/rootfs/etc/network/interfaces
  121. sudo sed -i '/iface eth0 inet static/a\ netmask 255.255.255.0' $MICROSD_MOUNT_POINT/rootfs/etc/network/interfaces
  122. sudo sed -i "/iface eth0 inet static/a\ address $BBB_FIXED_IP_ADDRESS" $MICROSD_MOUNT_POINT/rootfs/etc/network/interfaces
  123. sudo sed -i '/iface usb0 inet static/,/ gateway 192.168.7.1/ s/^/#/' $MICROSD_MOUNT_POINT/rootfs/etc/network/interfaces
  124. sudo sed -i 's/nameserver.*/nameserver 213.73.91.35/g' $MICROSD_MOUNT_POINT/rootfs/etc/resolv.conf
  125. sudo sed -i '/nameserver 213.73.91.35/a\nameserver 85.214.20.141' $MICROSD_MOUNT_POINT/rootfs/etc/resolv.conf
  126. clear
  127. echo '*** Initial microSD card setup is complete ***'
  128. echo ''
  129. echo 'The microSD card can now be removed and inserted into the Beaglebone Black.'
  130. echo 'Once the Beaglebone has booted then you can log in with:'
  131. echo ''
  132. echo " ssh debian@$BBB_FIXED_IP_ADDRESS"
  133. echo ''
  134. echo 'The password is "temppwd". You can then become the root user by typing:'
  135. echo ''
  136. echo ' su'
  137. echo ''
  138. echo 'Using the password "root". Change the root user password by typing:'
  139. echo ''
  140. echo ' passwd'
  141. echo ''
  142. echo "If you can't log in as root then try typing 'exit' and then:"
  143. echo ''
  144. echo " ssh root@$BBB_FIXED_IP_ADDRESS"
  145. echo ''
  146. echo 'Then create a user for the system with:'
  147. echo ''
  148. echo ' adduser [username]'
  149. echo ''
  150. echo 'Enter the command "exit" a couple of times to get back to your main system'
  151. echo 'then log back in as the user you just created with:'
  152. echo ''
  153. echo ' ssh [username]@$BBB_FIXED_IP_ADDRESS'
  154. echo ''
  155. echo 'and use the "su" command to become the root user again. You can then load'
  156. echo 'the freedombone main installation script with:'
  157. echo ''
  158. echo ' apt-get -y install git'
  159. echo ' git clone https://github.com/bashrc/freedombone.git'
  160. echo ' cd freedombone'
  161. echo ''
  162. echo 'Finally you can use the freedombone command to install a server configuration:'
  163. echo ''
  164. echo ' freedombone menuconfig'
  165. echo ''
  166. echo 'See the manpage for more information on how to use the freedombone command.'
  167. exit 0