vbuilder.sh.in 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861
  1. #!/bin/bash
  2. # -*- coding: utf-8-unix -*-
  3. Usage_C(){
  4. cat<<EOF
  5. Usage: $(basename $0) {--version [version]} {--arch [arch]} {--category [categories]} {--dist-upgrade} {--target [target]} {--with-compat32} {--bootstrap-dir [directory]} {--cache-dir [directory]} {--built-rpms-dir [directory]} {clean|build|build-rpm [src.rpm]|install-rpm [arch.rpm|package]|remove-rpm [package]|show-info}
  6. Options:
  7. --version: set [version] (default: ${DEFAULT_VERSION})
  8. --arch: set [arch] (default: $(uname -i))
  9. --category: set [categories] (default: ${CATEGORIES})
  10. --dist-upgrade: make VineSeed bootstrap via ${STABLE_VERSION}
  11. --unionfs: cover a bootstrap with unionfs
  12. --target: build rpms with [target]
  13. --with-compat32: build rpms with compat32 on boostrap
  14. --bootstrap-dir: set a bootstrap directory (default: ${VBOOTSTRAP_DIR})
  15. --cache-dir: set a directory to cache rpms (default: ${CACHE_DIR})
  16. --built-rpms-dir: set a directory to store built rpms in chroot (default: ${BUILT_RPMS_DIR})
  17. Actions:
  18. clean: clean the boostrap of [version]
  19. build: build a boostrap of [version]
  20. build-rpm: build [src.rpm] on a boostrap
  21. install-rpm: install [arch.rpm|package] on a boostrap
  22. remove-rpm: remove [package] on a boostrap
  23. show-info: show basic informations and logs in chroot
  24. For example,
  25. * make a clean/plain build environment on the current archtecture:
  26. $(basename $0) --clean --build
  27. * build rpms from the specified source rpm:
  28. $(basename $0) --build-rpm [src.rpm]
  29. * make a plain build environment for Vine Linux 4.2:
  30. $(basename $0) --version 4.2 --clean --build
  31. * make a i386 chroot on x86_64:
  32. $(basename $0) --arch i386 --clean --build
  33. * build a kernel package with target i686
  34. $(basename $0) --target i686 --build-rpm [kernel src.rpm]
  35. * build a compat32 package:
  36. $(basename $0) --arch i386 --with-compat32 --build-rpm [src.rpm]
  37. $(/usr/sbin/vbootstrap | sed -e s/^Usage:.*// -e s/^E:.*//)
  38. EOF
  39. }
  40. Usage_ja(){
  41. Usage_C
  42. }
  43. Msg_MissingParameter_C(){
  44. local para=$1
  45. cat<<EOF
  46. E: Missing some parameters after ${para}
  47. EOF
  48. }
  49. Msg_MissingParameter_ja(){
  50. local para=$1
  51. cat<<EOF
  52. E: ${para} 以後のいくつかの引数に間違いがあります
  53. EOF
  54. }
  55. Msg_NoSuchCategoryExists_C(){
  56. local para=$1
  57. cat<<EOF
  58. E: No such category exists: $para
  59. EOF
  60. }
  61. Msg_NoSuchCategoryExists_ja(){
  62. local para=$1
  63. cat<<EOF
  64. E: そのようなカテゴリは存在しません: $para
  65. EOF
  66. }
  67. Msg_GiveMoreOptions_C(){
  68. cat<<EOF
  69. E: You can give no more options after actions
  70. EOF
  71. }
  72. Msg_GiveNoMoreOptions_ja(){
  73. cat<<EOF
  74. E: 動作の以後にオプションを与えられません
  75. EOF
  76. }
  77. Msg_GiveAtLeastOneAction_C(){
  78. cat<<EOF
  79. E: You must give at least one action
  80. EOF
  81. }
  82. Msg_GiveAtLeastOneAction_ja(){
  83. cat<<EOF
  84. E: 少なくとも1つの動作を与えなければなりません
  85. EOF
  86. }
  87. Msg_NoSupportVARCH_C(){
  88. cat<<EOF
  89. E: arch ${VARCH} is NOT supported on $(uname -i)
  90. EOF
  91. }
  92. Msg_NoSupportVARCH_ja(){
  93. cat<<EOF
  94. E: ${VARCH} アーキテクチャは $(uname -i) 上で非サポートです
  95. EOF
  96. }
  97. Msg_NoSupportVERSION_C(){
  98. cat<<EOF
  99. E: ${VERSION} is NOT supported
  100. EOF
  101. }
  102. Msg_NoSupportVERSION_ja(){
  103. cat<<EOF
  104. E: バージョン ${VERSION} は非サポートです
  105. EOF
  106. }
  107. Msg_NoSupportDistUpgradeVERSION_C(){
  108. cat<<EOF
  109. E: version ${VERSION} does not support --dist-upgrade option
  110. EOF
  111. }
  112. Msg_NoSupportDistUpgradeVERSION_ja(){
  113. cat<<EOF
  114. E: バージョン ${VERSION} では --dist-upgrade オプションはサポートされていません
  115. EOF
  116. }
  117. Msg_NoSupportTARGET_C(){
  118. cat<<EOF
  119. E: rpm build target ${TARGET} is NOT supported
  120. EOF
  121. }
  122. Msg_NoSupportTARGET_ja(){
  123. cat<<EOF
  124. E: rpm ビルドターゲット ${TARGET} はサポートされていません
  125. EOF
  126. }
  127. Msg_NotPackageName_C(){
  128. local RPM_PKG=$1
  129. cat<<EOF
  130. E: $RPM_PKG is not a package name
  131. EOF
  132. }
  133. Msg_NotPackageName_ja(){
  134. local RPM_PKG=$1
  135. cat<<EOF
  136. E: $RPM_PKG はパッケージ名でありません
  137. EOF
  138. }
  139. Msg_NotSourceRPM_C(){
  140. local RPM_PKG=$1
  141. cat<<EOF
  142. E: $RPM_PKG is not a source RPM package
  143. EOF
  144. }
  145. Msg_NotSourceRPM_ja(){
  146. local RPM_PKG=$1
  147. cat<<EOF
  148. E: $RPM_PKG はソース RPM パッケージでありません
  149. EOF
  150. }
  151. ##############################################################################
  152. check-parameter(){
  153. [ -z "$*" ] && Usage_$LOCALE && return 1
  154. while [ ! -z "$*" ]; do
  155. case $1 in
  156. --help|help)
  157. Usage_$LOCALE
  158. return 1
  159. ;;
  160. --version|--arch|--category|--target|--bootstrap-dir|--cache-dir|--built-rpms-dir)
  161. [ $with_actions -eq 1 ] && \
  162. Msg_GiveNoMoreOptions_$LOCALE && return 1
  163. shift
  164. check-next-parameter $1 || return 1
  165. ;;
  166. --dist-upgrade|--unionfs|--with-compat32)
  167. [ $with_actions -eq 1 ] && \
  168. Msg_GiveNoMoreOptions_$LOCALE && return 1
  169. ;;
  170. --build-rpm|build-rpm|--install-rpm|install-rpm|--remove-rpm|remove-rpm)
  171. with_actions=1
  172. shift
  173. check-next-parameter $1 || return 1
  174. ;;
  175. --build|build|--clean|clean|--show-info|show-info)
  176. with_actions=1
  177. ;;
  178. *)
  179. Msg_MissingParameter_$LOCALE $1
  180. return 1
  181. ;;
  182. esac
  183. shift
  184. done
  185. [ $with_actions -eq 0 ] && Msg_GiveAtLeastOneAction_$LOCALE && return 1
  186. return 0
  187. }
  188. check-next-parameter(){
  189. local arg=$1
  190. [ -z "${arg}" ] && Msg_MissingParameter_$LOCALE ${arg} && return 1
  191. [ $(echo ${arg} | grep '^-') ] && \
  192. Msg_MissingParameter_$LOCALE ${arg} && return 1
  193. return 0
  194. }
  195. setup-vbuilder(){
  196. ## load default settings
  197. VBUILDER_CONF=/etc/vbootstrap/vbuilder.conf
  198. if [ -r $VBUILDER_CONF ]; then
  199. . $VBUILDER_CONF
  200. fi
  201. [ -z "${DEFAULT_VERSION}" ] && \
  202. DEFAULT_VERSION=@@VBUILDER_DEFAULT_VERSION@@
  203. [ -z "${CATEGORIES}" ] && \
  204. CATEGORIES=@@VBUILDER_CATEGORIES@@
  205. [ -z "${VBOOTSTRAP_DIR}" ] && \
  206. VBOOTSTRAP_DIR=@@VBUILDER_VBOOTSTRAP_DIR@@
  207. [ -z "${CACHE_DIR}" ] && \
  208. CACHE_DIR=@@VBUILDER_CACHE_DIR@@
  209. [ -z "${BUILT_RPMS_DIR}" ] && \
  210. BUILT_RPMS_DIR=@@VBUILDER_BUILT_RPMS_DIR@@
  211. ## set default version for vbootstrap
  212. VERSION=$DEFAULT_VERSION
  213. ## set current stable relase version
  214. STABLE_VERSION=@@VBUILDER_STABLE_VERSION@@
  215. ## set locale
  216. case $LANG in
  217. ja*) LOCALE=ja ;;
  218. *) LOCALE=C ;;
  219. esac
  220. ## set boolian
  221. with_setup_vbootstrap=0
  222. with_unionfs=0
  223. with_dist_upgrade=0
  224. with_actions=0
  225. with_category_main=0
  226. with_category_plus=0
  227. with_category_nonfree=0
  228. with_category_test=0
  229. with_category_proposed_updates=0
  230. with_category_security=0
  231. }
  232. setup-vbootstrap(){
  233. if [ ${with_setup_vbootstrap} -eq 0 ]; then
  234. with_setup_vbootstrap=1
  235. ## check some directories
  236. ## Note: create $BUILT_RPMS_DIR in RPM_Build()
  237. [ -d $VBOOTSTRAP_DIR ] || mkdir -p $VBOOTSTRAP_DIR
  238. [ -d $CACHE_DIR ] || mkdir -p $CACHE_DIR
  239. ## check a chroot archtecture
  240. if [ -z ${VARCH} ]; then
  241. VARCH=$(uname -i)
  242. else
  243. case "${VARCH}" in
  244. i386|i686|x86_64)
  245. [ "$(uname -i)" = "ppc" ] && \
  246. Msg_NoSupportVARCH_$LOCALE && exit 1
  247. ;;
  248. ppc)
  249. [ "$(uname -i)" = "i386" -o "$(uname -i)" = "i686" -o "$(uname -i)" = "x86_64" ] && \
  250. Msg_NoSupportVARCH_$LOCALE && exit 1
  251. ;;
  252. esac
  253. fi
  254. ##!! 4.2 is NO support on VARCH=x86_64
  255. if [ "${VERSION}" = "4.2" -a "${VARCH}" = "x86_64" ]; then
  256. Msg_NoSupportVERSION_${LOCALE} && exit 1
  257. fi
  258. ## support i386 chroot on x86_64 below:
  259. [ "${VARCH}" != "$(uname -i)" ] && VERSION=${VERSION}_${VARCH}
  260. ## check support ${VERSION}
  261. if [ -z "$(/usr/sbin/vbootstrap | sed -e s/^Usage:.*// -e s/^E:.*// | grep -m 1 ${VERSION})" ]; then
  262. Msg_NoSupportVERSION_$LOCALE && exit 1
  263. fi
  264. ## check ${VERSION} equals VineSeed*, when with_dist_upgrade=1
  265. if [ $with_dist_upgrade -eq 1 ]; then
  266. if [ "$(echo ${VERSION} | sed -e "s/\(VineSeed\).*/\1/")" != "VineSeed" ]; then
  267. Msg_NoSupportDistUpgradeVERSION_$LOCALE && exit 1
  268. fi
  269. fi
  270. ## set ${MAJOR_VERSION}
  271. MAJOR_VERSION=$(echo ${VERSION} | sed -e "s/_i[0-9]86//")
  272. ## check apt categories
  273. ## "main" category is unconditionally permited
  274. with_category_main=1
  275. for cat in $(echo ${CATEGORIES} | sed -e "s/,/ /"g); do
  276. case $cat in
  277. main)
  278. with_category_main=1
  279. ;;
  280. plus)
  281. with_category_plus=1
  282. ;;
  283. nonfree)
  284. with_category_nonfree=1
  285. ;;
  286. test)
  287. ## "test" category only exists in VineSeed
  288. [ "${MAJOR_VERSION}" = "VineSeed" ] || \
  289. Msg_NoSuchCategoryExists_$LOCALE ${cat} && exit 1
  290. with_category_test=1
  291. ;;
  292. proposed-updates)
  293. ##!! "proposed-updates" category does not exist in 4.2
  294. [ "${MAJOR_VERSION}" = "4.2" ] && \
  295. Msg_NoSuchCategoryExists_$LOCALE ${cat} && exit 1
  296. with_category_proposed_updates=1
  297. ;;
  298. security)
  299. ## "security" category does not exist in VineSeed
  300. [ "${MAJOR_VERSION}" = "VineSeed" ] && \
  301. Msg_NoSuchCategoryExists_$LOCALE ${cat} && exit 1
  302. with_category_security=1
  303. ;;
  304. *)
  305. Msg_NoSuchCategoryExists_$LOCALE ${cat} && exit 1
  306. ;;
  307. esac
  308. done
  309. ## check build target option ${TARGET}
  310. if [ ! -z "${TARGET}" ]; then
  311. RPM_TARGET_LIST="$(cat /usr/lib/rpm/rpmrc | grep arch_canon: | sed -e "s/arch_canon:[[:blank:]]*\(.*\):.*/\1/")"
  312. if [ -z "$(echo $RPM_TARGET_LIST | grep $TARGET)" ]; then
  313. Msg_NoSupportTARGET_$LOCALE && exit 1
  314. fi
  315. fi
  316. fi
  317. BUILD_ROOT=${VBOOTSTRAP_DIR}/${VERSION}
  318. BUILD_USER=vbuilder
  319. BUILD_DIR=/home/${BUILD_USER}/rpm
  320. UNIONFS_DIR=${VBOOTSTRAP_DIR}/unionfs/${VERSION}
  321. ARCHIVES_DIR=${BUILD_ROOT}/var/cache/apt/archives
  322. EXTERNAL_ARCHIVES_DIR=${CACHE_DIR}/${VERSION}/apt/archives
  323. VBUILDER_LOG=${BUILD_ROOT}/var/log/vbuilder.log
  324. __chroot_sh="/usr/sbin/chroot ${BUILD_ROOT} /bin/sh -c"
  325. mkdir -p $VBOOTSTRAP_DIR
  326. }
  327. setup-vbootstrap-rpm(){
  328. setup-vbootstrap
  329. ## check ${BUILD_ROOT}
  330. [ -d ${BUILD_ROOT} ] || Build
  331. DIST_RELEASE=$(cat ${BUILD_ROOT}/etc/vine-release | cut -f3 -d" " | cut -f1 -d.)
  332. if [ -f $RPM_PKG ]; then
  333. BASE_RPM_PKG=$(basename $RPM_PKG)
  334. cp -f $RPM_PKG $BUILD_ROOT${BUILD_DIR}
  335. else
  336. BASE_RPM_PKG=$RPM_PKG
  337. fi
  338. }
  339. ## recover apt-get data on host/chroot
  340. apt-get-update(){
  341. case $1 in
  342. --host)
  343. echo -n "apt-get update on host ... "
  344. apt-get -qq update > /dev/null 2>&1
  345. echo "done."
  346. ;;
  347. --chroot)
  348. echo -n "apt-get update on chroot ... "
  349. $__chroot_sh 'apt-get -qq update' > /dev/null 2>&1
  350. echo "done."
  351. ;;
  352. *)
  353. echo apt-get-update: unknown option $1
  354. exit 1
  355. ;;
  356. esac
  357. }
  358. ## mount-chroot {|--umount} [file system|name]
  359. ## support file systems: /home /tmp /sys /proc /dev/shm /dev/pts /dev
  360. ## support name: vfs chache_dir
  361. ## NOTE: /tmp needs for applications which use X
  362. ## vfs is virtual file systems
  363. ## archives_dir is ${EXTERNAL_ARCHIVES_DIR} to ${ARCHIVES_DIR}
  364. mount-chroot(){
  365. if [ "$1" = "--umount" ]; then
  366. mount-chroot-umount $2 || return 1
  367. else
  368. mount-chroot-mount $1 || return 1
  369. fi
  370. return 0
  371. }
  372. ## mount-chroot-umount [file system|name]
  373. mount-chroot-umount(){
  374. local fs=$1
  375. case $fs in
  376. /home|/tmp|/sys|/proc|/dev/shm|/dev/pts|/dev)
  377. [ -d ${BUILD_ROOT}${fs} ] || return 1
  378. [ -z "$(mount | grep ${BUILD_ROOT}${fs})" ] || \
  379. umount ${BUILD_ROOT}${fs}
  380. return 0
  381. ;;
  382. vfs)
  383. # for dir in /sys /proc /dev/shm /dev/pts /dev; do
  384. # mount-chroot-umount ${dir} || return 1
  385. # done
  386. [ -d ${BUILD_ROOT}/proc ] || return 1
  387. [ -z "$(mount | grep ${BUILD_ROOT}/proc)" ] || \
  388. umount ${BUILD_ROOT}/proc
  389. return 0
  390. ;;
  391. archives_dir)
  392. [ -d ${ARCHIVES_DIR} ] || return 1
  393. [ -z "$(mount | grep ${ARCHIVES_DIR})" ] || \
  394. umount ${ARCHIVES_DIR}
  395. return 0
  396. ;;
  397. unionfs_dir)
  398. [ -d ${BUILD_ROOT} ] || return 1
  399. [ -z "$(mount | grep ${BUILD_ROOT} | grep unionfs)" ] || \
  400. umount ${BUILD_ROOT}
  401. if [ ! -z "$(mount | grep ${BUILD_ROOT} | grep unionfs)" ]; then
  402. echo "Retry lazy unmount ... "
  403. umount -l ${BUILD_ROOT}
  404. echo "done."
  405. fi
  406. return 0
  407. ;;
  408. *)
  409. echo mount-chroot-umount: unknown file system $fs
  410. exit 1
  411. ;;
  412. esac
  413. }
  414. ## mount-chroot-mount [file system|name]
  415. mount-chroot-mount(){
  416. local fs=$1
  417. local mnt_opts=""
  418. case $fs in
  419. /home)
  420. mnt_opts="-o rbind"
  421. ;;
  422. *)
  423. mnt_opts="--bind"
  424. ;;
  425. esac
  426. case $fs in
  427. /home|/tmp|/sys|/proc|/dev/shm|/dev/pts|/dev)
  428. [ -d ${BUILD_ROOT}${fs} ] || mkdir -p ${BUILD_ROOT}${fs}
  429. [ -z "$(mount | grep ${BUILD_ROOT}${fs})" ] && \
  430. mount ${mnt_opts} ${fs} ${BUILD_ROOT}${fs}
  431. return 0
  432. ;;
  433. vfs)
  434. # for dir in /dev /dev/pts /dev/shm /proc /sys; do
  435. # mount-chroot-mount ${dir} || return 1
  436. # done
  437. mount-chroot-mount /proc || return 1
  438. return 0
  439. ;;
  440. archives_dir)
  441. [ -d ${EXTERNAL_ARCHIVES_DIR} ] || mkdir -p ${EXTERNAL_ARCHIVES_DIR}
  442. [ -d ${ARCHIVES_DIR} ] || mkdir -p ${ARCHIVES_DIR}
  443. [ -z "$(mount | grep ${ARCHIVES_DIR})" ] && \
  444. mount ${mnt_opts} ${EXTERNAL_ARCHIVES_DIR} ${ARCHIVES_DIR}
  445. [ -d ${ARCHIVES_DIR}/partial ] || mkdir -p ${ARCHIVES_DIR}/partial
  446. return 0
  447. ;;
  448. unionfs_dir)
  449. if [ $with_unionfs -eq 1 ]; then
  450. [ -d ${UNIONFS_DIR} ] || mkdir -p ${UNIONFS_DIR}
  451. [ -z "$(mount | grep ${BUILD_ROOT})" ] && \
  452. mount -t unionfs -o dirs=${UNIONFS_DIR}=rw:${BUILD_ROOT}=ro unionfs ${BUILD_ROOT}
  453. unionctl ${BUILD_ROOT} --list
  454. fi
  455. return 0
  456. ;;
  457. *)
  458. echo mount-chroot-mount: unknown file system $fs
  459. exit 1
  460. ;;
  461. esac
  462. }
  463. write-vbuilder-log(){
  464. HRULE="======================================================================"
  465. [ -d ${BUILD_ROOT} ] || return 1
  466. if [ ! -f $VBUILDER_LOG ]; then
  467. cat<<EOF > $VBUILDER_LOG
  468. ${HRULE}
  469. VBUILDER REPORT
  470. DATE: $(LANG=C date)
  471. HOSTNAME: $(hostname)
  472. OS: $(echo $($__chroot_sh "cat /etc/vine-release"))
  473. %_arch: $(echo $($__chroot_sh "rpm --eval %_arch"))
  474. --version: ${VERSION}
  475. $(echo $([ -z "${VARCH}" ] || echo "--arch: ${VARCH}"))
  476. $(echo $([ -z "${CATEGORIES}" ] || echo "--category: ${CATEGORIES}"))
  477. $(echo $([ $with_dist_upgrade -eq 1 ] && echo "--dist-upgrade"))
  478. $(echo $([ $with_unionfs -eq 1 ] && echo "--unionfs"))
  479. $(echo $([ -z "${TARGET}" ] || echo "--target: ${TARGET}"))
  480. --bootstrap-dir: ${VBOOTSTRAP_DIR}
  481. --cache-dir: ${CACHE_DIR}
  482. --built-rpms-dir: ${BUILT_RPMS_DIR}
  483. ${HRULE}
  484. [$VBUILDER_CONF]
  485. $(cat $VBUILDER_CONF)
  486. [History]
  487. EOF
  488. else
  489. cat<<EOF >> $VBUILDER_LOG
  490. $*
  491. EOF
  492. fi
  493. }
  494. ##############################################################################
  495. Clean(){
  496. setup-vbootstrap
  497. # output end-of-line in $VBUILDER_LOG
  498. [ -f $VBUILDER_LOG ] && write-vbuilder-log ${HRULE}
  499. Show-Info
  500. # mount-chroot --umount /home
  501. # mount-chroot --umount /tmp
  502. mount-chroot --umount vfs
  503. mount-chroot --umount archives_dir
  504. mount-chroot --umount unionfs_dir
  505. apt-get-update --host
  506. if [ $with_unionfs -eq 1 ]; then
  507. if [ -d ${UNIONFS_DIR} ]; then
  508. echo -n "Cleaning build root \"${UNIONFS_DIR}\" via unionfs ... "
  509. rm -rf ${UNIONFS_DIR}
  510. echo "done."
  511. fi
  512. else
  513. if [ -d ${BUILD_ROOT} ]; then
  514. echo -n "Cleaning build root \"${BUILD_ROOT}\" ... "
  515. rm -rf ${BUILD_ROOT}
  516. echo "done."
  517. fi
  518. fi
  519. echo "Cleanup a build farm for ${VERSION} done."
  520. }
  521. Build(){
  522. setup-vbootstrap
  523. if [ $with_dist_upgrade -eq 1 ]; then
  524. ## make bootstrap of ${STABLE_VERSION}
  525. /usr/sbin/vbootstrap \
  526. $(echo ${VERSION} | sed -e "s/VineSeed/${STABLE_VERSION}/") \
  527. ${BUILD_ROOT}
  528. ## aim apt-line to VineSeed
  529. sed -i "s/apt ${STABLE_VERSION}/apt VineSeed/g" \
  530. ${BUILD_ROOT}/etc/apt/sources.list.d/main.list
  531. else
  532. /usr/sbin/vbootstrap ${VERSION} ${BUILD_ROOT}
  533. fi
  534. mount-chroot archives_dir
  535. mount-chroot vfs
  536. # mount-chroot /tmp
  537. # mount-chroot /home
  538. $__chroot_sh 'apt-get -qq update && apt-get -qq -y dist-upgrade'
  539. ##!! 4.2 has no apt-sourceslist-{plus,nonfree,proposed-updates} packages
  540. case ${MAJOR_VERSION} in
  541. 4.2)
  542. $__chroot_sh "sed -i -e 's/main plus updates nonfree *$/$(echo ${CATEGORIES} | sed -e "s/,/ /"g) updates/g' /etc/apt/sources.list"
  543. # [ $with_category_security -eq 1 ] && \
  544. # echo
  545. ;;
  546. @@VBUILDER_STABLE_VERSION@@)
  547. [ $with_category_plus -eq 1 ] && \
  548. $__chroot_sh 'apt-get -qq update && apt-get -qq -y install apt-sourceslist-plus'
  549. [ $with_category_nonfree -eq 1 ] && \
  550. $__chroot_sh 'apt-get -qq update && apt-get -qq -y install apt-sourceslist-nonfree'
  551. [ $with_category_proposed_updates -eq 1 ] && \
  552. $__chroot_sh 'apt-get -qq update && apt-get -qq -y install apt-sourceslist-proposed-updates'
  553. # [ $with_category_security -eq 1 ] && \
  554. # echo
  555. ;;
  556. VineSeed)
  557. [ $with_category_plus -eq 1 ] && \
  558. $__chroot_sh 'apt-get -qq update && apt-get -qq -y install apt-sourceslist-plus'
  559. [ $with_category_nonfree -eq 1 ] && \
  560. $__chroot_sh 'apt-get -qq update && apt-get -qq -y install apt-sourceslist-nonfree'
  561. [ $with_category_test -eq 1 ] && \
  562. $__chroot_sh 'apt-get -qq update && apt-get -qq -y install apt-sourceslist-test'
  563. ;;
  564. esac
  565. [ $with_dist_upgrade -eq 1 ] && \
  566. $__chroot_sh 'apt-get -qq update && apt-get -qq -y dist-upgrade'
  567. $__chroot_sh 'apt-get -qq -y install build-essential'
  568. [ $with_category_nonfree -eq 1 ] && \
  569. $__chroot_sh 'apt-get -qq -y install self-build-setup'
  570. $__chroot_sh 'apt-get -qq -y install etcskel shadow-utils'
  571. $__chroot_sh 'cd /dev && /sbin/MAKEDEV console'
  572. $__chroot_sh 'cd /dev && /sbin/MAKEDEV null'
  573. $__chroot_sh 'cd /dev && /sbin/MAKEDEV zero'
  574. $__chroot_sh '/usr/sbin/pwconv'
  575. $__chroot_sh "/usr/sbin/useradd ${BUILD_USER}"
  576. ##!! for rpm-4.8.0 or higher
  577. ##!! (See http://trac.vinelinux.org/wiki/Vine6/AboutUpdateToolchain)
  578. if [ "$(echo ${VERSION} | sed -e "s/\(VineSeed\).*/\1/")" = "VineSeed" ]; then
  579. $__chroot_sh "sed -i -e 's/^%_topdir/#%_topdir/' /home/${BUILD_USER}/.rpmmacros"
  580. fi
  581. ## output basic informations in chroot
  582. write-vbuilder-log
  583. write-vbuilder-log "build"
  584. # mount-chroot --umount /home
  585. # mount-chroot --umount /tmp
  586. mount-chroot --umount vfs
  587. mount-chroot --umount archives_dir
  588. apt-get-update --host
  589. echo "Making a build farm for ${VERSION} done."
  590. }
  591. Show-Info(){
  592. setup-vbootstrap
  593. [ -f $VBUILDER_LOG ] && cat $VBUILDER_LOG
  594. }
  595. RPM_Remove(){
  596. setup-vbootstrap-rpm
  597. mount-chroot unionfs_dir
  598. mount-chroot archives_dir
  599. mount-chroot vfs
  600. apt-get-update --chroot
  601. [ -f $RPM_PKG ] && Msg_NotPackageName_$LOCALE $RPM_PKG && exit 1
  602. $__chroot_sh "apt-get -y remove $BASE_RPM_PKG"
  603. write-vbuilder-log "remove-rpm $RPM_PKG"
  604. mount-chroot --umount vfs
  605. mount-chroot --umount archives_dir
  606. mount-chroot --umount unionfs_dir
  607. apt-get-update --host
  608. }
  609. RPM_Install(){
  610. setup-vbootstrap-rpm
  611. mount-chroot unionfs_dir
  612. mount-chroot archives_dir
  613. mount-chroot vfs
  614. apt-get-update --chroot
  615. $__chroot_sh "cd ${BUILD_DIR} && apt-get -y install $BASE_RPM_PKG"
  616. write-vbuilder-log "install-rpm $RPM_PKG"
  617. mount-chroot --umount vfs
  618. mount-chroot --umount archives_dir
  619. mount-chroot --umount unionfs_dir
  620. apt-get-update --host
  621. }
  622. RPM_Build(){
  623. setup-vbootstrap-rpm
  624. mount-chroot unionfs_dir
  625. mount-chroot archives_dir
  626. mount-chroot vfs
  627. apt-get-update --chroot
  628. [ ! -f $RPM_PKG ] && Msg_NotSourceRPM_$LOCALE $RPM_PKG && exit 1
  629. RPM_PKG_USER=$(stat -c %U $RPM_PKG)
  630. RPM_PKG_GROUP=$(stat -c %G $RPM_PKG)
  631. [ ! -z "${SUDO_UID}" ] && RPM_PKG_USER=${SUDO_UID}
  632. [ ! -z "${SUDO_GID}" ] && RPM_PKG_GROUP=${SUDO_GID}
  633. local __install="install -p -v -o ${RPM_PKG_USER} -g ${RPM_PKG_GROUP}"
  634. RPM_PKG_ARCH_LIST="RPMS/i386 RPMS/i686 RPMS/x86_64 RPMS/ppc RPMS/noarch SRPMS"
  635. [ -z "${TARGET}" ] || \
  636. RPM_PKG_ARCH_LIST="RPMS/${TARGET} ${RPM_PKG_ARCH_LIST}"
  637. ## make src.rpm for $VERSION
  638. $__chroot_sh "cd ${BUILD_DIR} && su ${BUILD_USER} -c 'rpm -ivh $BASE_RPM_PKG'"
  639. $__chroot_sh "cd ${BUILD_DIR} && su ${BUILD_USER} -c 'rpmbuild -bs --nodeps --clean --rmsource --rmspec ${BUILD_DIR}/SPECS/*.spec'"
  640. ## change ${DIST_RELEASE}
  641. BASE_RPM_PKG=$(echo $BASE_RPM_PKG | sed -e "s/vl\([0-9]*\)\./vl${DIST_RELEASE}\./")
  642. ## rebuild $BASE_RPM_PKG on ${DIST_RELEASE}
  643. $__chroot_sh "cd ${BUILD_DIR}/SRPMS && apt-get -y build-dep $BASE_RPM_PKG"
  644. $__chroot_sh "cd ${BUILD_DIR}/SRPMS && su ${BUILD_USER} -c 'rpmbuild --rebuild $RPM_OPTS $BASE_RPM_PKG'"
  645. $__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')"
  646. ## copy built rpms to ${HOME}/rpm/ for each archtectures
  647. echo "Copying built rpms to ${BUILT_RPMS_DIR} for each archtectures ... "
  648. for i in $RPM_PKG_ARCH_LIST; do \
  649. if [ -d $BUILD_ROOT${BUILD_DIR}/${i} ]; then
  650. if [ ! -d ${BUILT_RPMS_DIR}/${MAJOR_VERSION}/${i} ]; then
  651. $__install -d ${BUILT_RPMS_DIR}/${MAJOR_VERSION}/${i}/
  652. chown -R ${RPM_PKG_USER}:${RPM_PKG_GROUP} ${BUILT_RPMS_DIR}
  653. fi
  654. find $BUILD_ROOT${BUILD_DIR}/${i} -type f -regex '.*\.rpm' \
  655. -exec $__install -m0644 {} ${BUILT_RPMS_DIR}/${MAJOR_VERSION}/${i}/ \;
  656. fi
  657. done
  658. write-vbuilder-log "build-rpm $RPM_PKG"
  659. mount-chroot --umount vfs
  660. mount-chroot --umount archives_dir
  661. mount-chroot --umount unionfs_dir
  662. apt-get-update --host
  663. echo "done."
  664. }
  665. ##############################################################################
  666. setup-vbuilder
  667. check-parameter $* || exit 1
  668. while [ $# -gt 0 ]; do
  669. tmpARG=$1
  670. case $tmpARG in
  671. --version|--arch|--category|--target|--bootstrap-dir|--cache-dir|--built-rpms-dir)
  672. shift
  673. ;;
  674. --dist-upgrade|--unionfs|--with-compat32)
  675. ;;
  676. --build-rpm|build-rpm|--install-rpm|install-rpm|--remove-rpm|remove-rpm)
  677. shift
  678. ;;
  679. --build|build|--clean|clean|--show-info|show-info)
  680. ;;
  681. *)
  682. echo unknown option $1
  683. exit 1
  684. ;;
  685. esac
  686. case $tmpARG in
  687. --version)
  688. VERSION=$1
  689. ;;
  690. --arch)
  691. VARCH=$1
  692. ;;
  693. --category)
  694. CATEGORIES=$1
  695. ;;
  696. --dist-upgrade)
  697. with_dist_upgrade=1
  698. ;;
  699. --unionfs)
  700. with_unionfs=1
  701. ;;
  702. --target)
  703. TARGET=$1
  704. RPM_OPTS="${RPM_OPTS} --target $TARGET"
  705. ;;
  706. --with-compat32)
  707. RPM_OPTS="${RPM_OPTS} --with compat32"
  708. ;;
  709. --bootstrap-dir)
  710. VBOOTSTRAP_DIR=$1
  711. ;;
  712. --cache-dir)
  713. CACHE_DIR=$1
  714. ;;
  715. --built-rpms-dir)
  716. BUILT_RPMS_DIR=$1
  717. ;;
  718. --build-rpm|build-rpm)
  719. RPM_PKG=$1
  720. RPM_Build || exit 1
  721. ;;
  722. --install-rpm|install-rpm)
  723. RPM_PKG=$1
  724. RPM_Install || exit 1
  725. ;;
  726. --remove-rpm|remove-rpm)
  727. RPM_PKG=$1
  728. RPM_Remove || exit 1
  729. ;;
  730. --show-info|show-info)
  731. Show-Info
  732. ;;
  733. --build|build)
  734. Build
  735. ;;
  736. --clean|clean)
  737. Clean
  738. ;;
  739. esac
  740. shift
  741. done
  742. exit