vbuilder.sh.in 30 KB

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