vbuilder.sh.in 17 KB

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