vbuilder.sh.in 22 KB

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