vbuilder.sh.in 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934
  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 -l"
  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 -l"
  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. require-root(){
  521. if [ $USER != "root" ]; then
  522. echo "The root privilege is required."
  523. sudo $0 $*
  524. return $?
  525. fi
  526. }
  527. ##############################################################################
  528. Clean(){
  529. setup-vbootstrap || return 1
  530. # # output end-of-line in $VBUILDER_LOG
  531. # [ -f $VBUILDER_LOG ] && write-vbuilder-log ${HRULE}
  532. # Show-Info
  533. # mount-chroot --umount /home
  534. # mount-chroot --umount /tmp
  535. mount-chroot --umount vfs
  536. mount-chroot --umount archives_dir
  537. mount-chroot --umount unionfs_dir
  538. apt-get-update --host
  539. if [ $with_unionfs -eq 1 ]; then
  540. if [ -d ${UNIONFS_DIR} ]; then
  541. echo -n "Cleaning build root \"${UNIONFS_DIR}\" via unionfs ... "
  542. rm -rf ${UNIONFS_DIR}
  543. echo "done."
  544. fi
  545. else
  546. if [ -d ${BUILD_ROOT} ]; then
  547. echo -n "Cleaning build root \"${BUILD_ROOT}\" ... "
  548. rm -rf ${BUILD_ROOT}
  549. echo "done."
  550. fi
  551. fi
  552. echo "Cleanup a build farm for ${VERSION} done."
  553. return 0
  554. }
  555. Build(){
  556. setup-vbootstrap || return 1
  557. if [ $with_dist_upgrade -eq 1 ]; then
  558. ## make bootstrap of ${STABLE_VERSION}
  559. /usr/sbin/vbootstrap \
  560. $(echo ${VERSION} | sed -e "s/VineSeed/${STABLE_VERSION}/") \
  561. ${BUILD_ROOT}
  562. ## aim apt-line to VineSeed
  563. sed -i "s/apt ${STABLE_VERSION}/apt VineSeed/g" \
  564. ${BUILD_ROOT}/etc/apt/sources.list.d/main.list
  565. else
  566. /usr/sbin/vbootstrap ${VERSION} ${BUILD_ROOT}
  567. fi
  568. mount-chroot archives_dir
  569. mount-chroot vfs
  570. # mount-chroot /tmp
  571. # mount-chroot /home
  572. $__chroot_sh 'apt-get -qq update && apt-get -qq -y dist-upgrade'
  573. ##!! 4.2 has no apt-sourceslist-{plus,nonfree,proposed-updates} packages
  574. case ${MAJOR_VERSION} in
  575. 4.2)
  576. $__chroot_sh "sed -i -e 's/main plus updates nonfree *$/$(echo ${CATEGORIES} | sed -e "s/,/ /"g) updates/g' /etc/apt/sources.list"
  577. # [ $with_category_security -eq 1 ] && \
  578. # echo
  579. ;;
  580. @@VBUILDER_STABLE_VERSION@@)
  581. [ $with_category_plus -eq 1 ] && \
  582. $__chroot_sh 'apt-get -qq update && apt-get -qq -y install apt-sourceslist-plus'
  583. [ $with_category_nonfree -eq 1 ] && \
  584. $__chroot_sh 'apt-get -qq update && apt-get -qq -y install apt-sourceslist-nonfree'
  585. [ $with_category_proposed_updates -eq 1 ] && \
  586. $__chroot_sh 'apt-get -qq update && apt-get -qq -y install apt-sourceslist-proposed-updates'
  587. # [ $with_category_security -eq 1 ] && \
  588. # echo
  589. ;;
  590. VineSeed)
  591. [ $with_category_plus -eq 1 ] && \
  592. $__chroot_sh 'apt-get -qq update && apt-get -qq -y install apt-sourceslist-plus'
  593. [ $with_category_nonfree -eq 1 ] && \
  594. $__chroot_sh 'apt-get -qq update && apt-get -qq -y install apt-sourceslist-nonfree'
  595. [ $with_category_test -eq 1 ] && \
  596. $__chroot_sh 'apt-get -qq update && apt-get -qq -y install apt-sourceslist-test'
  597. ;;
  598. esac
  599. [ $with_dist_upgrade -eq 1 ] && \
  600. $__chroot_sh 'apt-get -qq update && apt-get -qq -y dist-upgrade'
  601. $__chroot_sh 'apt-get -qq -y install build-essential'
  602. [ $with_category_nonfree -eq 1 ] && \
  603. $__chroot_sh 'apt-get -qq -y install self-build-setup'
  604. $__chroot_sh 'apt-get -qq -y install etcskel shadow-utils'
  605. $__chroot_sh 'cd /dev && /sbin/MAKEDEV console'
  606. $__chroot_sh 'cd /dev && /sbin/MAKEDEV null'
  607. $__chroot_sh 'cd /dev && /sbin/MAKEDEV zero'
  608. $__chroot_sh 'cd /dev && /sbin/MAKEDEV random'
  609. $__chroot_sh 'cd /dev && /sbin/MAKEDEV urandom'
  610. $__chroot_sh '/usr/sbin/pwconv'
  611. $__chroot_sh "/usr/sbin/useradd ${BUILD_USER}"
  612. ##!! for rpm-4.8.0 or higher
  613. ##!! (See http://trac.vinelinux.org/wiki/Vine6/AboutUpdateToolchain)
  614. if [ "$(echo ${VERSION} | sed -e "s/\(VineSeed\).*/\1/")" = "VineSeed" ]; then
  615. $__chroot_sh "sed -i -e 's/^%_topdir/#%_topdir/' /home/${BUILD_USER}/.rpmmacros"
  616. fi
  617. ## output basic informations in chroot
  618. write-vbuilder-log
  619. write-vbuilder-log "build"
  620. # mount-chroot --umount /home
  621. # mount-chroot --umount /tmp
  622. mount-chroot --umount vfs
  623. mount-chroot --umount archives_dir
  624. apt-get-update --host
  625. echo "Making a build farm for ${VERSION} done."
  626. return 0
  627. }
  628. Show-Info(){
  629. setup-vbootstrap || return 1
  630. [ -f $VBUILDER_LOG ] && cat $VBUILDER_LOG
  631. return 0
  632. }
  633. RPM_Remove(){
  634. setup-vbootstrap-rpm || return 1
  635. mount-chroot unionfs_dir
  636. mount-chroot archives_dir
  637. mount-chroot vfs
  638. apt-get-update --chroot
  639. [ -f $RPM_PKG ] && Msg_NotPackageName_$LOCALE $RPM_PKG && return 1
  640. $__chroot_sh "apt-get -y remove $BASE_RPM_PKG"
  641. write-vbuilder-log "remove-rpm $RPM_PKG"
  642. mount-chroot --umount vfs
  643. mount-chroot --umount archives_dir
  644. mount-chroot --umount unionfs_dir
  645. apt-get-update --host
  646. return 0
  647. }
  648. RPM_Install(){
  649. setup-vbootstrap-rpm || return 1
  650. mount-chroot unionfs_dir
  651. mount-chroot archives_dir
  652. mount-chroot vfs
  653. apt-get-update --chroot
  654. $__chroot_sh "cd ${BUILD_DIR} && apt-get -y install $BASE_RPM_PKG"
  655. write-vbuilder-log "install-rpm $RPM_PKG"
  656. mount-chroot --umount vfs
  657. mount-chroot --umount archives_dir
  658. mount-chroot --umount unionfs_dir
  659. apt-get-update --host
  660. return 0
  661. }
  662. RPM_Build(){
  663. setup-vbootstrap-rpm || return 1
  664. mount-chroot unionfs_dir
  665. mount-chroot archives_dir
  666. mount-chroot vfs
  667. apt-get-update --chroot
  668. [ ! -f $RPM_PKG ] && Msg_NotSourceRPM_$LOCALE $RPM_PKG && return 1
  669. RPM_PKG_USER=$(stat -c %U $RPM_PKG)
  670. RPM_PKG_GROUP=$(stat -c %G $RPM_PKG)
  671. [ ! -z "${SUDO_UID}" ] && RPM_PKG_USER=${SUDO_UID}
  672. [ ! -z "${SUDO_GID}" ] && RPM_PKG_GROUP=${SUDO_GID}
  673. local __install="install -p -v -o ${RPM_PKG_USER} -g ${RPM_PKG_GROUP}"
  674. ## make src.rpm for $VERSION
  675. $__chroot_sh "cd ${BUILD_DIR} && su ${BUILD_USER} -c 'rpm -ivh $BASE_RPM_PKG'"
  676. $__chroot_sh "cd ${BUILD_DIR} && su ${BUILD_USER} -c 'rpmbuild -bs --nodeps --clean --rmsource --rmspec $RPM_OPTS ${BUILD_DIR}/SPECS/*.spec'"
  677. ## change ${DIST_RELEASE}
  678. BASE_RPM_PKG=$(echo $BASE_RPM_PKG | sed -e "s/vl\([0-9]*\)\./vl${DIST_RELEASE}\./")
  679. ## rebuild $BASE_RPM_PKG on ${DIST_RELEASE}
  680. $__chroot_sh "cd ${BUILD_DIR}/SRPMS && apt-get -o APT::Install::Virtual=true -y build-dep $BASE_RPM_PKG"
  681. $__chroot_sh "cd ${BUILD_DIR}/SRPMS && su ${BUILD_USER} -c 'rpmbuild --rebuild $RPM_OPTS $BASE_RPM_PKG'"
  682. [ $with_no_install -eq 0 ] && \
  683. $__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')"
  684. ## copy built rpms to ${HOME}/rpm/ for each archtectures
  685. echo "Copying built rpms to ${BUILT_RPMS_DIR} for each archtectures ... "
  686. for i in $RPM_PKG_ARCH_LIST; do \
  687. if [ -d $BUILD_ROOT${BUILD_DIR}/${i} ]; then
  688. if [ ! -d ${BUILT_RPMS_DIR}/${MAJOR_VERSION}/${i} ]; then
  689. $__install -d ${BUILT_RPMS_DIR}/${MAJOR_VERSION}/${i}/
  690. chown -R ${RPM_PKG_USER}:${RPM_PKG_GROUP} ${BUILT_RPMS_DIR}
  691. fi
  692. find $BUILD_ROOT${BUILD_DIR}/${i} -type f -regex '.*\.rpm' \
  693. -exec $__install -m0644 {} ${BUILT_RPMS_DIR}/${MAJOR_VERSION}/${i}/ \;
  694. fi
  695. done
  696. write-vbuilder-log "build-rpm $RPM_PKG"
  697. mount-chroot --umount vfs
  698. mount-chroot --umount archives_dir
  699. mount-chroot --umount unionfs_dir
  700. apt-get-update --host
  701. echo "done."
  702. return 0
  703. }
  704. RPM_Sign(){
  705. [ $with_sign -eq 1 ] || return 1
  706. [ -z "${SUDO_USER}" ] && Msg_SUDO_USERisEmpty_$LOCALE && return 1
  707. 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')"
  708. return 0
  709. }
  710. ##############################################################################
  711. require-root $* || exit 1
  712. setup-vbuilder || exit 1
  713. check-parameter $* || exit 1
  714. while [ $# -gt 0 ]; do
  715. tmpARG=$1
  716. case $tmpARG in
  717. --version|--arch|--category|--target|--rpmbuild-with|--bootstrap-dir|--cache-dir|--built-rpms-dir)
  718. shift
  719. ;;
  720. --dist-upgrade|--unionfs|--with-compat32|--sign|--no-install)
  721. ;;
  722. --build-rpm|build-rpm|--install-rpm|install-rpm|--remove-rpm|remove-rpm)
  723. shift
  724. ;;
  725. --build|build|--clean|clean|--show-info|show-info)
  726. ;;
  727. *)
  728. echo unknown option $1
  729. exit 1
  730. ;;
  731. esac
  732. case $tmpARG in
  733. --version)
  734. VERSION=$1
  735. ;;
  736. --arch)
  737. VARCH=$1
  738. ;;
  739. --category)
  740. CATEGORIES=$1
  741. ;;
  742. --dist-upgrade)
  743. with_dist_upgrade=1
  744. ;;
  745. --unionfs)
  746. with_unionfs=1
  747. ;;
  748. --target)
  749. TARGET=$1
  750. RPM_OPTS="${RPM_OPTS} --target $TARGET"
  751. ;;
  752. --with-compat32)
  753. RPM_OPTS="${RPM_OPTS} --with compat32"
  754. ;;
  755. --rpmbuild-with)
  756. RPM_OPTS="${RPM_OPTS} --with $1"
  757. ;;
  758. --sign)
  759. with_sign=1
  760. ;;
  761. --no-install)
  762. with_no_install=1
  763. ;;
  764. --bootstrap-dir)
  765. VBOOTSTRAP_DIR=$1
  766. ;;
  767. --cache-dir)
  768. CACHE_DIR=$1
  769. ;;
  770. --built-rpms-dir)
  771. BUILT_RPMS_DIR=$1
  772. ;;
  773. --build-rpm|build-rpm)
  774. RPM_PKG=$1
  775. RPM_Build || exit 1
  776. ;;
  777. --install-rpm|install-rpm)
  778. RPM_PKG=$1
  779. RPM_Install || exit 1
  780. ;;
  781. --remove-rpm|remove-rpm)
  782. RPM_PKG=$1
  783. RPM_Remove || exit 1
  784. ;;
  785. --show-info|show-info)
  786. Show-Info || exit 1
  787. ;;
  788. --build|build)
  789. Build || exit 1
  790. ;;
  791. --clean|clean)
  792. Clean || exit 1
  793. ;;
  794. esac
  795. shift
  796. done
  797. RPM_Sign
  798. exit