vbuilder.sh.in 22 KB

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