summaryrefslogtreecommitdiff
path: root/localqemubuilder-create
blob: 4ed389b79dc8f24719220e9033df6e2d2a60583c (plain)
  1. #!/bin/sh
  2. #
  3. # Copyright © 2006-2009 Jonas Smedegaard <dr@jones.dk>
  4. # Description: Create QEMU environment
  5. #
  6. # This program is free software; you can redistribute it and/or modify
  7. # it under the terms of the GNU General Public License as published by
  8. # the Free Software Foundation; either version 2, or (at your option)
  9. # any later version.
  10. #
  11. # This program is distributed in the hope that it will be useful, but
  12. # WITHOUT ANY WARRANTY; without even the implied warranty of
  13. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  14. # General Public License for more details.
  15. #
  16. # You should have received a copy of the GNU General Public License
  17. # along with this program; if not, write to the Free Software
  18. # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
  19. # 02111-1307 USA.
  20. #
  21. # Depends: qemu, sudo
  22. set -e
  23. PRG=$(basename "$0")
  24. showhelp() {
  25. cat <<EOF
  26. Usage: $PRG POOL [ DISTRIBUTION [ OTHERMIRROR] ]
  27. Examples:
  28. $PRG sid
  29. $PRG sid+mm sid 'deb http://debian-multimedia.org/ sid main'
  30. $PRG sid-ia32 sid --arch i386
  31. EOF
  32. }
  33. exit1() {
  34. echo "ERROR: $1"
  35. exit 1
  36. }
  37. ask() {
  38. echo -n "$1 (y/N)? "
  39. read response
  40. case "$response" in
  41. y|Y)
  42. :
  43. ;;
  44. *)
  45. return 1
  46. ;;
  47. esac
  48. return
  49. }
  50. if [ $# -eq 0 ]; then
  51. showhelp
  52. exit1 "not enough parameters"
  53. fi
  54. pool=
  55. distro=
  56. arch=
  57. newline='
  58. '
  59. while [ $# -gt 0 ]; do
  60. case $1 in
  61. -h|--help)
  62. showhelp
  63. exit 0
  64. ;;
  65. --arch|-a)
  66. arch="$2"
  67. shift 2 || exit1 "option \"--arg\" requires an argument"
  68. ;;
  69. --)
  70. shift
  71. break
  72. ;;
  73. --*|-*)
  74. # opts="$opts $1"
  75. # shift
  76. exit1 "options (apart from --arch) are curently unsupported"
  77. ;;
  78. *)
  79. if [ -z "$pool" ]; then
  80. pool="$1"
  81. elif [ -z "$distro" ]; then
  82. distro="$1"
  83. else
  84. othermirrors="${othermirrors:+$othermirrors$newline}$1"
  85. fi
  86. shift
  87. ;;
  88. esac
  89. done
  90. if [ -z "$pool" ]; then
  91. exit1 "no pool provided"
  92. fi
  93. if [ -z "$distro" ]; then
  94. distro="$pool"
  95. fi
  96. case $arch in
  97. armel)
  98. # kernelurl="http://yoush.homelinux.org:8079/nikita/armel-qemubuilder/vmlinuz-2.6.26-versatile-qemu"
  99. # kernelref="http://yoush.homelinux.org:8079/tech/setting-up-armel-qemubuilder"
  100. kernelurl="http://people.debian.org/~aurel32/qemu/armel/vmlinuz-2.6.26-1-versatile"
  101. initrdurl="http://people.debian.org/~aurel32/qemu/armel/initrd.img-2.6.26-1-versatile"
  102. kernelref="http://people.debian.org/~aurel32/qemu/armel/"
  103. ;;
  104. mipsel)
  105. kernelurl="http://people.debian.org/~aurel32/qemu/mipsel/vmlinux-2.6.26-1-4kc-malta"
  106. kernelref="http://people.debian.org/~aurel32/qemu/mipsel/"
  107. ;;
  108. *)
  109. exit1 "unsupported architecture: \"$arch\""
  110. ;;
  111. esac
  112. basepath="/var/cache/pbuilder/base-$pool.qemu"
  113. aptcache=""
  114. buildresult="$HOME/src/pbuild-$pool/"
  115. qemudir="/var/cache/pbuilder/qemu-$pool/"
  116. makepaths=''
  117. for path in "$buildresult" "$qemudir"; do
  118. if [ ! -d "$path" ]; then
  119. echo "W: Needed path \"$path\" does not exist"
  120. makepaths='yes'
  121. fi
  122. done
  123. if [ "$makepaths" = 'yes' ]; then
  124. [ "$force" = 'yes' ] \
  125. || ask 'Create the missing path(s)' \
  126. || exit1 "Cannot continue without those missing paths"
  127. mkdir -p "$buildresult"
  128. sudo mkdir -p "$qemudir"
  129. fi
  130. if [ -f "$basepath" ]; then
  131. echo "W: Needed path \"$basepath\" already exists"
  132. [ "$force" = 'yes' ] \
  133. || ask 'Remove the path' \
  134. || exit1 "Cannot continue with that path already there"
  135. sudo rm "$basepath"
  136. fi
  137. for url in $kernelurl $initrdurl; do
  138. file="$qemudir/$(basename $url)"
  139. if [ -f "$file" ]; then
  140. echo "W: file \"$file\" already exists"
  141. if [ "$force" = 'yes' ] || ask 'Replace old file'; then
  142. sudo rm "$file"
  143. fi
  144. fi
  145. done
  146. for url in $kernelurl $initrdurl; do
  147. file="$qemudir/$(basename $url)"
  148. if ! [ -f "$qemudir/$kernel" ]; then
  149. sudo wget -O "$file" "$kernelurl"
  150. fi
  151. done
  152. if [ -f "$qemudir/cfg" ]; then
  153. echo "W: Configfile \"$qemydir/cfg\" already exists"
  154. if [ "$force" = 'yes' ] || ask 'Overwrite old config'; then
  155. sudo rm "$qemudir/cfg"
  156. fi
  157. fi
  158. if ! [ -f "$qemudir/cfg" ]; then
  159. sudo sh -c "cat >\"$qemudir/cfg\"" <<EOF
  160. # kernel origin: $kernelurl
  161. # more info: $kernelref
  162. ARCH=$arch
  163. MEMORY_MEGS=256
  164. ${kernelurl:+KERNEL_IMAGE=$qemudir/$(basename $kernelurl)}
  165. ${initrdurl:+INITRD=$qemudir/$(basename $initrdurl)}
  166. MIRRORSITE=http://auryn:9999/debian
  167. #ARCH_DISKDEVICE=sd
  168. EOF
  169. fi
  170. if [ -n "$othermirrors" ]; then
  171. echo "$othermirrors" | perl -e "while (<>) {/\w/ and unshift @m, '--othermirror', \$_};"\
  172. "exec 'sudo', 'qemubuilder', '--create', '--buildresult', '$buildresult', '--distribution', '$distro', '--basepath', '$basepath', '--aptcache', '$aptcache', '--configfile', '$qemudir/cfg', @m"
  173. else
  174. perl -e "exec 'sudo', 'qemubuilder', '--create', '--buildresult', '$buildresult', '--distribution', '$distro', '--basepath', '$basepath', '--aptcache', '$aptcache', '--configfile', '$qemudir/cfg'"
  175. fi