vbuilder.sh.in 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677
  1. #!/bin/bash
  2. # -*- coding: utf-8-unix -*-
  3. Usage_C(){
  4. cat<<EOF
  5. Usage: $(basename $0) {--version [version]} {--arch [arch]} {--dist-upgrade} {--target [target]} {--with-compat32} {--build|--clean|--build-rpm [src.rpm]|--install-rpm [arch.rpm|package]|--remove-rpm [package]}
  6. Options:
  7. --version: set [version] (default: ${DEFAULT_VERSION})
  8. --arch: set [arch] (default: $(uname -i))
  9. --dist-upgrade: make VineSeed bootstrap via ${STABLE_VERSION}
  10. --unionfs cover a bootstrap with unionfs
  11. --target: build rpms with [target]
  12. --with-compat32: build rpms with compat32 on boostrap
  13. Actions:
  14. --clean: clean boostrap of [version]
  15. --build: build boostrap of [version]
  16. --build-rpm: build [src.rpm] on boostrap
  17. --install-rpm: install [arch.rpm|package] on boostrap
  18. --remove-rpm: remove [package] on boostrap
  19. For example,
  20. * make a clean/plain build environment on the current archtecture:
  21. $(basename $0) --clean --build
  22. * build rpms from the specified source rpm:
  23. $(basename $0) --build-rpm [src.rpm]
  24. * make a plain build environment for Vine Linux 4.2:
  25. $(basename $0) --version 4.2 --clean --build
  26. * make a i386 chroot on x86_64:
  27. $(basename $0) --arch i386 --clean --build
  28. * build a kernel package with target i686
  29. $(basename $0) --target i686 --build-rpm [kernel src.rpm]
  30. * build a compat32 package:
  31. $(basename $0) --arch i386 --with-compat32 --build-rpm [src.rpm]
  32. $(/usr/sbin/vbootstrap | sed -e s/^Usage:.*// -e s/^E:.*//)
  33. EOF
  34. }
  35. Usage_ja(){
  36. Usage_C
  37. }
  38. Msg_MissingParameter_C(){
  39. para=$1
  40. cat<<EOF
  41. E: Missing some parameters after ${para}
  42. EOF
  43. }
  44. Msg_MissingParameter_ja(){
  45. para=$1
  46. cat<<EOF
  47. E: ${para} 以後のいくつかのパラメータに間違いがあります
  48. EOF
  49. }
  50. Msg_NoSupportVARCH_C(){
  51. cat<<EOF
  52. E: arch ${VARCH} is NOT supported on $(uname -i)
  53. EOF
  54. }
  55. Msg_NoSupportVARCH_ja(){
  56. cat<<EOF
  57. E: ${VARCH} アーキテクチャは $(uname -i) 上で非サポートです
  58. EOF
  59. }
  60. Msg_NoSupportVERSION_C(){
  61. cat<<EOF
  62. E: ${VERSION} is NOT supported
  63. EOF
  64. }
  65. Msg_NoSupportVERSION_ja(){
  66. cat<<EOF
  67. E: バージョン ${VERSION} は非サポートです
  68. EOF
  69. }
  70. Msg_NoSupportDistUpgradeVERSION_C(){
  71. cat<<EOF
  72. E: version ${VERSION} does not support --dist-upgrade option
  73. EOF
  74. }
  75. Msg_NoSupportDistUpgradeVERSION_ja(){
  76. cat<<EOF
  77. E: バージョン ${VERSION} では --dist-upgrade オプションはサポートされていません
  78. EOF
  79. }
  80. Msg_NoSupportTARGET_C(){
  81. cat<<EOF
  82. E: rpm build target ${TARGET} is NOT supported
  83. EOF
  84. }
  85. Msg_NoSupportTARGET_ja(){
  86. cat<<EOF
  87. E: rpm ビルドターゲット ${TARGET} はサポートされていません
  88. EOF
  89. }
  90. Msg_NotPackageName_C(){
  91. cat<<EOF
  92. E: $RPM_PKG is not a package name
  93. EOF
  94. }
  95. Msg_NotPackageName_ja(){
  96. cat<<EOF
  97. E: $RPM_PKG はパッケージ名でありません
  98. EOF
  99. }
  100. Msg_NotSourceRPM_C(){
  101. cat<<EOF
  102. E: $RPM_PKG is not a source RPM package
  103. EOF
  104. }
  105. Msg_NotSourceRPM_ja(){
  106. cat<<EOF
  107. E: $RPM_PKG はソース RPM パッケージでありません
  108. EOF
  109. }
  110. ##############################################################################
  111. check-parameter(){
  112. if [ -z "$*" ]; then
  113. Usage_$LOCALE
  114. return 1
  115. fi
  116. while [ ! -z "$*" ]; do
  117. case $1 in
  118. --version|--arch|--target|--build-rpm|--install-rpm|--remove-rpm)
  119. shift
  120. check-next-parameter $1 || return 1
  121. ;;
  122. --dist-upgrade|--unionfs|--with-compat32|--build|--clean)
  123. ;;
  124. *)
  125. Msg_MissingParameter_$LOCALE $1
  126. return 1
  127. ;;
  128. esac
  129. shift
  130. done
  131. return 0
  132. }
  133. check-next-parameter(){
  134. arg=$1
  135. if [ -z "${arg}" ]; then
  136. Msg_MissingParameter_$LOCALE ${arg}
  137. return 1
  138. fi
  139. if [ $(echo ${arg} | grep '^-') ]; then
  140. Msg_MissingParameter_$LOCALE ${arg}
  141. return 1
  142. fi
  143. return 0
  144. }
  145. setup-vbuilder(){
  146. ## load default settings
  147. if [ -r /etc/vbootstrap/vbuilder.conf ]; then
  148. . /etc/vbootstrap/vbuilder.conf
  149. fi
  150. [ -z "${VBOOTSTRAP_DIR}" ] && \
  151. VBOOTSTRAP_DIR=@@VBUILDER_VBOOTSTRAP_DIR@@
  152. [ -z "${DEFAULT_VERSION}" ] && \
  153. DEFAULT_VERSION=@@VBUILDER_DEFAULT_VERSION@@
  154. [ -z "${BUILT_RPMS_DIR}" ] && \
  155. BUILT_RPMS_DIR=@@VBUILDER_BUILT_RPMS_DIR@@
  156. [ -d $VBOOTSTRAP_DIR ] || mkdir -p $VBOOTSTRAP_DIR
  157. VERSION=$DEFAULT_VERSION
  158. ## current stable relase version
  159. STABLE_VERSION=@@VBUILDER_STABLE_VERSION@@
  160. ## set locale
  161. case $LANG in
  162. ja*) LOCALE=ja ;;
  163. *) LOCALE=C ;;
  164. esac
  165. ## set boolian
  166. with_setup_vbootstrap=0
  167. with_unionfs=0
  168. with_dist_upgrade=0
  169. }
  170. setup-vbootstrap(){
  171. if [ ${with_setup_vbootstrap} -eq 0 ]; then
  172. with_setup_vbootstrap=1
  173. ## check a chroot archtecture
  174. if [ ! -z ${VARCH} ]; then
  175. case "${VARCH}" in
  176. i386)
  177. [ "$(uname -i)" = "ppc" ] && \
  178. Msg_NoSupportVARCH_$LOCALE
  179. [ $? -eq 0 ] && exit 1
  180. ;;
  181. i686)
  182. [ "$(uname -i)" = "ppc" ] && \
  183. Msg_NoSupportVARCH_$LOCALE
  184. [ $? -eq 0 ] && exit 1
  185. ;;
  186. x86_64)
  187. [ "$(uname -i)" = "ppc" ] && \
  188. Msg_NoSupportVARCH_$LOCALE
  189. [ $? -eq 0 ] && exit 1
  190. ;;
  191. ppc)
  192. [ "$(uname -i)" = "i386" -o "$(uname -i)" = "i686" -o "$(uname -i)" = "x86_64" ] && \
  193. Msg_NoSupportVARCH_$LOCALE
  194. [ $? -eq 0 ] && exit 1
  195. ;;
  196. esac
  197. fi
  198. [ -z ${VARCH} ] && VARCH=$(uname -i)
  199. ##!! 4.2 is NO support on VARCH=x86_64
  200. if [ "${VERSION}" = "4.2" -a "${VARCH}" = "x86_64" ]; then
  201. Msg_NoSupportVERSION_${LOCALE}
  202. exit 1
  203. fi
  204. ## support i386 chroot on x86_64 below:
  205. [ "${VARCH}" != "$(uname -i)" ] && VERSION=${VERSION}_${VARCH}
  206. ## check support ${VERSION}
  207. if [ -z "$(/usr/sbin/vbootstrap | sed -e s/^Usage:.*// -e s/^E:.*// | grep -m 1 ${VERSION})" ]; then
  208. Msg_NoSupportVERSION_$LOCALE
  209. exit 1
  210. fi
  211. ## check ${VERSION} equals VineSeed*, when with_dist_upgrade=1
  212. if [ $with_dist_upgrade -eq 1 ]; then
  213. if [ "$(echo ${VERSION} | sed -e "s/\(VineSeed\).*/\1/")" != "VineSeed" ]; then
  214. Msg_NoSupportDistUpgradeVERSION_$LOCALE
  215. exit 1
  216. fi
  217. fi
  218. ## check build target option ${TARGET}
  219. if [ ! -z "${TARGET}" ]; then
  220. RPM_TARGET_LIST="$(cat /usr/lib/rpm/rpmrc | grep arch_canon: | sed -e "s/arch_canon:[[:blank:]]*\(.*\):.*/\1/")"
  221. if [ -z "$(echo $RPM_TARGET_LIST | grep $TARGET)" ]; then
  222. Msg_NoSupportTARGET_$LOCALE
  223. exit 1
  224. fi
  225. fi
  226. fi
  227. MAJOR_VERSION=$(echo ${VERSION} | sed -e "s/_i[0-9]86//")
  228. BUILD_ROOT=${VBOOTSTRAP_DIR}/${VERSION}
  229. BUILD_USER=vbuilder
  230. BUILD_DIR=/home/${BUILD_USER}/rpm
  231. ARCHIVES_DIR=${BUILD_ROOT}/var/cache/apt/archives
  232. CACHE_DIR=${VBOOTSTRAP_DIR}/cache/${VERSION}/apt/archives
  233. UNIONFS_DIR=${VBOOTSTRAP_DIR}/unionfs/${VERSION}
  234. __chroot_sh="/usr/sbin/chroot ${BUILD_ROOT} /bin/sh -c"
  235. mkdir -p $VBOOTSTRAP_DIR
  236. }
  237. setup-vbootstrap-rpm(){
  238. setup-vbootstrap
  239. ## check ${BUILD_ROOT}
  240. [ -d ${BUILD_ROOT} ] || Build
  241. DIST_RELEASE=$(cat ${BUILD_ROOT}/etc/vine-release | cut -f3 -d" " | cut -f1 -d.)
  242. if [ -f $RPM_PKG ]; then
  243. BASE_RPM_PKG=$(basename $RPM_PKG)
  244. cp -f $RPM_PKG $BUILD_ROOT${BUILD_DIR}
  245. else
  246. BASE_RPM_PKG=$RPM_PKG
  247. fi
  248. }
  249. ## recover apt-get data on host/chroot
  250. apt-get-update(){
  251. case $1 in
  252. --host)
  253. echo -n "apt-get update on host ... "
  254. apt-get -qq update > /dev/null 2>&1
  255. echo "done."
  256. ;;
  257. --chroot)
  258. echo -n "apt-get update on chroot ... "
  259. $__chroot_sh 'apt-get -qq update' > /dev/null 2>&1
  260. echo "done."
  261. ;;
  262. *)
  263. echo apt-get-update: unknown option $1
  264. exit 1
  265. ;;
  266. esac
  267. }
  268. ## mount-chroot {|--umount} [file system|name]
  269. ## support file systems: /home /tmp /sys /proc /dev/shm /dev/pts /dev
  270. ## support name: vfs chache_dir
  271. ## NOTE: /tmp needs for applications which use X
  272. ## vfs is virtual file systems
  273. ## cache_dir is ${CACHE_DIR} to ${ARCHIVES_DIR}
  274. mount-chroot(){
  275. if [ "$1" = "--umount" ]; then
  276. mount-chroot-umount $2 || return 1
  277. else
  278. mount-chroot-mount $1 || return 1
  279. fi
  280. return 0
  281. }
  282. ## mount-chroot-umount [file system|name]
  283. mount-chroot-umount(){
  284. local fs=$1
  285. case $fs in
  286. /home|/tmp|/sys|/proc|/dev/shm|/dev/pts|/dev)
  287. [ -d ${BUILD_ROOT}${fs} ] || return 1
  288. [ -z "$(mount | grep ${BUILD_ROOT}${fs})" ] || \
  289. umount ${BUILD_ROOT}${fs}
  290. return 0
  291. ;;
  292. vfs)
  293. # for dir in /sys /proc /dev/shm /dev/pts /dev; do
  294. # mount-chroot-umount ${dir} || return 1
  295. # done
  296. [ -d ${BUILD_ROOT}/proc ] || return 1
  297. [ -z "$(mount | grep ${BUILD_ROOT}/proc)" ] || \
  298. umount ${BUILD_ROOT}/proc
  299. return 0
  300. ;;
  301. cache_dir)
  302. [ -d ${ARCHIVES_DIR} ] || return 1
  303. [ -z "$(mount | grep ${ARCHIVES_DIR})" ] || \
  304. umount ${ARCHIVES_DIR}
  305. return 0
  306. ;;
  307. unionfs_dir)
  308. [ -d ${BUILD_ROOT} ] || return 1
  309. [ -z "$(mount | grep ${BUILD_ROOT} | grep unionfs)" ] || \
  310. umount ${BUILD_ROOT}
  311. if [ ! -z "$(mount | grep ${BUILD_ROOT} | grep unionfs)" ]; then
  312. echo "Retry lazy unmount ... "
  313. umount -l ${BUILD_ROOT}
  314. echo "done."
  315. fi
  316. return 0
  317. ;;
  318. *)
  319. echo mount-chroot-umount: unknown file system $fs
  320. exit 1
  321. ;;
  322. esac
  323. }
  324. ## mount-chroot-mount [file system|name]
  325. mount-chroot-mount(){
  326. local fs=$1
  327. local mnt_opts=""
  328. case $fs in
  329. /home)
  330. mnt_opts="-o rbind"
  331. ;;
  332. *)
  333. mnt_opts="--bind"
  334. ;;
  335. esac
  336. case $fs in
  337. /home|/tmp|/sys|/proc|/dev/shm|/dev/pts|/dev)
  338. [ -d ${BUILD_ROOT}${fs} ] || mkdir -p ${BUILD_ROOT}${fs}
  339. [ -z "$(mount | grep ${BUILD_ROOT}${fs})" ] && \
  340. mount ${mnt_opts} ${fs} ${BUILD_ROOT}${fs}
  341. return 0
  342. ;;
  343. vfs)
  344. # for dir in /dev /dev/pts /dev/shm /proc /sys; do
  345. # mount-chroot-mount ${dir} || return 1
  346. # done
  347. mount-chroot-mount /proc || return 1
  348. return 0
  349. ;;
  350. cache_dir)
  351. [ -d ${CACHE_DIR} ] || mkdir -p ${CACHE_DIR}
  352. [ -d ${ARCHIVES_DIR} ] || mkdir -p ${ARCHIVES_DIR}
  353. [ -z "$(mount | grep ${ARCHIVES_DIR})" ] && \
  354. mount ${mnt_opts} ${CACHE_DIR} ${ARCHIVES_DIR}
  355. [ -d ${ARCHIVES_DIR}/partial ] || mkdir -p ${ARCHIVES_DIR}/partial
  356. return 0
  357. ;;
  358. unionfs_dir)
  359. if [ $with_unionfs -eq 1 ]; then
  360. [ -d ${UNIONFS_DIR} ] || mkdir -p ${UNIONFS_DIR}
  361. [ -z "$(mount | grep ${BUILD_ROOT})" ] && \
  362. mount -t unionfs -o dirs=${UNIONFS_DIR}=rw:${BUILD_ROOT}=ro unionfs ${BUILD_ROOT}
  363. unionctl ${BUILD_ROOT} --list
  364. fi
  365. return 0
  366. ;;
  367. *)
  368. echo mount-chroot-mount: unknown file system $fs
  369. exit 1
  370. ;;
  371. esac
  372. }
  373. ##############################################################################
  374. Clean(){
  375. setup-vbootstrap
  376. # mount-chroot --umount /home
  377. # mount-chroot --umount /tmp
  378. mount-chroot --umount vfs
  379. mount-chroot --umount cache_dir
  380. mount-chroot --umount unionfs_dir
  381. apt-get-update --host
  382. if [ $with_unionfs -eq 1 ]; then
  383. if [ -d ${UNIONFS_DIR} ]; then
  384. echo -n "Cleaning build root \"${UNIONFS_DIR}\" via unionfs ... "
  385. rm -rf ${UNIONFS_DIR}
  386. echo "done."
  387. fi
  388. else
  389. if [ -d ${BUILD_ROOT} ]; then
  390. echo -n "Cleaning build root \"${BUILD_ROOT}\" ... "
  391. rm -rf ${BUILD_ROOT}
  392. echo "done."
  393. fi
  394. fi
  395. echo "Cleanup a build farm for ${VERSION} done."
  396. }
  397. Retry_vbootstrap-post(){
  398. local CHROOT_DIST_RELEASE=$(cat ${BUILD_ROOT}/etc/vine-release | cut -f3 -d" " | cut -f1 -d.)
  399. local DIST_RELEASE=$(cat /etc/vine-release | cut -f3 -d" " | cut -f1 -d.)
  400. if [ "${CHROOT_DIST_RELEASE}" != "${DIST_RELEASE}" ]; then
  401. . /usr/share/vbootstrap/scripts/${VERSION}
  402. $__chroot_sh "rm /var/lib/rpm/*"
  403. $__chroot_sh "rpmdb --initdb"
  404. $__chroot_sh "apt-get -qq update"
  405. $__chroot_sh "apt-get -qq -y install ${BASE_PKGS}"
  406. fi
  407. }
  408. Build(){
  409. setup-vbootstrap
  410. if [ $with_dist_upgrade -eq 1 ]; then
  411. ## make bootstrap of ${STABLE_VERSION}
  412. /usr/sbin/vbootstrap \
  413. $(echo ${VERSION} | sed -e "s/VineSeed/${STABLE_VERSION}/") \
  414. ${BUILD_ROOT}
  415. ## aim apt-line to VineSeed
  416. sed -i "s/apt ${STABLE_VERSION}/apt VineSeed/g" \
  417. ${BUILD_ROOT}/etc/apt/sources.list.d/main.list
  418. else
  419. /usr/sbin/vbootstrap ${VERSION} ${BUILD_ROOT}
  420. fi
  421. ## retry vbootstrap post in Build()
  422. Retry_vbootstrap-post
  423. mount-chroot cache_dir
  424. mount-chroot vfs
  425. # mount-chroot /tmp
  426. # mount-chroot /home
  427. $__chroot_sh 'apt-get -qq update && apt-get -qq -y dist-upgrade'
  428. ##!! 4.2 has no apt-sourceslist-{plus,nonfree} packages
  429. if [ "${MAJOR_VERSION}" != "4.2" ]; then
  430. $__chroot_sh 'apt-get -qq update && apt-get -qq -y install apt-sourceslist-plus'
  431. $__chroot_sh 'apt-get -qq update && apt-get -qq -y install apt-sourceslist-nonfree'
  432. fi
  433. if [ $with_dist_upgrade -eq 1 ]; then
  434. $__chroot_sh 'apt-get -qq update && apt-get -qq -y dist-upgrade'
  435. fi
  436. $__chroot_sh 'apt-get -qq -y install build-essential'
  437. $__chroot_sh 'apt-get -qq -y install self-build-setup'
  438. $__chroot_sh 'apt-get -qq -y install etcskel shadow-utils'
  439. $__chroot_sh 'cd /dev && /sbin/MAKEDEV console'
  440. $__chroot_sh 'cd /dev && /sbin/MAKEDEV null'
  441. $__chroot_sh 'cd /dev && /sbin/MAKEDEV zero'
  442. $__chroot_sh '/usr/sbin/pwconv'
  443. $__chroot_sh "/usr/sbin/useradd ${BUILD_USER}"
  444. ##!! for rpm-4.8.0 or higher
  445. ##!! (See http://trac.vinelinux.org/wiki/Vine6/AboutUpdateToolchain)
  446. if [ "$(echo ${VERSION} | sed -e "s/\(VineSeed\).*/\1/")" = "VineSeed" ]; then
  447. $__chroot_sh "sed -i -e 's/^%_topdir/#%_topdir/' /home/${BUILD_USER}/.rpmmacros"
  448. fi
  449. # mount-chroot --umount /home
  450. # mount-chroot --umount /tmp
  451. mount-chroot --umount vfs
  452. mount-chroot --umount cache_dir
  453. apt-get-update --host
  454. echo "Making a build farm for ${VERSION} done."
  455. }
  456. RPM_Remove(){
  457. setup-vbootstrap-rpm
  458. mount-chroot unionfs_dir
  459. mount-chroot cache_dir
  460. mount-chroot vfs
  461. if [ -f $RPM_PKG ]; then
  462. Msg_NotPackageName_$LOCALE
  463. exit 1
  464. fi
  465. $__chroot_sh "apt-get -y remove $BASE_RPM_PKG"
  466. mount-chroot --umount vfs
  467. mount-chroot --umount cache_dir
  468. mount-chroot --umount unionfs_dir
  469. apt-get-update --host
  470. }
  471. RPM_Install(){
  472. setup-vbootstrap-rpm
  473. mount-chroot unionfs_dir
  474. mount-chroot cache_dir
  475. mount-chroot vfs
  476. apt-get-update --chroot
  477. $__chroot_sh "cd ${BUILD_DIR} && apt-get -y install $BASE_RPM_PKG"
  478. mount-chroot --umount vfs
  479. mount-chroot --umount cache_dir
  480. mount-chroot --umount unionfs_dir
  481. apt-get-update --host
  482. }
  483. RPM_Build(){
  484. setup-vbootstrap-rpm
  485. mount-chroot unionfs_dir
  486. mount-chroot cache_dir
  487. mount-chroot vfs
  488. if [ ! -f $RPM_PKG ]; then
  489. Msg_NotSourceRPM_$LOCALE
  490. exit 1
  491. fi
  492. RPM_PKG_USER=$(stat -c %U $RPM_PKG)
  493. RPM_PKG_GROUP=$(stat -c %G $RPM_PKG)
  494. local __install="install -p -v -o ${RPM_PKG_USER} -g ${RPM_PKG_GROUP}"
  495. RPM_PKG_ARCH_LIST="RPMS/i386 RPMS/i686 RPMS/x86_64 RPMS/ppc RPMS/noarch SRPMS"
  496. [ -z "${TARGET}" ] || \
  497. RPM_PKG_ARCH_LIST="RPMS/${TARGET} ${RPM_PKG_ARCH_LIST}"
  498. ## make src.rpm for $VERSION
  499. $__chroot_sh "cd ${BUILD_DIR} && su ${BUILD_USER} -c 'rpm -ivh $BASE_RPM_PKG'"
  500. $__chroot_sh "cd ${BUILD_DIR} && su ${BUILD_USER} -c 'rpmbuild -bs --nodeps --clean --rmsource --rmspec ${BUILD_DIR}/SPECS/*.spec'"
  501. ## change ${DIST_RELEASE}
  502. BASE_RPM_PKG=$(echo $BASE_RPM_PKG | sed -e "s/vl\([0-9]*\)\./vl${DIST_RELEASE}\./")
  503. ## rebuild $BASE_RPM_PKG on ${DIST_RELEASE}
  504. $__chroot_sh "cd ${BUILD_DIR}/SRPMS && apt-get -y build-dep $BASE_RPM_PKG"
  505. $__chroot_sh "cd ${BUILD_DIR}/SRPMS && su ${BUILD_USER} -c 'rpmbuild --rebuild $RPM_OPTS $BASE_RPM_PKG'"
  506. $__chroot_sh "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|.*\/.*\.src\.rpm||g' -e 's/$/ \\/g')"
  507. ## copy built rpms to ${HOME}/rpm/ for each archtectures
  508. echo "Copying built rpms to ${HOME}/rpm/ for each archtectures ... "
  509. for i in $RPM_PKG_ARCH_LIST; do \
  510. if [ -d $BUILD_ROOT${BUILD_DIR}/${i} ]; then
  511. [ -d ${BUILT_RPMS_DIR}/${MAJOR_VERSION}/${i} ] || \
  512. $__install -d ${BUILT_RPMS_DIR}/${MAJOR_VERSION}/${i}/
  513. find $BUILD_ROOT${BUILD_DIR}/${i} -type f -regex '.*\.rpm' \
  514. -exec $__install -m0644 {} ${BUILT_RPMS_DIR}/${MAJOR_VERSION}/${i}/ \;
  515. fi
  516. done
  517. mount-chroot --umount vfs
  518. mount-chroot --umount cache_dir
  519. mount-chroot --umount unionfs_dir
  520. apt-get-update --host
  521. echo "done."
  522. }
  523. ##############################################################################
  524. setup-vbuilder
  525. check-parameter $* || exit 1
  526. while [ $# -gt 0 ]; do
  527. tmpARG=$1
  528. case $tmpARG in
  529. --version|--arch|--target|--build-rpm|--install-rpm|--remove-rpm)
  530. shift
  531. ;;
  532. --dist-upgrade|--unionfs|--with-compat32|--build|--clean)
  533. ;;
  534. *)
  535. echo unknown option $1
  536. exit 1
  537. ;;
  538. esac
  539. case $tmpARG in
  540. --version)
  541. VERSION=$1
  542. ;;
  543. --arch)
  544. VARCH=$1
  545. ;;
  546. --dist-upgrade)
  547. with_dist_upgrade=1
  548. ;;
  549. --unionfs)
  550. with_unionfs=1
  551. ;;
  552. --target)
  553. TARGET=$1
  554. RPM_OPTS="${RPM_OPTS} --target $TARGET"
  555. ;;
  556. --with-compat32)
  557. RPM_OPTS="${RPM_OPTS} --with compat32"
  558. ;;
  559. --build-rpm)
  560. RPM_PKG=$1
  561. RPM_Build || exit 1
  562. ;;
  563. --install-rpm)
  564. RPM_PKG=$1
  565. RPM_Install || exit 1
  566. ;;
  567. --remove-rpm)
  568. RPM_PKG=$1
  569. RPM_Remove || exit 1
  570. ;;
  571. --build)
  572. Build
  573. ;;
  574. --clean)
  575. Clean
  576. ;;
  577. esac
  578. shift
  579. done
  580. exit