vbuilder.sh.in 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924
  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_GiveNoMoreOptions_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_ix86_on_x86_64=0
  242. with_category_main=0
  243. with_category_plus=0
  244. with_category_nonfree=0
  245. with_category_test=0
  246. with_category_proposed_updates=0
  247. with_category_security=0
  248. return 0
  249. }
  250. setup-vbootstrap(){
  251. if [ ${with_setup_vbootstrap} -eq 0 ]; then
  252. with_setup_vbootstrap=1
  253. ## check some directories
  254. ## Note: create $BUILT_RPMS_DIR in RPM_Build()
  255. [ -d $VBOOTSTRAP_DIR ] || mkdir -p $VBOOTSTRAP_DIR
  256. [ -d $CACHE_DIR ] || mkdir -p $CACHE_DIR
  257. ## check a chroot archtecture
  258. if [ -z ${VARCH} ]; then
  259. VARCH=$(uname -i)
  260. else
  261. case "${VARCH}" in
  262. i386|i686|x86_64)
  263. [ "$(uname -i)" = "ppc" ] && \
  264. Msg_NoSupportVARCH_$LOCALE && return 1
  265. ;;
  266. ppc)
  267. [ "$(uname -i)" = "i386" -o "$(uname -i)" = "i686" -o "$(uname -i)" = "x86_64" ] && \
  268. Msg_NoSupportVARCH_$LOCALE && return 1
  269. ;;
  270. esac
  271. fi
  272. ##!! 4.2 is NO support on VARCH=x86_64
  273. if [ "${VERSION}" = "4.2" -a "${VARCH}" = "x86_64" ]; then
  274. Msg_NoSupportVERSION_${LOCALE} && return 1
  275. fi
  276. ## support i386 chroot on x86_64 below:
  277. [ "${VARCH}" != "$(uname -i)" ] && \
  278. VERSION=${VERSION}_${VARCH} && \
  279. with_ix86_on_x86_64=1
  280. ## check support ${VERSION}
  281. if [ -z "$(/usr/sbin/vbootstrap | sed -e s/^Usage:.*// -e s/^E:.*// | grep -m 1 ${VERSION})" ]; then
  282. Msg_NoSupportVERSION_$LOCALE && return 1
  283. fi
  284. ## check ${VERSION} equals VineSeed*, when with_dist_upgrade=1
  285. if [ $with_dist_upgrade -eq 1 ]; then
  286. if [ "$(echo ${VERSION} | sed -e "s/\(VineSeed\).*/\1/")" != "VineSeed" ]; then
  287. Msg_NoSupportDistUpgradeVERSION_$LOCALE && return 1
  288. fi
  289. fi
  290. ## set ${MAJOR_VERSION}
  291. MAJOR_VERSION=$(echo ${VERSION} | sed -e "s/_i[0-9]86//")
  292. ## check apt categories
  293. ## "main" category is unconditionally permited
  294. with_category_main=1
  295. for cat in $(echo ${CATEGORIES} | sed -e "s/,/ /"g); do
  296. case $cat in
  297. main)
  298. with_category_main=1
  299. ;;
  300. plus)
  301. with_category_plus=1
  302. ;;
  303. nonfree)
  304. with_category_nonfree=1
  305. ;;
  306. test)
  307. ## "test" category only exists in VineSeed
  308. [ "${MAJOR_VERSION}" = "VineSeed" ] || \
  309. Msg_NoSuchCategoryExists_$LOCALE ${cat} && return 1
  310. with_category_test=1
  311. ;;
  312. proposed-updates)
  313. ##!! "proposed-updates" category does not exist in 4.2
  314. [ "${MAJOR_VERSION}" = "4.2" ] && \
  315. Msg_NoSuchCategoryExists_$LOCALE ${cat} && return 1
  316. with_category_proposed_updates=1
  317. ;;
  318. security)
  319. ## "security" category does not exist in VineSeed
  320. [ "${MAJOR_VERSION}" = "VineSeed" ] && \
  321. Msg_NoSuchCategoryExists_$LOCALE ${cat} && return 1
  322. with_category_security=1
  323. ;;
  324. *)
  325. Msg_NoSuchCategoryExists_$LOCALE ${cat} && return 1
  326. ;;
  327. esac
  328. done
  329. ## check build target option ${TARGET}
  330. if [ ! -z "${TARGET}" ]; then
  331. RPM_TARGET_LIST="$(cat /usr/lib/rpm/rpmrc | grep arch_canon: | sed -e "s/arch_canon:[[:blank:]]*\(.*\):.*/\1/")"
  332. if [ -z "$(echo $RPM_TARGET_LIST | grep $TARGET)" ]; then
  333. Msg_NoSupportTARGET_$LOCALE && return 1
  334. fi
  335. fi
  336. ## set ${RPM_PKG_ARCH_LIST}
  337. RPM_PKG_ARCH_LIST="RPMS/i386 RPMS/i686 RPMS/x86_64 RPMS/ppc RPMS/noarch SRPMS"
  338. [ -z "${TARGET}" ] || \
  339. RPM_PKG_ARCH_LIST="RPMS/${TARGET} ${RPM_PKG_ARCH_LIST}"
  340. fi
  341. ## set global variables
  342. BUILD_ROOT=${VBOOTSTRAP_DIR}/${VERSION}
  343. BUILD_USER=vbuilder
  344. BUILD_DIR=/home/${BUILD_USER}/rpm
  345. UNIONFS_DIR=${VBOOTSTRAP_DIR}/unionfs/${VERSION}
  346. ARCHIVES_DIR=${BUILD_ROOT}/var/cache/apt/archives
  347. EXTERNAL_ARCHIVES_DIR=${CACHE_DIR}/${VERSION}/apt/archives
  348. VBUILDER_LOG=${BUILD_ROOT}/var/log/vbuilder.log
  349. __chroot_sh="/usr/sbin/chroot ${BUILD_ROOT} /bin/sh -c"
  350. mkdir -p $VBOOTSTRAP_DIR
  351. return 0
  352. }
  353. setup-vbootstrap-rpm(){
  354. setup-vbootstrap || return 1
  355. ## check ${BUILD_ROOT}
  356. [ -d ${BUILD_ROOT} ] || Build
  357. ## setarch ix86 if ix86 chroot on x86_64 host
  358. [ $with_ix86_on_x86_64 -eq 1 ] && \
  359. __chroot_sh="/usr/sbin/chroot ${BUILD_ROOT} setarch ${VARCH} /bin/sh -c"
  360. DIST_RELEASE=$(cat ${BUILD_ROOT}/etc/vine-release | cut -f3 -d" " | cut -f1 -d.)
  361. if [ -f $RPM_PKG ]; then
  362. BASE_RPM_PKG=$(basename $RPM_PKG)
  363. cp -f $RPM_PKG $BUILD_ROOT${BUILD_DIR}
  364. else
  365. BASE_RPM_PKG=$RPM_PKG
  366. fi
  367. return 0
  368. }
  369. ## recover apt-get data on host/chroot
  370. apt-get-update(){
  371. case $1 in
  372. --host)
  373. echo -n "apt-get update on host ... "
  374. apt-get -qq update > /dev/null 2>&1
  375. echo "done."
  376. ;;
  377. --chroot)
  378. echo -n "apt-get update on chroot ... "
  379. $__chroot_sh 'apt-get -qq update' > /dev/null 2>&1
  380. echo "done."
  381. ;;
  382. *)
  383. echo apt-get-update: unknown option $1
  384. exit 1
  385. ;;
  386. esac
  387. }
  388. ## mount-chroot {|--umount} [file system|name]
  389. ## support file systems: /home /tmp /sys /proc /dev/shm /dev/pts /dev
  390. ## support name: vfs archives_dir
  391. ## NOTE: /tmp needs for applications which use X
  392. ## vfs is virtual file systems
  393. ## archives_dir uses to mount ${EXTERNAL_ARCHIVES_DIR} to ${ARCHIVES_DIR}
  394. ## unionfs_dir covers ${BUILD_ROOT} with unionfs
  395. mount-chroot(){
  396. if [ "$1" = "--umount" ]; then
  397. mount-chroot-umount $2 || return 1
  398. else
  399. mount-chroot-mount $1 || return 1
  400. fi
  401. return 0
  402. }
  403. ## mount-chroot-umount [file system|name]
  404. mount-chroot-umount(){
  405. local fs=$1
  406. case $fs in
  407. /home|/tmp|/sys|/proc|/dev/shm|/dev/pts|/dev)
  408. [ -d ${BUILD_ROOT}${fs} ] || return 1
  409. [ -z "$(mount | grep ${BUILD_ROOT}${fs})" ] || \
  410. umount ${BUILD_ROOT}${fs}
  411. ;;
  412. vfs)
  413. # for dir in /sys /proc /dev/shm /dev/pts /dev; do
  414. # mount-chroot-umount ${dir} || return 1
  415. # done
  416. [ -d ${BUILD_ROOT}/proc ] || return 1
  417. [ -z "$(mount | grep ${BUILD_ROOT}/proc)" ] || \
  418. umount ${BUILD_ROOT}/proc
  419. ;;
  420. archives_dir)
  421. [ -d ${ARCHIVES_DIR} ] || return 1
  422. [ -z "$(mount | grep ${ARCHIVES_DIR})" ] || \
  423. umount ${ARCHIVES_DIR}
  424. ;;
  425. unionfs_dir)
  426. [ -d ${BUILD_ROOT} ] || return 1
  427. [ -z "$(mount | grep ${BUILD_ROOT} | grep unionfs)" ] || \
  428. umount ${BUILD_ROOT}
  429. if [ ! -z "$(mount | grep ${BUILD_ROOT} | grep unionfs)" ]; then
  430. echo "Retry lazy unmount ... "
  431. umount -l ${BUILD_ROOT}
  432. echo "done."
  433. fi
  434. ;;
  435. *)
  436. echo mount-chroot-umount: unknown file system $fs
  437. exit 1
  438. ;;
  439. esac
  440. return 0
  441. }
  442. ## mount-chroot-mount [file system|name]
  443. mount-chroot-mount(){
  444. local fs=$1
  445. local mnt_opts=""
  446. case $fs in
  447. /home)
  448. mnt_opts="-o rbind"
  449. ;;
  450. *)
  451. mnt_opts="--bind"
  452. ;;
  453. esac
  454. case $fs in
  455. /home|/tmp|/sys|/proc|/dev/shm|/dev/pts|/dev)
  456. [ -d ${BUILD_ROOT}${fs} ] || mkdir -p ${BUILD_ROOT}${fs}
  457. [ -z "$(mount | grep ${BUILD_ROOT}${fs})" ] && \
  458. mount ${mnt_opts} ${fs} ${BUILD_ROOT}${fs}
  459. ;;
  460. vfs)
  461. # for dir in /dev /dev/pts /dev/shm /proc /sys; do
  462. # mount-chroot-mount ${dir} || return 1
  463. # done
  464. mount-chroot-mount /proc || return 1
  465. ;;
  466. archives_dir)
  467. [ -d ${EXTERNAL_ARCHIVES_DIR} ] || mkdir -p ${EXTERNAL_ARCHIVES_DIR}
  468. [ -d ${ARCHIVES_DIR} ] || mkdir -p ${ARCHIVES_DIR}
  469. [ -z "$(mount | grep ${ARCHIVES_DIR})" ] && \
  470. mount ${mnt_opts} ${EXTERNAL_ARCHIVES_DIR} ${ARCHIVES_DIR}
  471. [ -d ${ARCHIVES_DIR}/partial ] || mkdir -p ${ARCHIVES_DIR}/partial
  472. ;;
  473. unionfs_dir)
  474. if [ $with_unionfs -eq 1 ]; then
  475. [ -d ${UNIONFS_DIR} ] || mkdir -p ${UNIONFS_DIR}
  476. [ -z "$(mount | grep ${BUILD_ROOT})" ] && \
  477. mount -t unionfs -o dirs=${UNIONFS_DIR}=rw:${BUILD_ROOT}=ro unionfs ${BUILD_ROOT}
  478. unionctl ${BUILD_ROOT} --list
  479. fi
  480. ;;
  481. *)
  482. echo mount-chroot-mount: unknown file system $fs
  483. exit 1
  484. ;;
  485. esac
  486. return 0
  487. }
  488. write-vbuilder-log(){
  489. HRULE="======================================================================"
  490. [ -d ${BUILD_ROOT} ] || return 1
  491. if [ ! -f $VBUILDER_LOG ]; then
  492. cat<<EOF > $VBUILDER_LOG
  493. ${HRULE}
  494. VBUILDER REPORT
  495. DATE: $(LANG=C date)
  496. HOSTNAME: $(hostname)
  497. OS: $(echo $($__chroot_sh "cat /etc/vine-release"))
  498. %_arch: $(echo $($__chroot_sh "rpm --eval %_arch"))
  499. --version: ${VERSION}
  500. $(echo $([ -z "${VARCH}" ] || echo "--arch: ${VARCH}"))
  501. $(echo $([ -z "${CATEGORIES}" ] || echo "--category: ${CATEGORIES}"))
  502. $(echo $([ $with_dist_upgrade -eq 1 ] && echo "--dist-upgrade"))
  503. $(echo $([ $with_unionfs -eq 1 ] && echo "--unionfs"))
  504. $(echo $([ -z "${TARGET}" ] || echo "--target: ${TARGET}"))
  505. --bootstrap-dir: ${VBOOTSTRAP_DIR}
  506. --cache-dir: ${CACHE_DIR}
  507. --built-rpms-dir: ${BUILT_RPMS_DIR}
  508. ${HRULE}
  509. [$VBUILDER_CONF]
  510. $(cat $VBUILDER_CONF)
  511. [History]
  512. EOF
  513. else
  514. cat<<EOF >> $VBUILDER_LOG
  515. $*
  516. EOF
  517. fi
  518. return 0
  519. }
  520. ##############################################################################
  521. Clean(){
  522. setup-vbootstrap || return 1
  523. # # output end-of-line in $VBUILDER_LOG
  524. # [ -f $VBUILDER_LOG ] && write-vbuilder-log ${HRULE}
  525. # Show-Info
  526. # mount-chroot --umount /home
  527. # mount-chroot --umount /tmp
  528. mount-chroot --umount vfs
  529. mount-chroot --umount archives_dir
  530. mount-chroot --umount unionfs_dir
  531. apt-get-update --host
  532. if [ $with_unionfs -eq 1 ]; then
  533. if [ -d ${UNIONFS_DIR} ]; then
  534. echo -n "Cleaning build root \"${UNIONFS_DIR}\" via unionfs ... "
  535. rm -rf ${UNIONFS_DIR}
  536. echo "done."
  537. fi
  538. else
  539. if [ -d ${BUILD_ROOT} ]; then
  540. echo -n "Cleaning build root \"${BUILD_ROOT}\" ... "
  541. rm -rf ${BUILD_ROOT}
  542. echo "done."
  543. fi
  544. fi
  545. echo "Cleanup a build farm for ${VERSION} done."
  546. return 0
  547. }
  548. Build(){
  549. setup-vbootstrap || return 1
  550. if [ $with_dist_upgrade -eq 1 ]; then
  551. ## make bootstrap of ${STABLE_VERSION}
  552. /usr/sbin/vbootstrap \
  553. $(echo ${VERSION} | sed -e "s/VineSeed/${STABLE_VERSION}/") \
  554. ${BUILD_ROOT}
  555. ## aim apt-line to VineSeed
  556. sed -i "s/apt ${STABLE_VERSION}/apt VineSeed/g" \
  557. ${BUILD_ROOT}/etc/apt/sources.list.d/main.list
  558. else
  559. /usr/sbin/vbootstrap ${VERSION} ${BUILD_ROOT}
  560. fi
  561. mount-chroot archives_dir
  562. mount-chroot vfs
  563. # mount-chroot /tmp
  564. # mount-chroot /home
  565. $__chroot_sh 'apt-get -qq update && apt-get -qq -y dist-upgrade'
  566. ##!! 4.2 has no apt-sourceslist-{plus,nonfree,proposed-updates} packages
  567. case ${MAJOR_VERSION} in
  568. 4.2)
  569. $__chroot_sh "sed -i -e 's/main plus updates nonfree *$/$(echo ${CATEGORIES} | sed -e "s/,/ /"g) updates/g' /etc/apt/sources.list"
  570. # [ $with_category_security -eq 1 ] && \
  571. # echo
  572. ;;
  573. @@VBUILDER_STABLE_VERSION@@)
  574. [ $with_category_plus -eq 1 ] && \
  575. $__chroot_sh 'apt-get -qq update && apt-get -qq -y install apt-sourceslist-plus'
  576. [ $with_category_nonfree -eq 1 ] && \
  577. $__chroot_sh 'apt-get -qq update && apt-get -qq -y install apt-sourceslist-nonfree'
  578. [ $with_category_proposed_updates -eq 1 ] && \
  579. $__chroot_sh 'apt-get -qq update && apt-get -qq -y install apt-sourceslist-proposed-updates'
  580. # [ $with_category_security -eq 1 ] && \
  581. # echo
  582. ;;
  583. VineSeed)
  584. [ $with_category_plus -eq 1 ] && \
  585. $__chroot_sh 'apt-get -qq update && apt-get -qq -y install apt-sourceslist-plus'
  586. [ $with_category_nonfree -eq 1 ] && \
  587. $__chroot_sh 'apt-get -qq update && apt-get -qq -y install apt-sourceslist-nonfree'
  588. [ $with_category_test -eq 1 ] && \
  589. $__chroot_sh 'apt-get -qq update && apt-get -qq -y install apt-sourceslist-test'
  590. ;;
  591. esac
  592. [ $with_dist_upgrade -eq 1 ] && \
  593. $__chroot_sh 'apt-get -qq update && apt-get -qq -y dist-upgrade'
  594. $__chroot_sh 'apt-get -qq -y install build-essential'
  595. [ $with_category_nonfree -eq 1 ] && \
  596. $__chroot_sh 'apt-get -qq -y install self-build-setup'
  597. $__chroot_sh 'apt-get -qq -y install etcskel shadow-utils'
  598. $__chroot_sh 'cd /dev && /sbin/MAKEDEV console'
  599. $__chroot_sh 'cd /dev && /sbin/MAKEDEV null'
  600. $__chroot_sh 'cd /dev && /sbin/MAKEDEV zero'
  601. $__chroot_sh 'cd /dev && /sbin/MAKEDEV random'
  602. $__chroot_sh 'cd /dev && /sbin/MAKEDEV urandom'
  603. $__chroot_sh '/usr/sbin/pwconv'
  604. $__chroot_sh "/usr/sbin/useradd ${BUILD_USER}"
  605. ##!! for rpm-4.8.0 or higher
  606. ##!! (See http://trac.vinelinux.org/wiki/Vine6/AboutUpdateToolchain)
  607. if [ "$(echo ${VERSION} | sed -e "s/\(VineSeed\).*/\1/")" = "VineSeed" ]; then
  608. $__chroot_sh "sed -i -e 's/^%_topdir/#%_topdir/' /home/${BUILD_USER}/.rpmmacros"
  609. fi
  610. ## output basic informations in chroot
  611. write-vbuilder-log
  612. write-vbuilder-log "build"
  613. # mount-chroot --umount /home
  614. # mount-chroot --umount /tmp
  615. mount-chroot --umount vfs
  616. mount-chroot --umount archives_dir
  617. apt-get-update --host
  618. echo "Making a build farm for ${VERSION} done."
  619. return 0
  620. }
  621. Show-Info(){
  622. setup-vbootstrap || return 1
  623. [ -f $VBUILDER_LOG ] && cat $VBUILDER_LOG
  624. return 0
  625. }
  626. RPM_Remove(){
  627. setup-vbootstrap-rpm || return 1
  628. mount-chroot unionfs_dir
  629. mount-chroot archives_dir
  630. mount-chroot vfs
  631. apt-get-update --chroot
  632. [ -f $RPM_PKG ] && Msg_NotPackageName_$LOCALE $RPM_PKG && return 1
  633. $__chroot_sh "apt-get -y remove $BASE_RPM_PKG"
  634. write-vbuilder-log "remove-rpm $RPM_PKG"
  635. mount-chroot --umount vfs
  636. mount-chroot --umount archives_dir
  637. mount-chroot --umount unionfs_dir
  638. apt-get-update --host
  639. return 0
  640. }
  641. RPM_Install(){
  642. setup-vbootstrap-rpm || return 1
  643. mount-chroot unionfs_dir
  644. mount-chroot archives_dir
  645. mount-chroot vfs
  646. apt-get-update --chroot
  647. $__chroot_sh "cd ${BUILD_DIR} && apt-get -y install $BASE_RPM_PKG"
  648. write-vbuilder-log "install-rpm $RPM_PKG"
  649. mount-chroot --umount vfs
  650. mount-chroot --umount archives_dir
  651. mount-chroot --umount unionfs_dir
  652. apt-get-update --host
  653. return 0
  654. }
  655. RPM_Build(){
  656. setup-vbootstrap-rpm || return 1
  657. mount-chroot unionfs_dir
  658. mount-chroot archives_dir
  659. mount-chroot vfs
  660. apt-get-update --chroot
  661. [ ! -f $RPM_PKG ] && Msg_NotSourceRPM_$LOCALE $RPM_PKG && return 1
  662. RPM_PKG_USER=$(stat -c %U $RPM_PKG)
  663. RPM_PKG_GROUP=$(stat -c %G $RPM_PKG)
  664. [ ! -z "${SUDO_UID}" ] && RPM_PKG_USER=${SUDO_UID}
  665. [ ! -z "${SUDO_GID}" ] && RPM_PKG_GROUP=${SUDO_GID}
  666. local __install="install -p -v -o ${RPM_PKG_USER} -g ${RPM_PKG_GROUP}"
  667. ## make src.rpm for $VERSION
  668. $__chroot_sh "cd ${BUILD_DIR} && su ${BUILD_USER} -c 'rpm -ivh $BASE_RPM_PKG'"
  669. $__chroot_sh "cd ${BUILD_DIR} && su ${BUILD_USER} -c 'rpmbuild -bs --nodeps --clean --rmsource --rmspec $RPM_OPTS ${BUILD_DIR}/SPECS/*.spec'"
  670. ## change ${DIST_RELEASE}
  671. BASE_RPM_PKG=$(echo $BASE_RPM_PKG | sed -e "s/vl\([0-9]*\)\./vl${DIST_RELEASE}\./")
  672. ## rebuild $BASE_RPM_PKG on ${DIST_RELEASE}
  673. $__chroot_sh "cd ${BUILD_DIR}/SRPMS && apt-get -o APT::Install::Virtual=true -y build-dep $BASE_RPM_PKG"
  674. $__chroot_sh "cd ${BUILD_DIR}/SRPMS && su ${BUILD_USER} -c 'rpmbuild --rebuild $RPM_OPTS $BASE_RPM_PKG'"
  675. [ $with_no_install -eq 0 ] && \
  676. $__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')"
  677. ## copy built rpms to ${HOME}/rpm/ for each archtectures
  678. echo "Copying built rpms to ${BUILT_RPMS_DIR} for each archtectures ... "
  679. for i in $RPM_PKG_ARCH_LIST; do \
  680. if [ -d $BUILD_ROOT${BUILD_DIR}/${i} ]; then
  681. if [ ! -d ${BUILT_RPMS_DIR}/${MAJOR_VERSION}/${i} ]; then
  682. $__install -d ${BUILT_RPMS_DIR}/${MAJOR_VERSION}/${i}/
  683. chown -R ${RPM_PKG_USER}:${RPM_PKG_GROUP} ${BUILT_RPMS_DIR}
  684. fi
  685. find $BUILD_ROOT${BUILD_DIR}/${i} -type f -regex '.*\.rpm' \
  686. -exec $__install -m0644 {} ${BUILT_RPMS_DIR}/${MAJOR_VERSION}/${i}/ \;
  687. fi
  688. done
  689. write-vbuilder-log "build-rpm $RPM_PKG"
  690. mount-chroot --umount vfs
  691. mount-chroot --umount archives_dir
  692. mount-chroot --umount unionfs_dir
  693. apt-get-update --host
  694. echo "done."
  695. return 0
  696. }
  697. RPM_Sign(){
  698. [ $with_sign -eq 1 ] || return 1
  699. [ -z "${SUDO_USER}" ] && Msg_SUDO_USERisEmpty_$LOCALE && return 1
  700. 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')"
  701. return 0
  702. }
  703. ##############################################################################
  704. setup-vbuilder || exit 1
  705. check-parameter $* || exit 1
  706. while [ $# -gt 0 ]; do
  707. tmpARG=$1
  708. case $tmpARG in
  709. --version|--arch|--category|--target|--rpmbuild-with|--bootstrap-dir|--cache-dir|--built-rpms-dir)
  710. shift
  711. ;;
  712. --dist-upgrade|--unionfs|--with-compat32|--sign|--no-install)
  713. ;;
  714. --build-rpm|build-rpm|--install-rpm|install-rpm|--remove-rpm|remove-rpm)
  715. shift
  716. ;;
  717. --build|build|--clean|clean|--show-info|show-info)
  718. ;;
  719. *)
  720. echo unknown option $1
  721. exit 1
  722. ;;
  723. esac
  724. case $tmpARG in
  725. --version)
  726. VERSION=$1
  727. ;;
  728. --arch)
  729. VARCH=$1
  730. ;;
  731. --category)
  732. CATEGORIES=$1
  733. ;;
  734. --dist-upgrade)
  735. with_dist_upgrade=1
  736. ;;
  737. --unionfs)
  738. with_unionfs=1
  739. ;;
  740. --target)
  741. TARGET=$1
  742. RPM_OPTS="${RPM_OPTS} --target $TARGET"
  743. ;;
  744. --with-compat32)
  745. RPM_OPTS="${RPM_OPTS} --with compat32"
  746. ;;
  747. --rpmbuild-with)
  748. RPM_OPTS="${RPM_OPTS} --with $1"
  749. ;;
  750. --sign)
  751. with_sign=1
  752. ;;
  753. --no-install)
  754. with_no_install=1
  755. ;;
  756. --bootstrap-dir)
  757. VBOOTSTRAP_DIR=$1
  758. ;;
  759. --cache-dir)
  760. CACHE_DIR=$1
  761. ;;
  762. --built-rpms-dir)
  763. BUILT_RPMS_DIR=$1
  764. ;;
  765. --build-rpm|build-rpm)
  766. RPM_PKG=$1
  767. RPM_Build || exit 1
  768. ;;
  769. --install-rpm|install-rpm)
  770. RPM_PKG=$1
  771. RPM_Install || exit 1
  772. ;;
  773. --remove-rpm|remove-rpm)
  774. RPM_PKG=$1
  775. RPM_Remove || exit 1
  776. ;;
  777. --show-info|show-info)
  778. Show-Info || exit 1
  779. ;;
  780. --build|build)
  781. Build || exit 1
  782. ;;
  783. --clean|clean)
  784. Clean || exit 1
  785. ;;
  786. esac
  787. shift
  788. done
  789. RPM_Sign
  790. exit