cloudmin-kvm-debian-install.sh 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315
  1. #!/bin/sh
  2. # cloudmin-kvm-debian-install.sh
  3. # Copyright 2005-2011 Virtualmin, Inc.
  4. #
  5. # Installs Cloudmin GPL for KVM and all dependencies on a Debian or Ubuntu
  6. # system.
  7. VER=1.1
  8. # Define functions
  9. yesno () {
  10. while read line; do
  11. case $line in
  12. y|Y|Yes|YES|yes|yES|yEs|YeS|yeS) return 0
  13. ;;
  14. n|N|No|NO|no|nO) return 1
  15. ;;
  16. *)
  17. printf "\nPlease enter y or n: "
  18. ;;
  19. esac
  20. done
  21. }
  22. # Show help page
  23. if [ "$1" = "--help" ]; then
  24. echo $0 [--qemu] [--no-bridge | --bridge-interface ethN]
  25. exit 0
  26. fi
  27. # Ask the user first
  28. cat <<EOF
  29. *******************************************************************************
  30. * Welcome to the Cloudmin GPL for KVM installer, version $VER *
  31. *******************************************************************************
  32. Operating systems supported by this installer are:
  33. Debian 4.0 or later on i386 and x86_64
  34. Ubuntu 8.04 or later on i386 and x86_64
  35. If your OS is not listed above, this script will fail (and attempting
  36. to run it on an unsupported OS is not recommended, or...supported).
  37. EOF
  38. printf " Continue? (y/n) "
  39. if ! yesno
  40. then exit
  41. fi
  42. echo ""
  43. # Check for non-kernel mode flag
  44. if [ "$1" = "--qemu" ]; then
  45. qemu=1
  46. fi
  47. # Check for flag to disable bridge setup
  48. if [ "$1" = "--no-bridge" ]; then
  49. shift
  50. nobridge=1
  51. fi
  52. # Check for flag for network interface
  53. if [ "$1" = "--bridge-interface" ]; then
  54. shift
  55. interface=$1
  56. shift
  57. fi
  58. # Cleanup old repo files
  59. grep -v cloudmin.virtualmin.com /etc/apt/sources.list >/etc/apt/sources.list.clean
  60. mv /etc/apt/sources.list.clean /etc/apt/sources.list
  61. # Check for KVM-capable CPU
  62. if [ "$qemu" != 1 ]; then
  63. echo Checking for hardware support for KVM ..
  64. grep -e vmx -e svm /proc/cpuinfo >/dev/null
  65. if [ $? != 0 ]; then
  66. echo .. not found. Make sure your CPU has Intel VT-x or AMD-V support
  67. echo ""
  68. exit 1
  69. fi
  70. echo .. found OK
  71. echo ""
  72. fi
  73. # Check for apt-get
  74. echo Checking for apt-get ..
  75. if [ ! -x /usr/bin/apt-get ]; then
  76. echo .. not installed. The Cloudmin installer requires APT to download packages
  77. echo ""
  78. exit 1
  79. fi
  80. echo .. found OK
  81. echo ""
  82. # Make sure we have wget
  83. echo "Installing wget .."
  84. apt-get -y install wget
  85. echo ".. done"
  86. echo ""
  87. # Check for wget or curl
  88. echo "Checking for curl or wget..."
  89. if [ -x "/usr/bin/curl" ]; then
  90. download="/usr/bin/curl -s "
  91. elif [ -x "/usr/bin/wget" ]; then
  92. download="/usr/bin/wget -nv -O -"
  93. else
  94. echo "No web download program available: Please install curl or wget"
  95. echo "and try again."
  96. exit 1
  97. fi
  98. echo "found $download"
  99. echo ""
  100. # Create Cloudmin licence file
  101. echo Creating Cloudmin licence file
  102. cat >/etc/server-manager-license <<EOF
  103. SerialNumber=GPL
  104. LicenseKey=GPL
  105. EOF
  106. chmod 600 /etc/server-manager-license
  107. # Download GPG keys
  108. echo Downloading GPG keys for packages ..
  109. $download "http://software.virtualmin.com/lib/RPM-GPG-KEY-virtualmin" >/tmp/RPM-GPG-KEY-virtualmin
  110. if [ "$?" != 0 ]; then
  111. echo .. download failed
  112. exit 1
  113. fi
  114. $download "http://software.virtualmin.com/lib/RPM-GPG-KEY-webmin" >/tmp/RPM-GPG-KEY-webmin
  115. if [ "$?" != 0 ]; then
  116. echo .. download failed
  117. exit 1
  118. fi
  119. echo .. done
  120. echo ""
  121. # Import keys
  122. echo Importing GPG keys ..
  123. apt-key add /tmp/RPM-GPG-KEY-virtualmin && apt-key add /tmp/RPM-GPG-KEY-webmin
  124. echo .. done
  125. echo ""
  126. # Setup the APT sources file
  127. echo Creating APT repository for Cloudmin packages ..
  128. cat >>/etc/apt/sources.list <<EOF
  129. deb http://cloudmin.virtualmin.com/kvm/debian binary/
  130. EOF
  131. apt-get update
  132. echo .. done
  133. echo ""
  134. # Turn off apparmor
  135. if [ -r /etc/init.d/apparmor ]; then
  136. echo Turning off apparmor ..
  137. /etc/init.d/apparmor stop
  138. update-rc.d -f apparmor remove
  139. echo .. done
  140. echo ""
  141. fi
  142. # YUM install Perl, modules and other dependencies
  143. echo Installing required Perl modules using APT ..
  144. apt-get -y install perl openssl libio-pty-perl libio-stty-perl libnet-ssleay-perl libwww-perl libdigest-hmac-perl libxml-simple-perl libcrypt-ssleay-perl libauthen-pam-perl cron bind9 lsof parted openssh-client openssh-server bzip2
  145. if [ "$?" != 0 ]; then
  146. echo .. install failed
  147. exit 1
  148. fi
  149. apt-get -y install kvm qemu || apt-get -y install qemu-kvm qemu
  150. if [ "$?" != 0 ]; then
  151. echo .. install failed
  152. exit 1
  153. fi
  154. apt-get install -y libjson-perl
  155. apt-get install -y bind9utils
  156. apt-get install -y dhcp3-server
  157. apt-get install -y libdigest-sha1-perl
  158. apt-get install -y ebtables
  159. echo .. done
  160. echo ""
  161. # Activate cgroups
  162. echo Installing and activating cgroups ..
  163. apt-get install -y cgroup-bin
  164. if [ "$?" != 0 ]; then
  165. echo .. install failed - CPU limits will not be available
  166. else
  167. /etc/init.d/cgconfig start
  168. update-rc.d cgconfig defaults
  169. echo .. done
  170. fi
  171. echo ""
  172. # Activate KVM kernel module
  173. if [ "$qemu" != 1 ]; then
  174. echo Activating KVM kernel module ..
  175. modprobe kvm-intel || modprobe kvm-amd
  176. /sbin/lsmod | grep kvm >/dev/null
  177. if [ "$?" != 0 ]; then
  178. echo .. kernel module did not load successfully
  179. exit 1
  180. fi
  181. sleep 5
  182. if [ ! -e /dev/kvm ]; then
  183. echo .. KVM device file /dev/kvm is missing
  184. exit 1
  185. fi
  186. echo .. done
  187. echo ""
  188. fi
  189. # Create loop devices if missing
  190. echo Creating /dev/loop devices ..
  191. for loop in 0 1 2 3 4 5 6 7; do
  192. if [ ! -r "/dev/loop$loop" ]; then
  193. mknod "/dev/loop$loop" b 7 $loop
  194. fi
  195. done
  196. echo .. done
  197. echo ""
  198. # APT install webmin, theme and Cloudmin
  199. echo Installing Cloudmin packages using APT ..
  200. apt-get -y install webmin
  201. apt-get -y install webmin-server-manager webmin-virtual-server-theme
  202. if [ "$?" != 0 ]; then
  203. echo .. install failed
  204. exit 1
  205. fi
  206. mkdir -p /xen
  207. echo .. done
  208. echo ""
  209. # Configure Webmin to use theme
  210. echo Configuring Webmin ..
  211. grep -v "^preroot=" /etc/webmin/miniserv.conf >/tmp/miniserv.conf.$$
  212. echo preroot=authentic-theme >>/tmp/miniserv.conf.$$
  213. cat /tmp/miniserv.conf.$$ >/etc/webmin/miniserv.conf
  214. rm -f /tmp/miniserv.conf.$$
  215. grep -v "^theme=" /etc/webmin/config >/tmp/config.$$
  216. echo theme=authentic-theme >>/tmp/config.$$
  217. cat /tmp/config.$$ >/etc/webmin/config
  218. rm -f /tmp/config.$$
  219. /etc/webmin/restart
  220. echo .. done
  221. echo ""
  222. # Setup BIND zone for virtual systems
  223. basezone=`hostname -d`
  224. if [ "$basezone" = "" ]; then
  225. basezone=example.com
  226. fi
  227. zone="cloudmin.$basezone"
  228. echo Creating DNS zone $zone ..
  229. /usr/share/webmin/server-manager/setup-bind-zone.pl --zone $zone --auto-view
  230. if [ "$?" != 0 ]; then
  231. echo .. failed
  232. else
  233. echo kvm_zone=$zone >>/etc/webmin/server-manager/config
  234. echo kvm_zone=$zone >>/etc/webmin/server-manager/this
  235. echo .. done
  236. fi
  237. echo ""
  238. # Set Qemu mode flag
  239. if [ "$qemu" = 1 ]; then
  240. echo kvm_qemu=1 >>/etc/webmin/server-manager/config
  241. fi
  242. # Enable bridge
  243. if [ "$nobridge" = "" ]; then
  244. echo Creating network bridge ..
  245. /usr/share/webmin/server-manager/setup-kvm-bridge.pl $interface
  246. brex=$?
  247. if [ "$brex" = 0 ]; then
  248. echo .. already configured
  249. else
  250. if [ "$brex" = 1 ]; then
  251. echo .. done
  252. else
  253. echo .. bridge creation failed
  254. fi
  255. fi
  256. echo ""
  257. fi
  258. # Open Webmin firewall port
  259. echo Opening port 10000 on host firewall ..
  260. /usr/share/webmin/firewall/open-ports.pl 10000 10001 10002 10003 10004 10005 843
  261. if [ "$?" != 0 ]; then
  262. echo .. failed
  263. else
  264. echo .. done
  265. fi
  266. echo ""
  267. # Tell user about need to reboot
  268. hostname=`hostname`
  269. if [ "$brex" = 1 ]; then
  270. echo Cloudmin GPL has been successfully installed. However, you will
  271. echo need to reboot to activate the network bridge before any KVM
  272. echo instances can be created.
  273. echo
  274. echo One this is done, you can login to Cloudmin at :
  275. echo https://$hostname:10000/
  276. else
  277. echo Cloudmin GPL has been successfully installed.
  278. echo
  279. echo You can login to Cloudmin at :
  280. echo https://$hostname:10000/
  281. fi
  282. # All done!