vbuilder.sh.in 23 KB

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