vbuilder.sh.in 23 KB

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