vbuilder.sh.in 30 KB

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