vbuilder.sh.in 23 KB

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