vbuilder.sh.in 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312
  1. #!/bin/bash
  2. # -*- coding: utf-8-unix -*-
  3. Usage_C(){
  4. cat<<EOF
  5. Usage: $(basename $0) {--version [version]} {--arch [arch]} {--build-rpm [src.rpm]|--install-rpm [arch.rpm]|--remove-rpm [package]|--build|--clean}
  6. --version: set [version] (default: ${DEFAULT_VERSION})
  7. --arch: set [arch] (default: $(uname -i))
  8. --build-rpm: build [src.rpm] on boostrap
  9. --install-rpm: install [arch.rpm] on boostrap
  10. --remove-rpm: remove [package] on boostrap
  11. --build: build boostrap of [version]
  12. --clean: clean boostrap of [version]
  13. For example,
  14. * make a clean/plain build environment on the current archtecture:
  15. $(basename $0) --clean --build
  16. * build source RPM:
  17. $(basename $0) --build-rpm [src.rpm]
  18. * make a plain build environment for Vine Linux 4.2:
  19. $(basename $0) --version 4.2 --clean --build
  20. * make a i386 chroot on x86_64:
  21. $(basename $0) --arch i386 --clean --build
  22. $(/usr/sbin/vbootstrap | sed -e s/^Usage:.*// -e s/^E:.*//)
  23. EOF
  24. }
  25. Usage_ja(){
  26. Usage_C
  27. }
  28. Msg_MissingParameter_C(){
  29. while read para; do
  30. cat<<EOF
  31. E: Missing some parameter before ${para}
  32. EOF
  33. done
  34. }
  35. Msg_MissingParameter_ja(){
  36. Msg_MissingParameter_C
  37. }
  38. Msg_NoSupportVARCH_C(){
  39. cat<<EOF
  40. E: arch ${VARCH} is NO support on $(uname -i)
  41. EOF
  42. }
  43. Msg_NoSupportVARCH_ja(){
  44. Msg_NoSupportVARCH_C
  45. }
  46. Msg_NoSupportVERSION_C(){
  47. cat<<EOF
  48. E: version ${VERSION} is NO support
  49. EOF
  50. }
  51. Msg_NoSupportVERSION_ja(){
  52. Msg_NoSupportVERSION_C
  53. }
  54. ##############################################################################
  55. setup-vbuilder(){
  56. ## load default settings
  57. if [ -d /etc/vbootstrap/vbuilder.conf ]; then
  58. . /etc/vbootstrap/vbuilder.conf
  59. else
  60. [ -z "${VBOOTSTRAP_DIR}" ] && \
  61. VBOOTSTRAP_DIR=@@VBUILDER_VBOOTSTRAP_DIR@@
  62. [ -z "${DEFAULT_VERSION}" ] && \
  63. DEFAULT_VERSION=@@VBUILDER_DEFAULT_VERSION@@
  64. fi
  65. [ -d $VBOOTSTRAP_DIR ] || mkdir -p $VBOOTSTRAP_DIR
  66. VERSION=$DEFAULT_VERSION
  67. ## set locale
  68. case $LANG in
  69. ja*) LOCALE=ja ;;
  70. *) LOCALE=C ;;
  71. esac
  72. }
  73. check-next-parameter(){
  74. while read arg; do
  75. if [ $(echo ${arg} | grep '^-') ]; then
  76. echo ${arg} | Msg_MissingParameter_$LOCALE
  77. return 1
  78. fi
  79. done
  80. }
  81. FLAG_setup_vbootstrap=0
  82. setup-vbootstrap(){
  83. if [ ${FLAG_setup_vbootstrap} -eq 0 ]; then
  84. FLAG_setup_vbootstrap=1
  85. ## check a chroot archtecture
  86. if [ ! -z ${VARCH} ]; then
  87. case "${VARCH}" in
  88. i386)
  89. [ "$(uname -i)" = "ppc" ] && \
  90. Msg_NoSupportVARCH_$LOCALE
  91. [ $? -eq 0 ] && exit 1
  92. ;;
  93. x86_64)
  94. [ "$(uname -i)" = "ppc" ] && \
  95. Msg_NoSupportVARCH_$LOCALE
  96. [ $? -eq 0 ] && exit 1
  97. ;;
  98. ppc)
  99. [ "$(uname -i)" = "i386" -o "$(uname -i)" = "x86_64" ] && \
  100. Msg_NoSupportVARCH_$LOCALE
  101. [ $? -eq 0 ] && exit 1
  102. ;;
  103. esac
  104. fi
  105. [ -z ${VARCH} ] && VARCH=$(uname -i)
  106. ##!! IRREGULAR: 4.2 is NO support on x86_64
  107. if [ "${VERSION}" = "4.2" -a "$(uname -i)" = "x86_64" ]; then
  108. Msg_NoSupportVERSION_${LOCALE}
  109. exit 1
  110. fi
  111. ## support for i386 chroot on x86_64 below:
  112. [ "${VARCH}" != "$(uname -i)" ] && VERSION=${VERSION}_${VARCH}
  113. ## check support ${VERSION}
  114. if [ -z "$(/usr/sbin/vbootstrap | sed -e s/^Usage:.*// -e s/^E:.*// | grep -m 1 ${VERSION})" ]; then
  115. Msg_NoSupportVERSION_$LOCALE
  116. exit 1
  117. fi
  118. fi
  119. BUILD_ROOT=${VBOOTSTRAP_DIR}/${VERSION}
  120. BUILD_USER=vbuilder
  121. CACHE_DIR=${VBOOTSTRAP_DIR}/cache/${VERSION}
  122. BUILD_DIR=/home/${BUILD_USER}/rpm
  123. mkdir -p $VBOOTSTRAP_DIR
  124. }
  125. ##############################################################################
  126. Clean(){
  127. setup-vbootstrap
  128. [ -d ${BUILD_ROOT}/proc ] && \
  129. umount ${BUILD_ROOT}/proc
  130. if [ -d ${BUILD_ROOT}/var/cache/apt/archives ]; then
  131. echo -n "Chaching RPMs in ${CACHE_DIR}/apt/archives ... "
  132. [ -d ${CACHE_DIR}/apt/archives ] || mkdir -p ${CACHE_DIR}/apt/archives
  133. mv -f ${BUILD_ROOT}/var/cache/apt/archives/*.rpm ${CACHE_DIR}/apt/archives/
  134. echo "done."
  135. fi
  136. if [ -d ${BUILD_ROOT} ]; then
  137. echo -n "Cleaning build root \"${BUILD_ROOT}\" ... "
  138. rm -rf ${BUILD_ROOT}
  139. echo "done."
  140. fi
  141. }
  142. Build(){
  143. setup-vbootstrap
  144. /usr/sbin/vbootstrap ${VERSION} ${BUILD_ROOT}
  145. [ -d ${BUILD_ROOT}/proc ] || mkdir -p ${BUILD_ROOT}/proc
  146. mount -t proc proc ${BUILD_ROOT}/proc
  147. if [ -d ${CACHE_DIR} ]; then
  148. echo -n "Copying chached RPMs to ${BUILD_ROOT}/var/cache/apt/archives ... "
  149. cp -f ${CACHE_DIR}/apt/archives/*.rpm ${BUILD_ROOT}/var/cache/apt/archives/
  150. echo "done."
  151. fi
  152. /usr/sbin/chroot ${BUILD_ROOT} \
  153. /bin/sh -c 'apt-get update && apt-get -y dist-upgrade'
  154. /usr/sbin/chroot ${BUILD_ROOT} \
  155. /bin/sh -c 'apt-get -y install apt-sourceslist-plus && apt-get update'
  156. /usr/sbin/chroot ${BUILD_ROOT} \
  157. /bin/sh -c 'apt-get -y install apt-sourceslist-nonfree && apt-get update'
  158. /usr/sbin/chroot ${BUILD_ROOT} \
  159. /bin/sh -c 'apt-get -y install build-essential self-build-setup'
  160. /usr/sbin/chroot ${BUILD_ROOT} \
  161. /bin/sh -c 'apt-get -y install etcskel shadow-utils'
  162. /usr/sbin/chroot ${BUILD_ROOT} /bin/sh -c 'cd /dev && /sbin/MAKEDEV console'
  163. /usr/sbin/chroot ${BUILD_ROOT} /bin/sh -c 'cd /dev && /sbin/MAKEDEV null'
  164. /usr/sbin/chroot ${BUILD_ROOT} /bin/sh -c 'cd /dev && /sbin/MAKEDEV zero'
  165. /usr/sbin/chroot ${BUILD_ROOT} /bin/sh -c '/usr/sbin/pwconv'
  166. /usr/sbin/chroot ${BUILD_ROOT} /bin/sh -c "/usr/sbin/useradd ${BUILD_USER}"
  167. echo "Making a build farm for ${VERSION} done."
  168. }
  169. setup-vbootstrap-rpm(){
  170. setup-vbootstrap
  171. ## check ${BUILD_ROOT}
  172. [ -d ${BUILD_ROOT} ] || Build
  173. if [ -f $RPM_PKG ]; then
  174. BASE_RPM_PKG=$(basename $RPM_PKG)
  175. cp -f $RPM_PKG $BUILD_ROOT${BUILD_DIR}
  176. else
  177. BASE_RPM_PKG=$RPM_PKG
  178. fi
  179. }
  180. RPM_Remove(){
  181. setup-vbootstrap-rpm
  182. if [ -f $RPM_PKG ]; then
  183. echo "$RPM_PKG: not package name."
  184. exit 1
  185. fi
  186. /usr/sbin/chroot ${BUILD_ROOT} \
  187. /bin/sh -c "apt-get -y remove $BASE_RPM_PKG"
  188. }
  189. RPM_Install(){
  190. setup-vbootstrap-rpm
  191. /usr/sbin/chroot ${BUILD_ROOT} \
  192. /bin/sh -c "cd ${BUILD_DIR} && apt-get -y install $BASE_RPM_PKG"
  193. }
  194. RPM_Build(){
  195. setup-vbootstrap-rpm
  196. if [ ! -f $RPM_PKG ]; then
  197. echo "$RPM_PKG: not source RPM package."
  198. exit 1
  199. fi
  200. /usr/sbin/chroot ${BUILD_ROOT} \
  201. /bin/sh -c "cd ${BUILD_DIR} && apt-get -y build-dep $BASE_RPM_PKG"
  202. /usr/sbin/chroot ${BUILD_ROOT} \
  203. /bin/sh -c "cd ${BUILD_DIR} && su ${BUILD_USER} -c 'rpmbuild --rebuild $RPM_OPTS $BASE_RPM_PKG'"
  204. /usr/sbin/chroot ${BUILD_ROOT} \
  205. /bin/sh -c "cd ${BUILD_DIR} && apt-get -y install $(find $BUILD_ROOT${BUILD_DIR}/RPMS -type f -regex '.*\.rpm' | sed -e s@${BUILD_ROOT}@@g -e 's|.*\/compat32-.*||g' -e 's/$/ \\/g')"
  206. }
  207. ##############################################################################
  208. setup-vbuilder
  209. [ $# -eq 0 ] && Usage_$LOCALE
  210. while [ $# -gt 0 ]; do
  211. case "$1" in
  212. --version)
  213. shift;
  214. echo $1 | check-next-parameter
  215. [ $? -eq 1 ] && exit 1
  216. VERSION=$1
  217. ;;
  218. --arch)
  219. shift;
  220. echo $1 | check-next-parameter
  221. [ $? -eq 1 ] && exit 1
  222. VARCH=$1
  223. ;;
  224. ##!! This option is obsolete for 5.0 or above higher version on i386.
  225. --with-compat32)
  226. RPM_OPTS="--with compat32"
  227. ;;
  228. --build-rpm)
  229. shift;
  230. echo $1 | check-next-parameter
  231. [ $? -eq 1 ] && exit 1
  232. RPM_PKG=$1
  233. RPM_Build
  234. ;;
  235. --install-rpm)
  236. shift;
  237. echo $1 | check-next-parameter
  238. [ $? -eq 1 ] && exit 1
  239. RPM_PKG=$1
  240. RPM_Install
  241. ;;
  242. --remove-rpm)
  243. shift;
  244. echo $1 | check-next-parameter
  245. [ $? -eq 1 ] && exit 1
  246. RPM_PKG=$1
  247. RPM_Remove
  248. ;;
  249. --build)
  250. Build
  251. ;;
  252. --clean)
  253. Clean
  254. ;;
  255. *)
  256. Usage_$LOCALE
  257. exit 1
  258. ;;
  259. esac
  260. shift
  261. done
  262. exit