vbuilder.sh.in 25 KB

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