vbuilder.sh.in 31 KB

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