vbuilder.sh.in 22 KB

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