vbuilder.sh.in 26 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898
  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. 5.2|@@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. $__chroot_sh 'apt-get -qq -y install etcskel shadow-utils'
  525. $__chroot_sh 'cd /dev && /sbin/MAKEDEV console'
  526. $__chroot_sh 'cd /dev && /sbin/MAKEDEV ptmx'
  527. $__chroot_sh 'cd /dev && /sbin/MAKEDEV null'
  528. $__chroot_sh 'cd /dev && /sbin/MAKEDEV zero'
  529. $__chroot_sh 'cd /dev && /sbin/MAKEDEV random'
  530. $__chroot_sh 'cd /dev && /sbin/MAKEDEV urandom'
  531. $__chroot_sh 'cd /dev && mkdir -p shm && chmod 777 shm'
  532. $__chroot_sh 'cd /dev && mkdir -p pts && chmod 755 pts'
  533. $__chroot_sh '/usr/sbin/pwconv'
  534. $__chroot_sh "/usr/sbin/useradd ${BUILD_USER}"
  535. ##!! for rpm-4.8.0 or higher
  536. ##!! (See http://trac.vinelinux.org/wiki/Vine6/AboutUpdateToolchain)
  537. if [ "${VERSION}" = "VineSeed" ]; then
  538. $__chroot_sh "sed -i -e 's/^%_topdir/#%_topdir/' /home/${BUILD_USER}/.rpmmacros"
  539. fi
  540. # mount-chroot --umount /home
  541. # mount-chroot --umount /tmp
  542. mount-chroot --umount /dev/shm
  543. mount-chroot --umount /dev/pts
  544. mount-chroot --umount archives_dir
  545. mount-chroot --umount /proc
  546. apt-get-update --host
  547. echo $"Making a build farm for ${PROFILE} done."
  548. return 0
  549. }
  550. RPM_Remove(){
  551. setup-vbootstrap-rpm || return 1
  552. mount-chroot unionfs_dir
  553. mount-chroot archives_dir
  554. mount-chroot /proc
  555. mount-chroot /dev/pts
  556. mount-chroot /dev/shm
  557. apt-get-update --chroot
  558. [ -f $RPM_PKG ] && \
  559. echo $"E: $RPM_PKG is not a package name" && return 1
  560. $__chroot_sh "apt-get -y remove $BASE_RPM_PKG"
  561. mount-chroot --umount /dev/shm
  562. mount-chroot --umount /dev/pts
  563. mount-chroot --umount /proc
  564. mount-chroot --umount archives_dir
  565. mount-chroot --umount unionfs_dir
  566. apt-get-update --host
  567. return 0
  568. }
  569. RPM_Install(){
  570. setup-vbootstrap-rpm || return 1
  571. mount-chroot unionfs_dir
  572. mount-chroot archives_dir
  573. mount-chroot /proc
  574. mount-chroot /dev/pts
  575. mount-chroot /dev/shm
  576. apt-get-update --chroot
  577. [ $with_category_nonfree -eq 1 ] && \
  578. [ ! -z "$(echo $BASE_RPM_PKG | grep -e 'self-build-' -e 'install-assist-')" ] && \
  579. $__chroot_sh 'rpm -q --quiet self-build-setup || apt-get -qq -y install self-build-setup'
  580. $__chroot_sh "cd ${BUILD_DIR} && apt-get -y install $BASE_RPM_PKG"
  581. mount-chroot --umount /dev/shm
  582. mount-chroot --umount /dev/pts
  583. mount-chroot --umount /proc
  584. mount-chroot --umount archives_dir
  585. mount-chroot --umount unionfs_dir
  586. apt-get-update --host
  587. return 0
  588. }
  589. RPM_Build(){
  590. setup-vbootstrap-rpm || return 1
  591. mount-chroot unionfs_dir
  592. mount-chroot archives_dir
  593. mount-chroot /proc
  594. mount-chroot /dev/pts
  595. mount-chroot /dev/shm
  596. apt-get-update --chroot
  597. [ ! -f $RPM_PKG ] && \
  598. echo $"E: $RPM_PKG is not a source RPM package" && return 1
  599. RPM_PKG_USER=$(stat -c %U $RPM_PKG)
  600. RPM_PKG_GROUP=$(stat -c %G $RPM_PKG)
  601. [ ! -z "${SUDO_UID}" ] && RPM_PKG_USER=${SUDO_UID}
  602. [ ! -z "${SUDO_GID}" ] && RPM_PKG_GROUP=${SUDO_GID}
  603. local __install="install -p -v -o ${RPM_PKG_USER} -g ${RPM_PKG_GROUP}"
  604. ## make src.rpm for $VERSION
  605. $__chroot_sh "cd ${BUILD_DIR} && su ${BUILD_USER} -c 'rpm -ivh $BASE_RPM_PKG'"
  606. $__chroot_sh "cd ${BUILD_DIR} && su ${BUILD_USER} -c 'rpmbuild -bs --nodeps --clean --rmsource --rmspec $RPM_OPTS ${BUILD_DIR}/SPECS/*.spec'"
  607. ## change ${DIST_RELEASE}
  608. BASE_RPM_PKG=$(echo $BASE_RPM_PKG | sed -e "s/vl[0-9]*\([A-Za-z]*[0-9A-Za-z]*\)\./vl${DIST_RELEASE}\1\./")
  609. ## rebuild $BASE_RPM_PKG on ${DIST_RELEASE}
  610. $__chroot_sh "cd ${BUILD_DIR}/SRPMS && apt-get -o APT::Install::Virtual=true -y build-dep $BASE_RPM_PKG"
  611. $__chroot_sh "cd ${BUILD_DIR}/SRPMS && su ${BUILD_USER} -c 'rpmbuild --rebuild $RPM_OPTS $BASE_RPM_PKG'"
  612. BUILT_RPMS_LIST=$(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. [ $with_category_nonfree -eq 1 ] && \
  614. [ ! -z "$(echo $BUILT_RPMS_LIST | grep -e 'self-build-' -e 'install-assist-')" ] && \
  615. $__chroot_sh 'rpm -q --quiet self-build-setup || apt-get -qq -y install self-build-setup'
  616. [ $with_no_install -eq 0 ] && \
  617. $__chroot_sh "cd ${BUILD_DIR} && apt-get -y install $BUILT_RPMS_LIST"
  618. ## copy built rpms to ${HOME}/rpm/ for each archtectures
  619. echo $"Copying built rpms to ${BUILT_RPMS_DIR} for each archtectures ... "
  620. for i in $RPM_PKG_ARCH_LIST; do
  621. [ -d $BUILD_ROOT${BUILD_DIR}/${i} ] || continue
  622. if [ ! -d ${BUILT_RPMS_DIR}/${VERSION}/${i} ]; then
  623. $__install -d ${BUILT_RPMS_DIR}/${VERSION}/${i}/
  624. chown -R ${RPM_PKG_USER}:${RPM_PKG_GROUP} ${BUILT_RPMS_DIR}
  625. fi
  626. find $BUILD_ROOT${BUILD_DIR}/${i} -type f -regex '.*\.rpm' \
  627. -exec $__install -m0644 {} ${BUILT_RPMS_DIR}/${VERSION}/${i}/ \;
  628. done
  629. mount-chroot --umount /dev/shm
  630. mount-chroot --umount /dev/pts
  631. mount-chroot --umount /proc
  632. mount-chroot --umount archives_dir
  633. mount-chroot --umount unionfs_dir
  634. apt-get-update --host
  635. echo $"done."
  636. return 0
  637. }
  638. RPM_Sign(){
  639. [ $with_sign -eq 1 ] || return 1
  640. setup-vbootstrap || return 1
  641. [ -d ${BUILD_ROOT} ] || Build
  642. mount-chroot unionfs_dir
  643. echo $"Signing built rpms using ${RPM_SIGN_USER}'s key: "
  644. 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')"
  645. mount-chroot --umount unionfs_dir
  646. return 0
  647. }
  648. Login_Chroot(){
  649. [ $with_login -eq 1 ] || return 1
  650. setup-vbootstrap || return 1
  651. __chroot="/usr/sbin/chroot ${BUILD_ROOT}"
  652. ## setarch ix86 if ix86 chroot on x86_64 host
  653. [ $with_ix86_on_x86_64 -eq 1 ] && \
  654. __chroot="/usr/sbin/chroot ${BUILD_ROOT} setarch ${VARCH}"
  655. mount-chroot unionfs_dir
  656. mount-chroot archives_dir
  657. mount-chroot /proc
  658. mount-chroot /dev/pts
  659. mount-chroot /dev/shm
  660. mount-chroot /tmp
  661. # mount-chroot /home
  662. apt-get-update --chroot
  663. ## copy host's configurations of /etc
  664. #passwd shadow group gshadow
  665. for i in resolv.conf hosts; do
  666. cp -pf /etc/${i} ${BUILD_ROOT}/etc
  667. done
  668. cp -Ppf /etc/localtime ${BUILD_ROOT}/etc
  669. $__chroot /bin/bash
  670. # mount-chroot --umount /home
  671. mount-chroot --umount /tmp
  672. mount-chroot --umount /dev/shm
  673. mount-chroot --umount /dev/pts
  674. mount-chroot --umount /proc
  675. mount-chroot --umount archives_dir
  676. mount-chroot --umount unionfs_dir
  677. apt-get-update --host
  678. return 0
  679. }
  680. ##############################################################################
  681. setup-vbuilder || exit 1
  682. check-parameter $* || exit 1
  683. while [ $# -gt 0 ]; do
  684. tmpARG=$1
  685. case $tmpARG in
  686. --version|--arch|--category|--target|--rpmbuild-define|--rpmbuild-with|--rpmbuild-without|--bootstrap-dir|--unionfs-dir|--cache-dir|--built-rpms-dir)
  687. shift
  688. ;;
  689. --dist-upgrade|--unionfs|--with-compat32|--sign|--no-install|--login|--debug)
  690. ;;
  691. --build-rpm|build-rpm|--install-rpm|install-rpm|--remove-rpm|remove-rpm)
  692. shift
  693. ;;
  694. --build|build|--clean|clean)
  695. ;;
  696. *)
  697. echo unknown option $1
  698. exit 1
  699. ;;
  700. esac
  701. case $tmpARG in
  702. --version)
  703. VERSION=$1
  704. ;;
  705. --arch)
  706. VARCH=$1
  707. ;;
  708. --category)
  709. CATEGORIES=$1
  710. ;;
  711. --dist-upgrade)
  712. with_dist_upgrade=1
  713. ;;
  714. --unionfs)
  715. with_unionfs=1
  716. ;;
  717. --target)
  718. TARGET=$1
  719. RPM_OPTS="${RPM_OPTS} --target $TARGET"
  720. ;;
  721. --with-compat32)
  722. RPM_OPTS="${RPM_OPTS} --with compat32"
  723. ;;
  724. --rpmbuild-define)
  725. RPM_OPTS="${RPM_OPTS} --define $1"
  726. ;;
  727. --rpmbuild-with)
  728. RPM_OPTS="${RPM_OPTS} --with $1"
  729. ;;
  730. --rpmbuild-without)
  731. RPM_OPTS="${RPM_OPTS} --without $1"
  732. ;;
  733. --sign)
  734. with_sign=1
  735. ;;
  736. --no-install)
  737. with_no_install=1
  738. ;;
  739. --login)
  740. with_login=1
  741. ;;
  742. --bootstrap-dir)
  743. VBOOTSTRAP_DIR=$1
  744. ;;
  745. --unionfs-dir)
  746. UNIONFS_DIR=$1
  747. ;;
  748. --cache-dir)
  749. CACHE_DIR=$1
  750. ;;
  751. --built-rpms-dir)
  752. BUILT_RPMS_DIR=$1
  753. ;;
  754. --debug)
  755. with_debug=1
  756. ;;
  757. --build-rpm|build-rpm)
  758. RPM_PKG=$1
  759. RPM_Build || exit 1
  760. ;;
  761. --install-rpm|install-rpm)
  762. RPM_PKG=$1
  763. RPM_Install || exit 1
  764. ;;
  765. --remove-rpm|remove-rpm)
  766. RPM_PKG=$1
  767. RPM_Remove || exit 1
  768. ;;
  769. --build|build)
  770. Build || exit 1
  771. ;;
  772. --clean|clean)
  773. Clean || exit 1
  774. ;;
  775. esac
  776. shift
  777. done
  778. RPM_Sign ||:
  779. Login_Chroot ||:
  780. exit