vbuilder.sh.in 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799
  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 names: 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. if [ ! -z "$(mount | grep ${BUILD_ROOT}${fs})" ]; then
  296. echo $"Retry lazy unmount ${BUILD_ROOT}${fs} ... "
  297. umount -l ${BUILD_ROOT}${fs}
  298. echo $"done."
  299. fi
  300. ;;
  301. vfs)
  302. for dir in /sys /proc /dev/shm /dev/pts /dev; do
  303. mount-chroot-umount ${dir} || return 1
  304. done
  305. # [ -d ${BUILD_ROOT}/proc ] || return 1
  306. # [ -z "$(mount | grep ${BUILD_ROOT}/proc)" ] || \
  307. # umount ${BUILD_ROOT}/proc
  308. ;;
  309. archives_dir)
  310. [ -d ${ARCHIVES_DIR} ] || return 1
  311. [ -z "$(mount | grep ${ARCHIVES_DIR})" ] || \
  312. umount ${ARCHIVES_DIR}
  313. ;;
  314. unionfs_dir)
  315. [ -d ${BUILD_ROOT} ] || return 1
  316. [ -z "$(mount | grep ${BUILD_ROOT} | grep unionfs)" ] || \
  317. umount ${BUILD_ROOT}
  318. if [ ! -z "$(mount | grep ${BUILD_ROOT} | grep unionfs)" ]; then
  319. echo $"Retry lazy unmount ${BUILD_ROOT} ... "
  320. umount -l ${BUILD_ROOT}
  321. echo $"done."
  322. fi
  323. ;;
  324. *)
  325. echo mount-chroot-umount: unknown file system $fs
  326. exit 1
  327. ;;
  328. esac
  329. return 0
  330. }
  331. ## mount-chroot-mount [file system|name]
  332. mount-chroot-mount(){
  333. local fs=$1
  334. local mnt_opts=""
  335. case $fs in
  336. /home)
  337. mnt_opts="-o _netdev,rbind"
  338. ;;
  339. *)
  340. mnt_opts="--bind -o _netdev"
  341. ;;
  342. esac
  343. case $fs in
  344. /home|/tmp|/sys|/proc|/dev/shm|/dev/pts|/dev)
  345. [ -d ${BUILD_ROOT}${fs} ] || mkdir -p ${BUILD_ROOT}${fs}
  346. [ -z "$(mount | grep ${BUILD_ROOT}${fs})" ] && \
  347. mount ${mnt_opts} ${fs} ${BUILD_ROOT}${fs}
  348. ;;
  349. vfs)
  350. for dir in /dev /dev/pts /dev/shm /proc /sys; do
  351. mount-chroot-mount ${dir} || return 1
  352. done
  353. # mount-chroot-mount /proc || return 1
  354. ;;
  355. archives_dir)
  356. [ -d ${EXTERNAL_ARCHIVES_DIR} ] || mkdir -p ${EXTERNAL_ARCHIVES_DIR}
  357. [ -d ${ARCHIVES_DIR} ] || mkdir -p ${ARCHIVES_DIR}
  358. [ -z "$(mount | grep ${ARCHIVES_DIR})" ] && \
  359. mount ${mnt_opts} ${EXTERNAL_ARCHIVES_DIR} ${ARCHIVES_DIR}
  360. [ -d ${ARCHIVES_DIR}/partial ] || mkdir -p ${ARCHIVES_DIR}/partial
  361. ;;
  362. unionfs_dir)
  363. if [ $with_unionfs -eq 1 ]; then
  364. [ -d ${UNIONFS_DIR} ] || mkdir -p ${UNIONFS_DIR}
  365. [ -z "$(mount | grep ${BUILD_ROOT})" ] && \
  366. mount -t unionfs -o dirs=${UNIONFS_DIR}=rw:${BUILD_ROOT}=ro unionfs ${BUILD_ROOT}
  367. unionctl ${BUILD_ROOT} --list
  368. fi
  369. ;;
  370. *)
  371. echo mount-chroot-mount: unknown file system $fs
  372. exit 1
  373. ;;
  374. esac
  375. return 0
  376. }
  377. write-vbuilder-log(){
  378. HRULE="======================================================================"
  379. [ -d ${BUILD_ROOT} ] || return 1
  380. if [ ! -f $VBUILDER_LOG ]; then
  381. cat<<EOF > $VBUILDER_LOG
  382. ${HRULE}
  383. VBUILDER REPORT
  384. DATE: $(LANG=C date)
  385. HOSTNAME: $(hostname)
  386. OS: $(echo $($__chroot_sh "cat /etc/vine-release"))
  387. %_arch: $(echo $($__chroot_sh "rpm --eval %_arch"))
  388. --version: ${VERSION}
  389. $(echo $([ -z "${VARCH}" ] || echo "--arch: ${VARCH}"))
  390. $(echo $([ -z "${CATEGORIES}" ] || echo "--category: ${CATEGORIES}"))
  391. $(echo $([ $with_dist_upgrade -eq 1 ] && echo "--dist-upgrade"))
  392. $(echo $([ $with_unionfs -eq 1 ] && echo "--unionfs"))
  393. $(echo $([ -z "${TARGET}" ] || echo "--target: ${TARGET}"))
  394. --bootstrap-dir: ${VBOOTSTRAP_DIR}
  395. --cache-dir: ${CACHE_DIR}
  396. --built-rpms-dir: ${BUILT_RPMS_DIR}
  397. ${HRULE}
  398. [$VBUILDER_CONF]
  399. $(cat $VBUILDER_CONF)
  400. [History]
  401. EOF
  402. else
  403. cat<<EOF >> $VBUILDER_LOG
  404. $*
  405. EOF
  406. fi
  407. return 0
  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]*\([A-Za-z]*\)\./vl${DIST_RELEASE}\1\./")
  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. while [ $# -gt 0 ]; do
  599. tmpARG=$1
  600. case $tmpARG in
  601. --version|--arch|--category|--target|--rpmbuild-define|--rpmbuild-with|--rpmbuild-without|--bootstrap-dir|--cache-dir|--built-rpms-dir)
  602. shift
  603. ;;
  604. --dist-upgrade|--unionfs|--with-compat32|--sign|--no-install)
  605. ;;
  606. --build-rpm|build-rpm|--install-rpm|install-rpm|--remove-rpm|remove-rpm)
  607. shift
  608. ;;
  609. --build|build|--clean|clean|--show-info|show-info)
  610. ;;
  611. *)
  612. echo unknown option $1
  613. exit 1
  614. ;;
  615. esac
  616. case $tmpARG in
  617. --version)
  618. VERSION=$1
  619. ;;
  620. --arch)
  621. VARCH=$1
  622. ;;
  623. --category)
  624. CATEGORIES=$1
  625. ;;
  626. --dist-upgrade)
  627. with_dist_upgrade=1
  628. ;;
  629. --unionfs)
  630. with_unionfs=1
  631. ;;
  632. --target)
  633. TARGET=$1
  634. RPM_OPTS="${RPM_OPTS} --target $TARGET"
  635. ;;
  636. --with-compat32)
  637. RPM_OPTS="${RPM_OPTS} --with compat32"
  638. ;;
  639. --rpmbuild-define)
  640. RPM_OPTS="${RPM_OPTS} --define $1"
  641. ;;
  642. --rpmbuild-with)
  643. RPM_OPTS="${RPM_OPTS} --with $1"
  644. ;;
  645. --rpmbuild-without)
  646. RPM_OPTS="${RPM_OPTS} --without $1"
  647. ;;
  648. --sign)
  649. with_sign=1
  650. ;;
  651. --no-install)
  652. with_no_install=1
  653. ;;
  654. --bootstrap-dir)
  655. VBOOTSTRAP_DIR=$1
  656. ;;
  657. --cache-dir)
  658. CACHE_DIR=$1
  659. ;;
  660. --built-rpms-dir)
  661. BUILT_RPMS_DIR=$1
  662. ;;
  663. --build-rpm|build-rpm)
  664. RPM_PKG=$1
  665. RPM_Build || exit 1
  666. ;;
  667. --install-rpm|install-rpm)
  668. RPM_PKG=$1
  669. RPM_Install || exit 1
  670. ;;
  671. --remove-rpm|remove-rpm)
  672. RPM_PKG=$1
  673. RPM_Remove || exit 1
  674. ;;
  675. --show-info|show-info)
  676. Show-Info || exit 1
  677. ;;
  678. --build|build)
  679. Build || exit 1
  680. ;;
  681. --clean|clean)
  682. Clean || exit 1
  683. ;;
  684. esac
  685. shift
  686. done
  687. RPM_Sign
  688. exit