vbuilder.sh.in 30 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014
  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|spec]|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|spec] 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. Usage
  87. return 1
  88. ;;
  89. --profile)
  90. shift
  91. with_profile=1
  92. PROFILE=$1
  93. check-next-parameter $1 || return 1
  94. ;;
  95. --version|--arch|--category|--fetch-url|--target|--rpmbuild-define|--rpmbuild-with|--rpmbuild-without|--bootstrap-dir|--unionfs-dir|--cache-dir|--built-rpms-dir)
  96. [ $with_actions -eq 1 ] && \
  97. echo $"E: You can give no more options after actions" && \
  98. return 1
  99. shift
  100. check-next-parameter $1 || return 1
  101. ;;
  102. --dist-upgrade|--unionfs|--with-compat32|--sign|--no-install|--login|--debug)
  103. [ $with_actions -eq 1 ] && \
  104. echo $"E: You can give no more options after actions" && \
  105. return 1
  106. ;;
  107. --build-rpm|build-rpm|--install-rpm|install-rpm|--remove-rpm|remove-rpm)
  108. with_actions=1
  109. shift
  110. check-next-parameter $1 || return 1
  111. ;;
  112. --build|build|--clean|clean)
  113. with_actions=1
  114. ;;
  115. *)
  116. echo $"E: Missing some parameters after $1"
  117. return 1
  118. ;;
  119. esac
  120. shift
  121. done
  122. [ $with_actions -eq 0 ] && \
  123. echo $"E: You must give at least one action" && return 1
  124. return 0
  125. }
  126. check-next-parameter(){
  127. [ -z "$1" ] && echo $"E: Missing some parameters after $1" && return 1
  128. [ $(echo $1 | grep '^-') ] && \
  129. echo $"E: Missing some parameters after $1" && return 1
  130. return 0
  131. }
  132. ## NOTE: setup-vbuilder() loads
  133. ## - system wide configurations (from /etc/vbootstrap/vbuilder.conf)
  134. ## - given profile (from /etc/vbootstrap/profile.d/*.conf)
  135. ## - given command-line parameters
  136. ## where given command-line parameters override the settings given profile,
  137. ## and the settings given profile override system wide settings.
  138. ## If you use a profile of vbuilder, you may not override the settings
  139. ## given profile.
  140. setup-vbuilder(){
  141. ## check $SUDO_USER and $USERHELPER_UID
  142. RPM_SIGN_USER=$SUDO_USER
  143. if [ -z "${RPM_SIGN_USER}" ]; then
  144. [ -z "${USERHELPER_UID}" ] && \
  145. echo $"W: \$SUDO_USER and \$USERHELPER_UID are empty" && \
  146. return 1
  147. RPM_SIGN_USER=$(getent passwd $USERHELPER_UID | cut -d":" -f1)
  148. fi
  149. ## get $RPM_SIGN_USER's home directory
  150. HOME=$(getent passwd $RPM_SIGN_USER | cut -d":" -f6)
  151. ## load default settings
  152. VBUILDER_CONF=/etc/vbootstrap/vbuilder.conf
  153. if [ -r $VBUILDER_CONF ]; then
  154. . $VBUILDER_CONF
  155. [ $? -eq 1 ] && return 1
  156. fi
  157. [ -z "${DEFAULT_VERSION}" ] && \
  158. DEFAULT_VERSION=@@VBUILDER_DEFAULT_VERSION@@
  159. [ -z "${CATEGORIES}" ] && \
  160. CATEGORIES=@@VBUILDER_CATEGORIES@@
  161. [ -z "${VBOOTSTRAP_FETCH_URL}" ] && \
  162. VBOOTSTRAP_FETCH_URL=@@VBUILDER_VBOOTSTRAP_FETCH_URL@@
  163. [ -z "${VBOOTSTRAP_DIR}" ] && \
  164. VBOOTSTRAP_DIR=@@VBUILDER_VBOOTSTRAP_DIR@@
  165. [ -z "${UNIONFS_DIR}" ] && \
  166. UNIONFS_DIR=@@VBUILDER_UNIONFS_DIR@@
  167. [ -z "${CACHE_DIR}" ] && \
  168. CACHE_DIR=@@VBUILDER_CACHE_DIR@@
  169. [ -z "${BUILT_RPMS_DIR}" ] && \
  170. BUILT_RPMS_DIR=@@VBUILDER_BUILT_RPMS_DIR@@
  171. ## load profile
  172. if [ ${with_profile} -eq 1 ]; then
  173. [ ! -r /etc/vbootstrap/profile.d/${PROFILE}.conf ] && \
  174. echo $"E: No such profile found: ${PROFILE}" && return 1
  175. . /etc/vbootstrap/profile.d/${PROFILE}.conf
  176. [ $? -eq 1 ] && return 1
  177. fi
  178. ## set default version for vbootstrap
  179. if [ ${with_profile} -eq 1 ]; then
  180. [ -z ${VERSION} ] && VERSION=$DEFAULT_VERSION
  181. else
  182. VERSION=$DEFAULT_VERSION
  183. fi
  184. ## set current stable relase version
  185. STABLE_VERSION=@@VBUILDER_STABLE_VERSION@@
  186. ## set default chroot archtecture
  187. UARCH=$(uname -i)
  188. case "${UARCH}" in
  189. arm*)
  190. UARCH="arm"
  191. ;;
  192. esac
  193. return 0
  194. }
  195. setup-vbootstrap(){
  196. if [ ${with_setup_vbootstrap} -eq 0 ]; then
  197. with_setup_vbootstrap=1
  198. ## check debug mode
  199. [ ${with_debug} -eq 1 ] && \
  200. cat $VBUILDER_CONF && \
  201. set && set -x
  202. ## check some directories
  203. ## Note: create $BUILT_RPMS_DIR in RPM_Build()
  204. [ -d $VBOOTSTRAP_DIR ] || mkdir -p $VBOOTSTRAP_DIR
  205. [ -d $CACHE_DIR ] || mkdir -p $CACHE_DIR
  206. ## check chroot version
  207. case ${VERSION} in
  208. 4.2|5.2|6.0|VineSeed)
  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. __chroot_sh="/usr/sbin/chroot ${BUILD_ROOT} /bin/sh -c -l"
  332. mkdir -p $VBOOTSTRAP_DIR
  333. return 0
  334. }
  335. setup-vbootstrap-rpm(){
  336. setup-vbootstrap || return 1
  337. ## check ${BUILD_ROOT}
  338. [ -d ${BUILD_ROOT} ] || Build
  339. ## setarch ix86 if ix86 chroot on x86_64 host
  340. [ $with_ix86_on_x86_64 -eq 1 ] && \
  341. __chroot_sh="/usr/sbin/chroot ${BUILD_ROOT} setarch ${VARCH} /bin/sh -c -l"
  342. DIST_RELEASE=$(cat ${BUILD_ROOT}/etc/vine-release | cut -f3 -d" " | cut -f1 -d.)
  343. if [ -f $RPM_PKG ]; then
  344. BASE_RPM_PKG=$(basename $RPM_PKG)
  345. cp -f $RPM_PKG $BUILD_ROOT${BUILD_DIR}
  346. else
  347. BASE_RPM_PKG=$RPM_PKG
  348. fi
  349. return 0
  350. }
  351. ## recover apt-get data on host/chroot
  352. apt-get-update(){
  353. case $1 in
  354. --host)
  355. echo -n $"apt-get update on host ... "
  356. apt-get -qq update > /dev/null 2>&1
  357. echo $"done."
  358. ;;
  359. --chroot)
  360. echo -n $"apt-get update on chroot ... "
  361. $__chroot_sh 'apt-get -qq update' > /dev/null 2>&1
  362. echo $"done."
  363. ;;
  364. *)
  365. echo apt-get-update: unknown option $1
  366. exit 1
  367. ;;
  368. esac
  369. }
  370. ## mount-chroot {|--umount} [file system|name]
  371. ## support file systems: /home /tmp /sys /proc /dev/shm /dev/pts /dev
  372. ## support names: vfs archives_dir
  373. ## NOTE: /tmp needs for applications which use X
  374. ## vfs is virtual file systems
  375. ## archives_dir uses to mount ${EXTERNAL_ARCHIVES_DIR} to ${ARCHIVES_DIR}
  376. ## unionfs_dir covers ${BUILD_ROOT} with unionfs
  377. mount-chroot(){
  378. if [ "$1" = "--umount" ]; then
  379. mount-chroot-umount $2 || return 1
  380. else
  381. mount-chroot-mount $1 || return 1
  382. fi
  383. return 0
  384. }
  385. ## mount-chroot-umount [file system|name]
  386. mount-chroot-umount(){
  387. local fs=$1
  388. case $fs in
  389. /home|/tmp|/sys|/proc|/dev/shm|/dev/pts|/dev)
  390. [ -d ${BUILD_ROOT}${fs} ] || return 1
  391. [ -z "$(mount | grep ${BUILD_ROOT}${fs})" ] || \
  392. umount ${BUILD_ROOT}${fs}
  393. if [ ! -z "$(mount | grep ${BUILD_ROOT}${fs})" ]; then
  394. echo $"Retry lazy unmount ${BUILD_ROOT}${fs} ... "
  395. umount -l ${BUILD_ROOT}${fs}
  396. echo $"done."
  397. fi
  398. ;;
  399. vfs)
  400. for dir in /sys /proc /dev/shm /dev/pts /dev; do
  401. mount-chroot-umount ${dir} || return 1
  402. done
  403. ;;
  404. archives_dir)
  405. [ -d ${ARCHIVES_DIR} ] || return 1
  406. [ -z "$(mount | grep ${ARCHIVES_DIR})" ] || \
  407. umount ${ARCHIVES_DIR}
  408. ;;
  409. unionfs_dir)
  410. [ -d ${BUILD_ROOT} ] || return 1
  411. [ -z "$(mount | grep ${BUILD_ROOT} | grep unionfs)" ] || \
  412. umount ${BUILD_ROOT}
  413. if [ ! -z "$(mount | grep ${BUILD_ROOT} | grep unionfs)" ]; then
  414. echo $"Retry lazy unmount ${BUILD_ROOT} ... "
  415. umount -l ${BUILD_ROOT}
  416. echo $"done."
  417. fi
  418. ;;
  419. *)
  420. echo mount-chroot-umount: unknown file system $fs
  421. exit 1
  422. ;;
  423. esac
  424. return 0
  425. }
  426. ## mount-chroot-mount [file system|name]
  427. mount-chroot-mount(){
  428. local fs=$1
  429. case $fs in
  430. /home)
  431. [ -d ${BUILD_ROOT}${fs} ] || mkdir -p ${BUILD_ROOT}${fs}
  432. [ -z "$(mount | grep ${BUILD_ROOT}${fs})" ] && \
  433. mount -o _netdev,rbind ${fs} ${BUILD_ROOT}${fs}
  434. ;;
  435. /tmp|/dev)
  436. [ -d ${BUILD_ROOT}${fs} ] || mkdir -p ${BUILD_ROOT}${fs}
  437. [ -z "$(mount | grep ${BUILD_ROOT}${fs})" ] && \
  438. mount --bind -o _netdev ${fs} ${BUILD_ROOT}${fs}
  439. ;;
  440. /sys)
  441. [ -d ${BUILD_ROOT}${fs} ] || mkdir -p ${BUILD_ROOT}${fs}
  442. [ -z "$(mount | grep ${BUILD_ROOT}${fs})" ] && \
  443. mount -o _netdev -t sysfs vbuildersysfs ${BUILD_ROOT}${fs}
  444. ;;
  445. /proc)
  446. [ -d ${BUILD_ROOT}${fs} ] || mkdir -p ${BUILD_ROOT}${fs}
  447. [ -z "$(mount | grep ${BUILD_ROOT}${fs})" ] && \
  448. mount -o _netdev -t proc vbuilderproc ${BUILD_ROOT}${fs}
  449. ;;
  450. /dev/shm)
  451. [ -d ${BUILD_ROOT}${fs} ] || mkdir -p ${BUILD_ROOT}${fs}
  452. [ -z "$(mount | grep ${BUILD_ROOT}${fs})" ] && \
  453. mount -o _netdev -t tmpfs vbuildertmpfs ${BUILD_ROOT}${fs}
  454. ;;
  455. /dev/pts)
  456. [ -d ${BUILD_ROOT}${fs} ] || mkdir -p ${BUILD_ROOT}${fs}
  457. [ -z "$(mount | grep ${BUILD_ROOT}${fs})" ] && \
  458. mount -o gid=5,mode=620,_netdev -t devpts vbuilderdevpts ${BUILD_ROOT}${fs}
  459. ;;
  460. vfs)
  461. for dir in /dev /dev/pts /dev/shm /proc /sys; do
  462. mount-chroot-mount ${dir} || return 1
  463. done
  464. ;;
  465. archives_dir)
  466. [ -d ${EXTERNAL_ARCHIVES_DIR} ] || mkdir -p ${EXTERNAL_ARCHIVES_DIR}
  467. [ -d ${ARCHIVES_DIR} ] || mkdir -p ${ARCHIVES_DIR}
  468. [ -z "$(mount | grep ${ARCHIVES_DIR})" ] && \
  469. mount --bind -o _netdev ${EXTERNAL_ARCHIVES_DIR} ${ARCHIVES_DIR}
  470. [ -d ${ARCHIVES_DIR}/partial ] || mkdir -p ${ARCHIVES_DIR}/partial
  471. ;;
  472. unionfs_dir)
  473. if [ $with_unionfs -eq 1 ]; then
  474. [ -d ${UNIONFS_ROOT} ] || mkdir -p ${UNIONFS_ROOT}
  475. [ -z "$(mount | grep ${UNIONFS_ROOT})" ] && \
  476. mount -t unionfs -o dirs=${UNIONFS_ROOT}=rw:${BUILD_ROOT}=ro unionfs ${BUILD_ROOT}
  477. unionctl ${BUILD_ROOT} --list
  478. fi
  479. ;;
  480. *)
  481. echo mount-chroot-mount: unknown file system $fs
  482. exit 1
  483. ;;
  484. esac
  485. return 0
  486. }
  487. ## TODO: support spec-validator
  488. ## spec-validator [spec file]
  489. spec-validator(){
  490. echo
  491. return 0
  492. }
  493. ##############################################################################
  494. Clean(){
  495. setup-vbootstrap || return 1
  496. # mount-chroot --umount /home
  497. mount-chroot --umount /tmp
  498. mount-chroot --umount /dev/shm
  499. mount-chroot --umount /dev/pts
  500. mount-chroot --umount /proc
  501. mount-chroot --umount archives_dir
  502. mount-chroot --umount unionfs_dir
  503. apt-get-update --host
  504. ## We remark that we first remove /, and secondly remove /.
  505. ## If we directly remove /, we obtained some non-empty directories:
  506. ## /dev/.udev/rules.d.
  507. if [ $with_unionfs -eq 1 ]; then
  508. if [ -d ${UNIONFS_ROOT} ]; then
  509. echo -n $"Cleaning build root ${UNIONFS_ROOT} via unionfs ... "
  510. rm -rf ${UNIONFS_ROOT} 2>/dev/null
  511. rm -rf ${UNIONFS_ROOT}
  512. echo $"done."
  513. fi
  514. else
  515. if [ -d ${BUILD_ROOT} ]; then
  516. echo -n $"Cleaning build root ${BUILD_ROOT} ... "
  517. rm -rf ${BUILD_ROOT} 2>/dev/null
  518. rm -rf ${BUILD_ROOT}
  519. echo $"done."
  520. fi
  521. fi
  522. echo $"Cleanup a build farm for ${BUILD_ROOT} done."
  523. return 0
  524. }
  525. Build(){
  526. setup-vbootstrap || return 1
  527. if [ $with_dist_upgrade -eq 1 ]; then
  528. ## make bootstrap of ${STABLE_VERSION}
  529. /usr/sbin/vbootstrap \
  530. $(echo ${BASE_PROFILE} | sed -e "s/VineSeed/${STABLE_VERSION}/") \
  531. ${VBOOTSTRAP_FETCH_URL} ${BUILD_ROOT}
  532. ## aim apt-line to VineSeed
  533. sed -i "s/apt ${STABLE_VERSION}/apt VineSeed/g" \
  534. ${BUILD_ROOT}/etc/apt/sources.list.d/main.list
  535. else
  536. /usr/sbin/vbootstrap ${BASE_PROFILE} ${VBOOTSTRAP_FETCH_URL} ${BUILD_ROOT}
  537. fi
  538. mount-chroot /proc
  539. mount-chroot archives_dir
  540. mount-chroot /dev/pts
  541. mount-chroot /dev/shm
  542. # mount-chroot /tmp
  543. # mount-chroot /home
  544. ##!! 4.2 has no apt-sourceslist-{plus,nonfree,proposed-updates} packages
  545. case ${VERSION} in
  546. 4.2)
  547. sed -i -e "s|@@VBUILDER_VBOOTSTRAP_FETCH_URL@@|${VBOOTSTRAP_FETCH_URL}|g" ${BUILD_ROOT}/etc/apt/sources.list
  548. sed -i -e 's/main plus updates nonfree *$/$(echo ${CATEGORIES} | sed -e "s/,/ /"g) updates/g' ${BUILD_ROOT}/etc/apt/sources.list
  549. $__chroot_sh 'apt-get -qq update && apt-get -qq -y dist-upgrade'
  550. # [ $with_category_security -eq 1 ] && \
  551. # echo
  552. ;;
  553. 5.2|@@VBUILDER_STABLE_VERSION@@)
  554. sed -i -e "s|@@VBUILDER_VBOOTSTRAP_FETCH_URL@@|${VBOOTSTRAP_FETCH_URL}|g" ${BUILD_ROOT}/etc/apt/sources.list.d/main.list
  555. $__chroot_sh 'apt-get -qq update && apt-get -qq -y dist-upgrade'
  556. [ $with_category_plus -eq 1 ] && \
  557. $__chroot_sh 'apt-get -qq update && apt-get -qq -y install apt-sourceslist-plus' && \
  558. sed -i -e "s|@@VBUILDER_VBOOTSTRAP_FETCH_URL@@|${VBOOTSTRAP_FETCH_URL}|g" ${BUILD_ROOT}/etc/apt/sources.list.d/plus.list
  559. [ $with_category_nonfree -eq 1 ] && \
  560. $__chroot_sh 'apt-get -qq update && apt-get -qq -y install apt-sourceslist-nonfree' && \
  561. sed -i -e "s|@@VBUILDER_VBOOTSTRAP_FETCH_URL@@|${VBOOTSTRAP_FETCH_URL}|g" ${BUILD_ROOT}/etc/apt/sources.list.d/nonfree.list
  562. [ $with_category_proposed_updates -eq 1 ] && \
  563. $__chroot_sh 'apt-get -qq update && apt-get -qq -y install apt-sourceslist-proposed-updates' && \
  564. sed -i -e "s|@@VBUILDER_VBOOTSTRAP_FETCH_URL@@|${VBOOTSTRAP_FETCH_URL}|g" ${BUILD_ROOT}/etc/apt/sources.list.d/proposed-updates.list
  565. # [ $with_category_security -eq 1 ] && \
  566. # echo
  567. ;;
  568. VineSeed)
  569. sed -i -e "s|@@VBUILDER_VBOOTSTRAP_FETCH_URL@@|${VBOOTSTRAP_FETCH_URL}|g" ${BUILD_ROOT}/etc/apt/sources.list.d/main.list
  570. $__chroot_sh 'apt-get -qq update && apt-get -qq -y dist-upgrade'
  571. [ $with_category_plus -eq 1 ] && \
  572. $__chroot_sh 'apt-get -qq update && apt-get -qq -y install apt-sourceslist-plus' && \
  573. sed -i -e "s|@@VBUILDER_VBOOTSTRAP_FETCH_URL@@|${VBOOTSTRAP_FETCH_URL}|g" ${BUILD_ROOT}/etc/apt/sources.list.d/plus.list
  574. [ $with_category_nonfree -eq 1 ] && \
  575. $__chroot_sh 'apt-get -qq update && apt-get -qq -y install apt-sourceslist-nonfree' && \
  576. sed -i -e "s|@@VBUILDER_VBOOTSTRAP_FETCH_URL@@|${VBOOTSTRAP_FETCH_URL}|g" ${BUILD_ROOT}/etc/apt/sources.list.d/nonfree.list
  577. [ $with_category_test -eq 1 ] && \
  578. $__chroot_sh 'apt-get -qq update && apt-get -qq -y install apt-sourceslist-test' && \
  579. sed -i -e "s|@@VBUILDER_VBOOTSTRAP_FETCH_URL@@|${VBOOTSTRAP_FETCH_URL}|g" ${BUILD_ROOT}/etc/apt/sources.list.d/test.list
  580. ;;
  581. esac
  582. [ $with_dist_upgrade -eq 1 ] && \
  583. $__chroot_sh 'apt-get -qq update && apt-get -qq -y dist-upgrade'
  584. $__chroot_sh 'apt-get -qq -y install build-essential'
  585. $__chroot_sh 'apt-get -qq -y install etcskel shadow-utils'
  586. $__chroot_sh 'cd /dev && /sbin/MAKEDEV console'
  587. $__chroot_sh 'cd /dev && /sbin/MAKEDEV ptmx'
  588. $__chroot_sh 'cd /dev && /sbin/MAKEDEV null'
  589. $__chroot_sh 'cd /dev && /sbin/MAKEDEV zero'
  590. $__chroot_sh 'cd /dev && /sbin/MAKEDEV random'
  591. $__chroot_sh 'cd /dev && /sbin/MAKEDEV urandom'
  592. $__chroot_sh 'cd /dev && mkdir -p shm && chmod 777 shm'
  593. $__chroot_sh 'cd /dev && mkdir -p pts && chmod 755 pts'
  594. $__chroot_sh '/usr/sbin/pwconv'
  595. $__chroot_sh "/usr/sbin/useradd ${BUILD_USER}"
  596. ##!! for rpm-4.8.0 or higher
  597. ##!! (See http://trac.vinelinux.org/wiki/Vine6/AboutUpdateToolchain)
  598. if [ "${VERSION}" = "VineSeed" ]; then
  599. $__chroot_sh "sed -i -e 's/^%_topdir/#%_topdir/' /home/${BUILD_USER}/.rpmmacros"
  600. fi
  601. ## set local repositories (profile only)
  602. if [ ${with_profile} -eq 1 ]; then
  603. if [ ! -z "${LOCAL_REPOS}" ]; then
  604. cat >${BUILD_ROOT}/etc/apt/sources.list.d/local.list<<EOF
  605. ${LOCAL_REPOS}
  606. EOF
  607. fi
  608. $__chroot_sh "apt-get update"
  609. ## additional base packages
  610. [ ! -z "${ADD_BASE_PKGS}" ] && \
  611. $__chroot_sh "apt-get -y install ${ADD_BASE_PKGS}"
  612. fi
  613. # mount-chroot --umount /home
  614. # mount-chroot --umount /tmp
  615. mount-chroot --umount /dev/shm
  616. mount-chroot --umount /dev/pts
  617. mount-chroot --umount archives_dir
  618. mount-chroot --umount /proc
  619. apt-get-update --host
  620. echo $"Making a build farm for ${BUILD_ROOT} done."
  621. return 0
  622. }
  623. RPM_Remove(){
  624. setup-vbootstrap-rpm || return 1
  625. mount-chroot unionfs_dir
  626. mount-chroot archives_dir
  627. mount-chroot /proc
  628. mount-chroot /dev/pts
  629. mount-chroot /dev/shm
  630. apt-get-update --chroot
  631. [ -f $RPM_PKG ] && \
  632. echo $"E: $RPM_PKG is not a package name" && return 1
  633. $__chroot_sh "apt-get -y remove $BASE_RPM_PKG"
  634. mount-chroot --umount /dev/shm
  635. mount-chroot --umount /dev/pts
  636. mount-chroot --umount /proc
  637. mount-chroot --umount archives_dir
  638. mount-chroot --umount unionfs_dir
  639. apt-get-update --host
  640. return 0
  641. }
  642. RPM_Install(){
  643. setup-vbootstrap-rpm || return 1
  644. mount-chroot unionfs_dir
  645. mount-chroot archives_dir
  646. mount-chroot /proc
  647. mount-chroot /dev/pts
  648. mount-chroot /dev/shm
  649. apt-get-update --chroot
  650. [ $with_category_nonfree -eq 1 ] && \
  651. [ ! -z "$(echo $BASE_RPM_PKG | grep -e 'self-build-' -e 'install-assist-')" ] && \
  652. $__chroot_sh 'rpm -q --quiet self-build-setup || apt-get -qq -y install self-build-setup'
  653. $__chroot_sh "cd ${BUILD_DIR} && apt-get -y install $BASE_RPM_PKG"
  654. mount-chroot --umount /dev/shm
  655. mount-chroot --umount /dev/pts
  656. mount-chroot --umount /proc
  657. mount-chroot --umount archives_dir
  658. mount-chroot --umount unionfs_dir
  659. apt-get-update --host
  660. return 0
  661. }
  662. RPM_Build(){
  663. [ ! -f ${RPM_PKG} ] && \
  664. echo $"E: No such file found: ${RPM_PKG}" && return 1
  665. ## check the extension of given $RPM_PKG
  666. local RPM_PKG_EXT=${RPM_PKG##*.}
  667. case ${RPM_PKG_EXT} in
  668. spec)
  669. ## In this case,
  670. ## the file ${RPM_PKG} is a spec file!
  671. # spec-validator ${RPM_PKG} || return 1
  672. # return 1
  673. ## We assign the variable ${RPM_PKG}
  674. ## the src.rpm generated by the spec file ${RPM_PKG}.
  675. RPM_PKG=$(rpm -E "%{_srcrpmdir}")/$(rpm -q --qf "%{name}-%{version}-%{release}\n" --specfile ${RPM_PKG} | head -n 1).src.rpm
  676. ;;
  677. rpm)
  678. RPM_PKG_EXT=$(echo ${RPM_PKG} | sed -e "s|.*\.\(src\.rpm\)$|\1|")
  679. [ "${RPM_PKG_EXT}" != "src.rpm" ] && \
  680. echo $"E: $RPM_PKG is NOT a source RPM package" && return 1
  681. ;;
  682. *)
  683. echo $"The action build-rpm cannot work such extension: ${RPM_PKG_EXT}"
  684. return 1
  685. ;;
  686. esac
  687. setup-vbootstrap-rpm || return 1
  688. mount-chroot unionfs_dir
  689. mount-chroot archives_dir
  690. mount-chroot /proc
  691. mount-chroot /dev/pts
  692. mount-chroot /dev/shm
  693. apt-get-update --chroot
  694. [ ! -f ${RPM_PKG} ] && \
  695. echo $"E: No such file found: ${RPM_PKG}" && return 1
  696. RPM_PKG_USER=$(stat -c %U $RPM_PKG)
  697. RPM_PKG_GROUP=$(stat -c %G $RPM_PKG)
  698. [ ! -z "${SUDO_UID}" ] && RPM_PKG_USER=${SUDO_UID}
  699. [ ! -z "${SUDO_GID}" ] && RPM_PKG_GROUP=${SUDO_GID}
  700. local __install="install -p -v -o ${RPM_PKG_USER} -g ${RPM_PKG_GROUP}"
  701. ## make src.rpm for $VERSION
  702. $__chroot_sh "cd ${BUILD_DIR} && su ${BUILD_USER} -c 'rpm -ivh $BASE_RPM_PKG'"
  703. $__chroot_sh "cd ${BUILD_DIR} && su ${BUILD_USER} -c 'rpmbuild -bs --nodeps --clean --rmsource --rmspec $RPM_OPTS ${BUILD_DIR}/SPECS/*.spec'"
  704. ## change ${DIST_RELEASE}
  705. BASE_RPM_PKG=$(echo $BASE_RPM_PKG | sed -e "s/vl[0-9]*\([A-Za-z]*[0-9A-Za-z]*\)\./vl${DIST_RELEASE}\1\./")
  706. ## rebuild $BASE_RPM_PKG on ${DIST_RELEASE}
  707. $__chroot_sh "cd ${BUILD_DIR}/SRPMS && apt-get -o APT::Install::Virtual=true -y build-dep $BASE_RPM_PKG"
  708. $__chroot_sh "cd ${BUILD_DIR}/SRPMS && su ${BUILD_USER} -c 'rpmbuild --rebuild $RPM_OPTS $BASE_RPM_PKG'"
  709. 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')
  710. [ $with_category_nonfree -eq 1 ] && \
  711. [ ! -z "$(echo $BUILT_RPMS_LIST | grep -e 'self-build-' -e 'install-assist-')" ] && \
  712. $__chroot_sh 'rpm -q --quiet self-build-setup || apt-get -qq -y install self-build-setup'
  713. [ $with_no_install -eq 0 ] && \
  714. $__chroot_sh "cd ${BUILD_DIR} && apt-get -y install $BUILT_RPMS_LIST"
  715. ## copy built rpms to ${HOME}/rpm/ for each archtectures
  716. echo $"Copying built rpms to ${BUILT_RPMS_DIR} for each archtectures ... "
  717. for i in $RPM_PKG_ARCH_LIST; do
  718. [ -d $BUILD_ROOT${BUILD_DIR}/${i} ] || continue
  719. if [ ! -d ${BUILT_RPMS_DIR}/${VERSION}/${i} ]; then
  720. $__install -d ${BUILT_RPMS_DIR}/${VERSION}/${i}/
  721. chown -R ${RPM_PKG_USER}:${RPM_PKG_GROUP} ${BUILT_RPMS_DIR}
  722. fi
  723. find $BUILD_ROOT${BUILD_DIR}/${i} -type f -regex '.*\.rpm' \
  724. -exec $__install -m0644 {} ${BUILT_RPMS_DIR}/${VERSION}/${i}/ \;
  725. done
  726. mount-chroot --umount /dev/shm
  727. mount-chroot --umount /dev/pts
  728. mount-chroot --umount /proc
  729. mount-chroot --umount archives_dir
  730. mount-chroot --umount unionfs_dir
  731. apt-get-update --host
  732. echo $"done."
  733. return 0
  734. }
  735. RPM_Sign(){
  736. [ $with_sign -eq 1 ] || return 1
  737. setup-vbootstrap || return 1
  738. [ -d ${BUILD_ROOT} ] || Build
  739. mount-chroot unionfs_dir
  740. echo $"Signing built rpms using ${RPM_SIGN_USER}'s key: "
  741. 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')"
  742. mount-chroot --umount unionfs_dir
  743. return 0
  744. }
  745. Login_Chroot(){
  746. [ $with_login -eq 1 ] || return 1
  747. setup-vbootstrap || return 1
  748. __chroot="/usr/sbin/chroot ${BUILD_ROOT}"
  749. ## setarch ix86 if ix86 chroot on x86_64 host
  750. [ $with_ix86_on_x86_64 -eq 1 ] && \
  751. __chroot="/usr/sbin/chroot ${BUILD_ROOT} setarch ${VARCH}"
  752. mount-chroot unionfs_dir
  753. mount-chroot archives_dir
  754. mount-chroot /proc
  755. mount-chroot /dev/pts
  756. mount-chroot /dev/shm
  757. mount-chroot /tmp
  758. # mount-chroot /home
  759. apt-get-update --chroot
  760. ## copy host's configurations of /etc
  761. #passwd shadow group gshadow
  762. for i in resolv.conf hosts; do
  763. cp -pf /etc/${i} ${BUILD_ROOT}/etc
  764. done
  765. cp -Ppf /etc/localtime ${BUILD_ROOT}/etc
  766. $__chroot /bin/bash
  767. # mount-chroot --umount /home
  768. mount-chroot --umount /tmp
  769. mount-chroot --umount /dev/shm
  770. mount-chroot --umount /dev/pts
  771. mount-chroot --umount /proc
  772. mount-chroot --umount archives_dir
  773. mount-chroot --umount unionfs_dir
  774. apt-get-update --host
  775. return 0
  776. }
  777. ##############################################################################
  778. initialize-variables || exit 1
  779. check-parameter $* || exit 1
  780. setup-vbuilder || exit 1
  781. while [ $# -gt 0 ]; do
  782. tmpARG=$1
  783. case $tmpARG in
  784. --profile)
  785. shift
  786. ;;
  787. --version|--arch|--category|--fetch-url|--target|--rpmbuild-define|--rpmbuild-with|--rpmbuild-without|--bootstrap-dir|--unionfs-dir|--cache-dir|--built-rpms-dir)
  788. shift
  789. ;;
  790. --dist-upgrade|--unionfs|--with-compat32|--sign|--no-install|--login|--debug)
  791. ;;
  792. --build-rpm|build-rpm|--install-rpm|install-rpm|--remove-rpm|remove-rpm)
  793. shift
  794. ;;
  795. --build|build|--clean|clean)
  796. ;;
  797. *)
  798. echo unknown option $1
  799. exit 1
  800. ;;
  801. esac
  802. case $tmpARG in
  803. --profile)
  804. ;;
  805. --version)
  806. VERSION=$1
  807. ;;
  808. --arch)
  809. VARCH=$1
  810. ;;
  811. --category)
  812. CATEGORIES=$1
  813. ;;
  814. --fetch-url)
  815. VBOOTSTRAP_FETCH_URL=$1
  816. ;;
  817. --dist-upgrade)
  818. with_dist_upgrade=1
  819. ;;
  820. --unionfs)
  821. with_unionfs=1
  822. ;;
  823. --target)
  824. TARGET=$1
  825. RPM_OPTS="${RPM_OPTS} --target $TARGET"
  826. ;;
  827. --with-compat32)
  828. RPM_OPTS="${RPM_OPTS} --with compat32"
  829. ;;
  830. --rpmbuild-define)
  831. RPM_OPTS="${RPM_OPTS} --define $1"
  832. ;;
  833. --rpmbuild-with)
  834. RPM_OPTS="${RPM_OPTS} --with $1"
  835. ;;
  836. --rpmbuild-without)
  837. RPM_OPTS="${RPM_OPTS} --without $1"
  838. ;;
  839. --sign)
  840. with_sign=1
  841. ;;
  842. --no-install)
  843. with_no_install=1
  844. ;;
  845. --login)
  846. with_login=1
  847. ;;
  848. --bootstrap-dir)
  849. VBOOTSTRAP_DIR=$1
  850. ;;
  851. --unionfs-dir)
  852. UNIONFS_DIR=$1
  853. ;;
  854. --cache-dir)
  855. CACHE_DIR=$1
  856. ;;
  857. --built-rpms-dir)
  858. BUILT_RPMS_DIR=$1
  859. ;;
  860. --debug)
  861. with_debug=1
  862. ;;
  863. --build-rpm|build-rpm)
  864. RPM_PKG=$1
  865. RPM_Build || exit 1
  866. ;;
  867. --install-rpm|install-rpm)
  868. RPM_PKG=$1
  869. RPM_Install || exit 1
  870. ;;
  871. --remove-rpm|remove-rpm)
  872. RPM_PKG=$1
  873. RPM_Remove || exit 1
  874. ;;
  875. --build|build)
  876. Build || exit 1
  877. ;;
  878. --clean|clean)
  879. Clean || exit 1
  880. ;;
  881. esac
  882. shift
  883. done
  884. RPM_Sign ||:
  885. Login_Chroot ||:
  886. exit