vbuilder.sh.in 24 KB

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