vbuilder.sh.in 21 KB

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