vbuilder.sh.in 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864
  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 archives_dir
  361. ## NOTE: /tmp needs for applications which use X
  362. ## vfs is virtual file systems
  363. ## archives_dir uses to mount ${EXTERNAL_ARCHIVES_DIR} to ${ARCHIVES_DIR}
  364. ## unionfs_dir covers ${BUILD_ROOT} with unionfs
  365. mount-chroot(){
  366. if [ "$1" = "--umount" ]; then
  367. mount-chroot-umount $2 || return 1
  368. else
  369. mount-chroot-mount $1 || return 1
  370. fi
  371. return 0
  372. }
  373. ## mount-chroot-umount [file system|name]
  374. mount-chroot-umount(){
  375. local fs=$1
  376. case $fs in
  377. /home|/tmp|/sys|/proc|/dev/shm|/dev/pts|/dev)
  378. [ -d ${BUILD_ROOT}${fs} ] || return 1
  379. [ -z "$(mount | grep ${BUILD_ROOT}${fs})" ] || \
  380. umount ${BUILD_ROOT}${fs}
  381. return 0
  382. ;;
  383. vfs)
  384. # for dir in /sys /proc /dev/shm /dev/pts /dev; do
  385. # mount-chroot-umount ${dir} || return 1
  386. # done
  387. [ -d ${BUILD_ROOT}/proc ] || return 1
  388. [ -z "$(mount | grep ${BUILD_ROOT}/proc)" ] || \
  389. umount ${BUILD_ROOT}/proc
  390. return 0
  391. ;;
  392. archives_dir)
  393. [ -d ${ARCHIVES_DIR} ] || return 1
  394. [ -z "$(mount | grep ${ARCHIVES_DIR})" ] || \
  395. umount ${ARCHIVES_DIR}
  396. return 0
  397. ;;
  398. unionfs_dir)
  399. [ -d ${BUILD_ROOT} ] || return 1
  400. [ -z "$(mount | grep ${BUILD_ROOT} | grep unionfs)" ] || \
  401. umount ${BUILD_ROOT}
  402. if [ ! -z "$(mount | grep ${BUILD_ROOT} | grep unionfs)" ]; then
  403. echo "Retry lazy unmount ... "
  404. umount -l ${BUILD_ROOT}
  405. echo "done."
  406. fi
  407. return 0
  408. ;;
  409. *)
  410. echo mount-chroot-umount: unknown file system $fs
  411. exit 1
  412. ;;
  413. esac
  414. }
  415. ## mount-chroot-mount [file system|name]
  416. mount-chroot-mount(){
  417. local fs=$1
  418. local mnt_opts=""
  419. case $fs in
  420. /home)
  421. mnt_opts="-o rbind"
  422. ;;
  423. *)
  424. mnt_opts="--bind"
  425. ;;
  426. esac
  427. case $fs in
  428. /home|/tmp|/sys|/proc|/dev/shm|/dev/pts|/dev)
  429. [ -d ${BUILD_ROOT}${fs} ] || mkdir -p ${BUILD_ROOT}${fs}
  430. [ -z "$(mount | grep ${BUILD_ROOT}${fs})" ] && \
  431. mount ${mnt_opts} ${fs} ${BUILD_ROOT}${fs}
  432. return 0
  433. ;;
  434. vfs)
  435. # for dir in /dev /dev/pts /dev/shm /proc /sys; do
  436. # mount-chroot-mount ${dir} || return 1
  437. # done
  438. mount-chroot-mount /proc || return 1
  439. return 0
  440. ;;
  441. archives_dir)
  442. [ -d ${EXTERNAL_ARCHIVES_DIR} ] || mkdir -p ${EXTERNAL_ARCHIVES_DIR}
  443. [ -d ${ARCHIVES_DIR} ] || mkdir -p ${ARCHIVES_DIR}
  444. [ -z "$(mount | grep ${ARCHIVES_DIR})" ] && \
  445. mount ${mnt_opts} ${EXTERNAL_ARCHIVES_DIR} ${ARCHIVES_DIR}
  446. [ -d ${ARCHIVES_DIR}/partial ] || mkdir -p ${ARCHIVES_DIR}/partial
  447. return 0
  448. ;;
  449. unionfs_dir)
  450. if [ $with_unionfs -eq 1 ]; then
  451. [ -d ${UNIONFS_DIR} ] || mkdir -p ${UNIONFS_DIR}
  452. [ -z "$(mount | grep ${BUILD_ROOT})" ] && \
  453. mount -t unionfs -o dirs=${UNIONFS_DIR}=rw:${BUILD_ROOT}=ro unionfs ${BUILD_ROOT}
  454. unionctl ${BUILD_ROOT} --list
  455. fi
  456. return 0
  457. ;;
  458. *)
  459. echo mount-chroot-mount: unknown file system $fs
  460. exit 1
  461. ;;
  462. esac
  463. }
  464. write-vbuilder-log(){
  465. HRULE="======================================================================"
  466. [ -d ${BUILD_ROOT} ] || return 1
  467. if [ ! -f $VBUILDER_LOG ]; then
  468. cat<<EOF > $VBUILDER_LOG
  469. ${HRULE}
  470. VBUILDER REPORT
  471. DATE: $(LANG=C date)
  472. HOSTNAME: $(hostname)
  473. OS: $(echo $($__chroot_sh "cat /etc/vine-release"))
  474. %_arch: $(echo $($__chroot_sh "rpm --eval %_arch"))
  475. --version: ${VERSION}
  476. $(echo $([ -z "${VARCH}" ] || echo "--arch: ${VARCH}"))
  477. $(echo $([ -z "${CATEGORIES}" ] || echo "--category: ${CATEGORIES}"))
  478. $(echo $([ $with_dist_upgrade -eq 1 ] && echo "--dist-upgrade"))
  479. $(echo $([ $with_unionfs -eq 1 ] && echo "--unionfs"))
  480. $(echo $([ -z "${TARGET}" ] || echo "--target: ${TARGET}"))
  481. --bootstrap-dir: ${VBOOTSTRAP_DIR}
  482. --cache-dir: ${CACHE_DIR}
  483. --built-rpms-dir: ${BUILT_RPMS_DIR}
  484. ${HRULE}
  485. [$VBUILDER_CONF]
  486. $(cat $VBUILDER_CONF)
  487. [History]
  488. EOF
  489. else
  490. cat<<EOF >> $VBUILDER_LOG
  491. $*
  492. EOF
  493. fi
  494. }
  495. ##############################################################################
  496. Clean(){
  497. setup-vbootstrap
  498. # # output end-of-line in $VBUILDER_LOG
  499. # [ -f $VBUILDER_LOG ] && write-vbuilder-log ${HRULE}
  500. # Show-Info
  501. # mount-chroot --umount /home
  502. # mount-chroot --umount /tmp
  503. mount-chroot --umount vfs
  504. mount-chroot --umount archives_dir
  505. mount-chroot --umount unionfs_dir
  506. apt-get-update --host
  507. if [ $with_unionfs -eq 1 ]; then
  508. if [ -d ${UNIONFS_DIR} ]; then
  509. echo -n "Cleaning build root \"${UNIONFS_DIR}\" via unionfs ... "
  510. rm -rf ${UNIONFS_DIR}
  511. echo "done."
  512. fi
  513. else
  514. if [ -d ${BUILD_ROOT} ]; then
  515. echo -n "Cleaning build root \"${BUILD_ROOT}\" ... "
  516. rm -rf ${BUILD_ROOT}
  517. echo "done."
  518. fi
  519. fi
  520. echo "Cleanup a build farm for ${VERSION} done."
  521. }
  522. Build(){
  523. setup-vbootstrap
  524. if [ $with_dist_upgrade -eq 1 ]; then
  525. ## make bootstrap of ${STABLE_VERSION}
  526. /usr/sbin/vbootstrap \
  527. $(echo ${VERSION} | sed -e "s/VineSeed/${STABLE_VERSION}/") \
  528. ${BUILD_ROOT}
  529. ## aim apt-line to VineSeed
  530. sed -i "s/apt ${STABLE_VERSION}/apt VineSeed/g" \
  531. ${BUILD_ROOT}/etc/apt/sources.list.d/main.list
  532. else
  533. /usr/sbin/vbootstrap ${VERSION} ${BUILD_ROOT}
  534. fi
  535. mount-chroot archives_dir
  536. mount-chroot vfs
  537. # mount-chroot /tmp
  538. # mount-chroot /home
  539. $__chroot_sh 'apt-get -qq update && apt-get -qq -y dist-upgrade'
  540. ##!! 4.2 has no apt-sourceslist-{plus,nonfree,proposed-updates} packages
  541. case ${MAJOR_VERSION} in
  542. 4.2)
  543. $__chroot_sh "sed -i -e 's/main plus updates nonfree *$/$(echo ${CATEGORIES} | sed -e "s/,/ /"g) updates/g' /etc/apt/sources.list"
  544. # [ $with_category_security -eq 1 ] && \
  545. # echo
  546. ;;
  547. @@VBUILDER_STABLE_VERSION@@)
  548. [ $with_category_plus -eq 1 ] && \
  549. $__chroot_sh 'apt-get -qq update && apt-get -qq -y install apt-sourceslist-plus'
  550. [ $with_category_nonfree -eq 1 ] && \
  551. $__chroot_sh 'apt-get -qq update && apt-get -qq -y install apt-sourceslist-nonfree'
  552. [ $with_category_proposed_updates -eq 1 ] && \
  553. $__chroot_sh 'apt-get -qq update && apt-get -qq -y install apt-sourceslist-proposed-updates'
  554. # [ $with_category_security -eq 1 ] && \
  555. # echo
  556. ;;
  557. VineSeed)
  558. [ $with_category_plus -eq 1 ] && \
  559. $__chroot_sh 'apt-get -qq update && apt-get -qq -y install apt-sourceslist-plus'
  560. [ $with_category_nonfree -eq 1 ] && \
  561. $__chroot_sh 'apt-get -qq update && apt-get -qq -y install apt-sourceslist-nonfree'
  562. [ $with_category_test -eq 1 ] && \
  563. $__chroot_sh 'apt-get -qq update && apt-get -qq -y install apt-sourceslist-test'
  564. ;;
  565. esac
  566. [ $with_dist_upgrade -eq 1 ] && \
  567. $__chroot_sh 'apt-get -qq update && apt-get -qq -y dist-upgrade'
  568. $__chroot_sh 'apt-get -qq -y install build-essential'
  569. [ $with_category_nonfree -eq 1 ] && \
  570. $__chroot_sh 'apt-get -qq -y install self-build-setup'
  571. $__chroot_sh 'apt-get -qq -y install etcskel shadow-utils'
  572. $__chroot_sh 'cd /dev && /sbin/MAKEDEV console'
  573. $__chroot_sh 'cd /dev && /sbin/MAKEDEV null'
  574. $__chroot_sh 'cd /dev && /sbin/MAKEDEV zero'
  575. $__chroot_sh 'cd /dev && /sbin/MAKEDEV random'
  576. $__chroot_sh 'cd /dev && /sbin/MAKEDEV urandom'
  577. $__chroot_sh '/usr/sbin/pwconv'
  578. $__chroot_sh "/usr/sbin/useradd ${BUILD_USER}"
  579. ##!! for rpm-4.8.0 or higher
  580. ##!! (See http://trac.vinelinux.org/wiki/Vine6/AboutUpdateToolchain)
  581. if [ "$(echo ${VERSION} | sed -e "s/\(VineSeed\).*/\1/")" = "VineSeed" ]; then
  582. $__chroot_sh "sed -i -e 's/^%_topdir/#%_topdir/' /home/${BUILD_USER}/.rpmmacros"
  583. fi
  584. ## output basic informations in chroot
  585. write-vbuilder-log
  586. write-vbuilder-log "build"
  587. # mount-chroot --umount /home
  588. # mount-chroot --umount /tmp
  589. mount-chroot --umount vfs
  590. mount-chroot --umount archives_dir
  591. apt-get-update --host
  592. echo "Making a build farm for ${VERSION} done."
  593. }
  594. Show-Info(){
  595. setup-vbootstrap
  596. [ -f $VBUILDER_LOG ] && cat $VBUILDER_LOG
  597. }
  598. RPM_Remove(){
  599. setup-vbootstrap-rpm
  600. mount-chroot unionfs_dir
  601. mount-chroot archives_dir
  602. mount-chroot vfs
  603. apt-get-update --chroot
  604. [ -f $RPM_PKG ] && Msg_NotPackageName_$LOCALE $RPM_PKG && exit 1
  605. $__chroot_sh "apt-get -y remove $BASE_RPM_PKG"
  606. write-vbuilder-log "remove-rpm $RPM_PKG"
  607. mount-chroot --umount vfs
  608. mount-chroot --umount archives_dir
  609. mount-chroot --umount unionfs_dir
  610. apt-get-update --host
  611. }
  612. RPM_Install(){
  613. setup-vbootstrap-rpm
  614. mount-chroot unionfs_dir
  615. mount-chroot archives_dir
  616. mount-chroot vfs
  617. apt-get-update --chroot
  618. $__chroot_sh "cd ${BUILD_DIR} && apt-get -y install $BASE_RPM_PKG"
  619. write-vbuilder-log "install-rpm $RPM_PKG"
  620. mount-chroot --umount vfs
  621. mount-chroot --umount archives_dir
  622. mount-chroot --umount unionfs_dir
  623. apt-get-update --host
  624. }
  625. RPM_Build(){
  626. setup-vbootstrap-rpm
  627. mount-chroot unionfs_dir
  628. mount-chroot archives_dir
  629. mount-chroot vfs
  630. apt-get-update --chroot
  631. [ ! -f $RPM_PKG ] && Msg_NotSourceRPM_$LOCALE $RPM_PKG && exit 1
  632. RPM_PKG_USER=$(stat -c %U $RPM_PKG)
  633. RPM_PKG_GROUP=$(stat -c %G $RPM_PKG)
  634. [ ! -z "${SUDO_UID}" ] && RPM_PKG_USER=${SUDO_UID}
  635. [ ! -z "${SUDO_GID}" ] && RPM_PKG_GROUP=${SUDO_GID}
  636. local __install="install -p -v -o ${RPM_PKG_USER} -g ${RPM_PKG_GROUP}"
  637. RPM_PKG_ARCH_LIST="RPMS/i386 RPMS/i686 RPMS/x86_64 RPMS/ppc RPMS/noarch SRPMS"
  638. [ -z "${TARGET}" ] || \
  639. RPM_PKG_ARCH_LIST="RPMS/${TARGET} ${RPM_PKG_ARCH_LIST}"
  640. ## make src.rpm for $VERSION
  641. $__chroot_sh "cd ${BUILD_DIR} && su ${BUILD_USER} -c 'rpm -ivh $BASE_RPM_PKG'"
  642. $__chroot_sh "cd ${BUILD_DIR} && su ${BUILD_USER} -c 'rpmbuild -bs --nodeps --clean --rmsource --rmspec ${BUILD_DIR}/SPECS/*.spec'"
  643. ## change ${DIST_RELEASE}
  644. BASE_RPM_PKG=$(echo $BASE_RPM_PKG | sed -e "s/vl\([0-9]*\)\./vl${DIST_RELEASE}\./")
  645. ## rebuild $BASE_RPM_PKG on ${DIST_RELEASE}
  646. $__chroot_sh "cd ${BUILD_DIR}/SRPMS && apt-get -o APT::Install::Virtual=true -y build-dep $BASE_RPM_PKG"
  647. $__chroot_sh "cd ${BUILD_DIR}/SRPMS && su ${BUILD_USER} -c 'rpmbuild --rebuild $RPM_OPTS $BASE_RPM_PKG'"
  648. $__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')"
  649. ## copy built rpms to ${HOME}/rpm/ for each archtectures
  650. echo "Copying built rpms to ${BUILT_RPMS_DIR} for each archtectures ... "
  651. for i in $RPM_PKG_ARCH_LIST; do \
  652. if [ -d $BUILD_ROOT${BUILD_DIR}/${i} ]; then
  653. if [ ! -d ${BUILT_RPMS_DIR}/${MAJOR_VERSION}/${i} ]; then
  654. $__install -d ${BUILT_RPMS_DIR}/${MAJOR_VERSION}/${i}/
  655. chown -R ${RPM_PKG_USER}:${RPM_PKG_GROUP} ${BUILT_RPMS_DIR}
  656. fi
  657. find $BUILD_ROOT${BUILD_DIR}/${i} -type f -regex '.*\.rpm' \
  658. -exec $__install -m0644 {} ${BUILT_RPMS_DIR}/${MAJOR_VERSION}/${i}/ \;
  659. fi
  660. done
  661. write-vbuilder-log "build-rpm $RPM_PKG"
  662. mount-chroot --umount vfs
  663. mount-chroot --umount archives_dir
  664. mount-chroot --umount unionfs_dir
  665. apt-get-update --host
  666. echo "done."
  667. }
  668. ##############################################################################
  669. setup-vbuilder
  670. check-parameter $* || exit 1
  671. while [ $# -gt 0 ]; do
  672. tmpARG=$1
  673. case $tmpARG in
  674. --version|--arch|--category|--target|--bootstrap-dir|--cache-dir|--built-rpms-dir)
  675. shift
  676. ;;
  677. --dist-upgrade|--unionfs|--with-compat32)
  678. ;;
  679. --build-rpm|build-rpm|--install-rpm|install-rpm|--remove-rpm|remove-rpm)
  680. shift
  681. ;;
  682. --build|build|--clean|clean|--show-info|show-info)
  683. ;;
  684. *)
  685. echo unknown option $1
  686. exit 1
  687. ;;
  688. esac
  689. case $tmpARG in
  690. --version)
  691. VERSION=$1
  692. ;;
  693. --arch)
  694. VARCH=$1
  695. ;;
  696. --category)
  697. CATEGORIES=$1
  698. ;;
  699. --dist-upgrade)
  700. with_dist_upgrade=1
  701. ;;
  702. --unionfs)
  703. with_unionfs=1
  704. ;;
  705. --target)
  706. TARGET=$1
  707. RPM_OPTS="${RPM_OPTS} --target $TARGET"
  708. ;;
  709. --with-compat32)
  710. RPM_OPTS="${RPM_OPTS} --with compat32"
  711. ;;
  712. --bootstrap-dir)
  713. VBOOTSTRAP_DIR=$1
  714. ;;
  715. --cache-dir)
  716. CACHE_DIR=$1
  717. ;;
  718. --built-rpms-dir)
  719. BUILT_RPMS_DIR=$1
  720. ;;
  721. --build-rpm|build-rpm)
  722. RPM_PKG=$1
  723. RPM_Build || exit 1
  724. ;;
  725. --install-rpm|install-rpm)
  726. RPM_PKG=$1
  727. RPM_Install || exit 1
  728. ;;
  729. --remove-rpm|remove-rpm)
  730. RPM_PKG=$1
  731. RPM_Remove || exit 1
  732. ;;
  733. --show-info|show-info)
  734. Show-Info
  735. ;;
  736. --build|build)
  737. Build
  738. ;;
  739. --clean|clean)
  740. Clean
  741. ;;
  742. esac
  743. shift
  744. done
  745. exit