vbuilder.sh.in 25 KB

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