[118] | 1 | #!/bin/bash |
---|
| 2 | # -*- coding: utf-8-unix -*- |
---|
| 3 | |
---|
[2522] | 4 | TEXTDOMAIN=vbootstrap |
---|
| 5 | TEXTDOMAINDIR=/usr/share/locale |
---|
| 6 | |
---|
[2516] | 7 | Usage(){ |
---|
[118] | 8 | cat<<EOF |
---|
[3675] | 9 | $(basename $0) @@VBUILDER_VERSION@@ $(echo $([ -z "@@VBUILDER_REVISION@@" ] || echo "(r@@VBUILDER_REVISION@@)")) |
---|
[5367] | 10 | Usage: $(basename $0) {--profile [profile]} {--version [version]} {--arch [arch]} {--category [categories]} {--fetch-url [fetch_url]} {--dist-upgrade} {--target [target]} {--with-compat32} {--rpmbuild-define [macro_expr]} {--rpmbuild-with [bcond_with]} {--rpmbuild-without [bcond_with]} {--sign} {--no-install} {--debug} {--help} {--bootstrap-dir [directory]} {--unionfs-dir [directory]} {--cache-dir [directory]} {--built-rpms-dir [directory]} {clean|build|build-rpm [src.rpm]|install-rpm [arch.rpm|package]|remove-rpm [package]} |
---|
[4076] | 11 | EOF |
---|
[411] | 12 | |
---|
[4076] | 13 | echo $" |
---|
[411] | 14 | Options: |
---|
[5364] | 15 | --profile: set a profile |
---|
[5450] | 16 | --version: set [version] (default: ${VERSION}) |
---|
[2718] | 17 | --arch: set [arch] (default: ${UARCH}) |
---|
[791] | 18 | --category: set [categories] (default: ${CATEGORIES}) |
---|
[5364] | 19 | --fetch-url: set [fetch_url] to fetch packages (default: ${VBOOTSTRAP_FETCH_URL}) |
---|
[412] | 20 | --dist-upgrade: make VineSeed bootstrap via ${STABLE_VERSION} |
---|
[791] | 21 | --unionfs: cover a bootstrap with unionfs |
---|
[406] | 22 | --target: build rpms with [target] |
---|
[3850] | 23 | --with-compat32: build rpms with compat32 on bootstrap |
---|
[2531] | 24 | --rpmbuild-define: give a option --define [macro_expr] to rpmbuild |
---|
[1476] | 25 | --rpmbuild-with: give a option --with [bcond_with] to rpmbuild |
---|
[2531] | 26 | --rpmbuild-without: give a option --without [bcond_with] to rpmbuild |
---|
[1240] | 27 | --sign: sign built rpms |
---|
[1267] | 28 | --no-install: build only a source rpm - do NOT install a built rpm |
---|
[2718] | 29 | --login: login in chroot as root user |
---|
[709] | 30 | --bootstrap-dir: set a bootstrap directory (default: ${VBOOTSTRAP_DIR}) |
---|
[2711] | 31 | --unionfs-dir: set a directory to store unionfs images of vbootstrap (default: ${UNIONFS_DIR}) |
---|
[725] | 32 | --cache-dir: set a directory to cache rpms (default: ${CACHE_DIR}) |
---|
[709] | 33 | --built-rpms-dir: set a directory to store built rpms in chroot (default: ${BUILT_RPMS_DIR}) |
---|
[2718] | 34 | --debug: enable debug mode |
---|
| 35 | --help: show this help |
---|
[4076] | 36 | " |
---|
[411] | 37 | |
---|
[4076] | 38 | echo $" |
---|
[411] | 39 | Actions: |
---|
[3850] | 40 | clean: clean the bootstrap of [version] |
---|
| 41 | build: build a bootstrap of [version] |
---|
[5367] | 42 | build-rpm: build [src.rpm] on a bootstrap |
---|
[3850] | 43 | install-rpm: install [arch.rpm|package] on a bootstrap |
---|
| 44 | remove-rpm: remove [package] on a bootstrap |
---|
[4076] | 45 | " |
---|
[118] | 46 | |
---|
[4076] | 47 | echo $" |
---|
[3968] | 48 | Examples: |
---|
[304] | 49 | * make a clean/plain build environment on the current archtecture: |
---|
[802] | 50 | $(basename $0) clean build |
---|
[470] | 51 | * build rpms from the specified source rpm: |
---|
[802] | 52 | $(basename $0) build-rpm [src.rpm] |
---|
[3676] | 53 | * make a plain build environment for Vine Linux 5.2: |
---|
| 54 | $(basename $0) --version 5.2 clean build |
---|
[304] | 55 | * make a i386 chroot on x86_64: |
---|
[802] | 56 | $(basename $0) --arch i386 clean build |
---|
| 57 | * build a kernel package with target i686: |
---|
| 58 | $(basename $0) --target i686 build-rpm [kernel src.rpm] |
---|
[406] | 59 | * build a compat32 package: |
---|
[802] | 60 | $(basename $0) --arch i386 --with-compat32 build-rpm [src.rpm] |
---|
[4076] | 61 | " |
---|
| 62 | /usr/sbin/vbootstrap | sed -e s/^Usage:.*// -e s/^E:.*// |
---|
[5364] | 63 | ## TODO: output supported profiles and their names/comments |
---|
[118] | 64 | } |
---|
| 65 | |
---|
[323] | 66 | ############################################################################## |
---|
| 67 | |
---|
[5364] | 68 | initialize-variables(){ |
---|
| 69 | ## set boolian variables |
---|
| 70 | with_profile=0 |
---|
| 71 | with_setup_vbootstrap=0 |
---|
| 72 | with_dist_upgrade=0 |
---|
| 73 | with_unionfs=0 |
---|
| 74 | with_sign=0 |
---|
| 75 | with_no_install=0 |
---|
| 76 | with_login=0 |
---|
| 77 | with_debug=0 |
---|
| 78 | with_actions=0 |
---|
| 79 | with_ix86_on_x86_64=0 |
---|
| 80 | with_category_main=0 |
---|
| 81 | with_category_plus=0 |
---|
| 82 | with_category_nonfree=0 |
---|
| 83 | with_category_test=0 |
---|
| 84 | with_category_proposed_updates=0 |
---|
| 85 | with_category_security=0 |
---|
| 86 | |
---|
| 87 | return 0 |
---|
| 88 | } |
---|
| 89 | |
---|
[416] | 90 | check-parameter(){ |
---|
[2516] | 91 | [ -z "$*" ] && Usage && return 1 |
---|
[416] | 92 | |
---|
| 93 | while [ ! -z "$*" ]; do |
---|
| 94 | case $1 in |
---|
[725] | 95 | --help|help) |
---|
[5367] | 96 | setup-vbuilder ||: |
---|
[2516] | 97 | Usage |
---|
[517] | 98 | return 1 |
---|
[516] | 99 | ;; |
---|
[5364] | 100 | --profile) |
---|
| 101 | shift |
---|
| 102 | with_profile=1 |
---|
| 103 | PROFILE=$1 |
---|
| 104 | check-next-parameter $1 || return 1 |
---|
| 105 | ;; |
---|
| 106 | --version|--arch|--category|--fetch-url|--target|--rpmbuild-define|--rpmbuild-with|--rpmbuild-without|--bootstrap-dir|--unionfs-dir|--cache-dir|--built-rpms-dir) |
---|
[725] | 107 | [ $with_actions -eq 1 ] && \ |
---|
[2516] | 108 | echo $"E: You can give no more options after actions" && \ |
---|
| 109 | return 1 |
---|
[416] | 110 | shift |
---|
| 111 | check-next-parameter $1 || return 1 |
---|
| 112 | ;; |
---|
[2718] | 113 | --dist-upgrade|--unionfs|--with-compat32|--sign|--no-install|--login|--debug) |
---|
[725] | 114 | [ $with_actions -eq 1 ] && \ |
---|
[2516] | 115 | echo $"E: You can give no more options after actions" && \ |
---|
| 116 | return 1 |
---|
[416] | 117 | ;; |
---|
[725] | 118 | --build-rpm|build-rpm|--install-rpm|install-rpm|--remove-rpm|remove-rpm) |
---|
| 119 | with_actions=1 |
---|
| 120 | shift |
---|
| 121 | check-next-parameter $1 || return 1 |
---|
| 122 | ;; |
---|
[3675] | 123 | --build|build|--clean|clean) |
---|
[725] | 124 | with_actions=1 |
---|
| 125 | ;; |
---|
[416] | 126 | *) |
---|
[2516] | 127 | echo $"E: Missing some parameters after $1" |
---|
[416] | 128 | return 1 |
---|
| 129 | ;; |
---|
| 130 | esac |
---|
| 131 | shift |
---|
| 132 | done |
---|
[725] | 133 | |
---|
[2516] | 134 | [ $with_actions -eq 0 ] && \ |
---|
| 135 | echo $"E: You must give at least one action" && return 1 |
---|
[725] | 136 | |
---|
[416] | 137 | return 0 |
---|
| 138 | } |
---|
| 139 | |
---|
[412] | 140 | check-next-parameter(){ |
---|
[2516] | 141 | [ -z "$1" ] && echo $"E: Missing some parameters after $1" && return 1 |
---|
[416] | 142 | |
---|
[2516] | 143 | [ $(echo $1 | grep '^-') ] && \ |
---|
| 144 | echo $"E: Missing some parameters after $1" && return 1 |
---|
[725] | 145 | |
---|
[412] | 146 | return 0 |
---|
| 147 | } |
---|
| 148 | |
---|
[5364] | 149 | ## NOTE: setup-vbuilder() loads |
---|
| 150 | ## - system wide configurations (from /etc/vbootstrap/vbuilder.conf) |
---|
| 151 | ## - given profile (from /etc/vbootstrap/profile.d/*.conf) |
---|
| 152 | ## - given command-line parameters |
---|
| 153 | ## where given command-line parameters override the settings given profile, |
---|
| 154 | ## and the settings given profile override system wide settings. |
---|
| 155 | ## If you use a profile of vbuilder, you may not override the settings |
---|
| 156 | ## given profile. |
---|
[323] | 157 | setup-vbuilder(){ |
---|
[3343] | 158 | ## check $SUDO_USER and $USERHELPER_UID |
---|
| 159 | RPM_SIGN_USER=$SUDO_USER |
---|
| 160 | if [ -z "${RPM_SIGN_USER}" ]; then |
---|
[3967] | 161 | [ -z "${USERHELPER_UID}" ] && \ |
---|
| 162 | echo $"W: \$SUDO_USER and \$USERHELPER_UID are empty" && \ |
---|
| 163 | return 1 |
---|
| 164 | |
---|
[3352] | 165 | RPM_SIGN_USER=$(getent passwd $USERHELPER_UID | cut -d":" -f1) |
---|
[3343] | 166 | fi |
---|
| 167 | ## get $RPM_SIGN_USER's home directory |
---|
| 168 | HOME=$(getent passwd $RPM_SIGN_USER | cut -d":" -f6) |
---|
| 169 | |
---|
[323] | 170 | ## load default settings |
---|
[725] | 171 | VBUILDER_CONF=/etc/vbootstrap/vbuilder.conf |
---|
| 172 | if [ -r $VBUILDER_CONF ]; then |
---|
| 173 | . $VBUILDER_CONF |
---|
[1240] | 174 | [ $? -eq 1 ] && return 1 |
---|
[323] | 175 | fi |
---|
[791] | 176 | [ -z "${CATEGORIES}" ] && \ |
---|
| 177 | CATEGORIES=@@VBUILDER_CATEGORIES@@ |
---|
[5364] | 178 | [ -z "${VBOOTSTRAP_FETCH_URL}" ] && \ |
---|
| 179 | VBOOTSTRAP_FETCH_URL=@@VBUILDER_VBOOTSTRAP_FETCH_URL@@ |
---|
[330] | 180 | [ -z "${VBOOTSTRAP_DIR}" ] && \ |
---|
| 181 | VBOOTSTRAP_DIR=@@VBUILDER_VBOOTSTRAP_DIR@@ |
---|
[2711] | 182 | [ -z "${UNIONFS_DIR}" ] && \ |
---|
| 183 | UNIONFS_DIR=@@VBUILDER_UNIONFS_DIR@@ |
---|
[725] | 184 | [ -z "${CACHE_DIR}" ] && \ |
---|
| 185 | CACHE_DIR=@@VBUILDER_CACHE_DIR@@ |
---|
[370] | 186 | [ -z "${BUILT_RPMS_DIR}" ] && \ |
---|
| 187 | BUILT_RPMS_DIR=@@VBUILDER_BUILT_RPMS_DIR@@ |
---|
[709] | 188 | |
---|
[5368] | 189 | ## set default version for vbootstrap |
---|
| 190 | VERSION=@@VBUILDER_DEFAULT_VERSION@@ |
---|
| 191 | |
---|
[5364] | 192 | ## load profile |
---|
| 193 | if [ ${with_profile} -eq 1 ]; then |
---|
| 194 | [ ! -r /etc/vbootstrap/profile.d/${PROFILE}.conf ] && \ |
---|
| 195 | echo $"E: No such profile found: ${PROFILE}" && return 1 |
---|
| 196 | |
---|
| 197 | . /etc/vbootstrap/profile.d/${PROFILE}.conf |
---|
| 198 | [ $? -eq 1 ] && return 1 |
---|
| 199 | fi |
---|
| 200 | |
---|
[709] | 201 | ## set current stable relase version |
---|
[411] | 202 | STABLE_VERSION=@@VBUILDER_STABLE_VERSION@@ |
---|
| 203 | |
---|
[3676] | 204 | ## set default chroot archtecture |
---|
| 205 | UARCH=$(uname -i) |
---|
| 206 | case "${UARCH}" in |
---|
| 207 | arm*) |
---|
| 208 | UARCH="arm" |
---|
| 209 | ;; |
---|
| 210 | esac |
---|
| 211 | |
---|
[1240] | 212 | return 0 |
---|
[323] | 213 | } |
---|
| 214 | |
---|
[118] | 215 | setup-vbootstrap(){ |
---|
[411] | 216 | if [ ${with_setup_vbootstrap} -eq 0 ]; then |
---|
| 217 | with_setup_vbootstrap=1 |
---|
[118] | 218 | |
---|
[2718] | 219 | ## check debug mode |
---|
| 220 | [ ${with_debug} -eq 1 ] && \ |
---|
[3675] | 221 | cat $VBUILDER_CONF && \ |
---|
[2718] | 222 | set && set -x |
---|
| 223 | |
---|
[725] | 224 | ## check some directories |
---|
| 225 | ## Note: create $BUILT_RPMS_DIR in RPM_Build() |
---|
[709] | 226 | [ -d $VBOOTSTRAP_DIR ] || mkdir -p $VBOOTSTRAP_DIR |
---|
[725] | 227 | [ -d $CACHE_DIR ] || mkdir -p $CACHE_DIR |
---|
[709] | 228 | |
---|
[3676] | 229 | ## check chroot version |
---|
| 230 | case ${VERSION} in |
---|
[4072] | 231 | 4.2|5.2|6.0|VineSeed) |
---|
[2718] | 232 | ;; |
---|
[3676] | 233 | *) |
---|
| 234 | echo $"E: ${VERSION} is NOT supported" |
---|
| 235 | return 1 |
---|
| 236 | ;; |
---|
[2718] | 237 | esac |
---|
| 238 | |
---|
| 239 | case "${VARCH}" in |
---|
| 240 | arm*) |
---|
| 241 | VARCH="arm" |
---|
| 242 | ;; |
---|
| 243 | esac |
---|
| 244 | |
---|
[304] | 245 | ## check a chroot archtecture |
---|
[725] | 246 | if [ -z ${VARCH} ]; then |
---|
[2718] | 247 | VARCH=${UARCH} |
---|
[725] | 248 | else |
---|
[304] | 249 | case "${VARCH}" in |
---|
[3676] | 250 | i386|x86_64) |
---|
| 251 | [ "${UARCH}" = "ppc" -o "${UARCH}" = "arm" ] && \ |
---|
| 252 | echo $"E: arch ${VARCH} is NOT supported on ${UARCH}" && return 1 |
---|
[304] | 253 | ;; |
---|
| 254 | ppc) |
---|
[3676] | 255 | [ "${UARCH}" = "i386" -o "${UARCH}" = "x86_64" -o "${UARCH}" = "arm" ] && \ |
---|
| 256 | echo $"E: arch ${VARCH} is NOT supported on ${UARCH}" && return 1 |
---|
[304] | 257 | ;; |
---|
[2718] | 258 | arm) |
---|
[3676] | 259 | [ "${UARCH}" = "i386" -o "${UARCH}" = "x86_64" -o "${UARCH}" = "ppc" ] && \ |
---|
[2718] | 260 | echo $"E: arch ${VARCH} is NOT supported on ${UARCH}" && return 1 |
---|
| 261 | ;; |
---|
[304] | 262 | esac |
---|
[323] | 263 | fi |
---|
| 264 | |
---|
[3676] | 265 | ##!! 4.2 is NO support on VARCH=x86_64 or VARCH=arch |
---|
| 266 | if [ "${VERSION}" = "4.2" ]; then |
---|
| 267 | if [ "${VARCH}" = "x86_64" -o "${VARCH}" = "arm" ]; then |
---|
| 268 | echo $"E: ${VERSION}_${VARCH} is NOT supported" |
---|
| 269 | return 1 |
---|
| 270 | fi |
---|
[323] | 271 | fi |
---|
| 272 | |
---|
[5364] | 273 | ## set base profile <version>_<arch> |
---|
| 274 | BASE_PROFILE=${VERSION}_${VARCH} |
---|
[2718] | 275 | |
---|
[5364] | 276 | ## check support ${BASE_PROFILE} |
---|
| 277 | if [ -z "$(/usr/sbin/vbootstrap | sed -e s/^Usage:.*// -e s/^E:.*// | grep -m 1 ${BASE_PROFILE})" ]; then |
---|
| 278 | echo $"E: ${BASE_PROFILE} is NOT supported" |
---|
[2516] | 279 | return 1 |
---|
[323] | 280 | fi |
---|
| 281 | |
---|
[411] | 282 | ## check ${VERSION} equals VineSeed*, when with_dist_upgrade=1 |
---|
| 283 | if [ $with_dist_upgrade -eq 1 ]; then |
---|
[3676] | 284 | if [ "${VERSION}" != "VineSeed" ]; then |
---|
[2516] | 285 | echo $"E: version ${VERSION} does not support --dist-upgrade option" |
---|
| 286 | return 1 |
---|
[411] | 287 | fi |
---|
| 288 | fi |
---|
| 289 | |
---|
[3676] | 290 | ## support i386 chroot on x86_64 below: |
---|
| 291 | [ "${UARCH}" = "x86_64" -a "${VARCH}" = "i386" ] && \ |
---|
| 292 | with_ix86_on_x86_64=1 |
---|
[791] | 293 | |
---|
| 294 | ## check apt categories |
---|
[800] | 295 | ## "main" category is unconditionally permited |
---|
[791] | 296 | with_category_main=1 |
---|
| 297 | for cat in $(echo ${CATEGORIES} | sed -e "s/,/ /"g); do |
---|
| 298 | case $cat in |
---|
| 299 | main) |
---|
| 300 | with_category_main=1 |
---|
| 301 | ;; |
---|
| 302 | plus) |
---|
| 303 | with_category_plus=1 |
---|
| 304 | ;; |
---|
| 305 | nonfree) |
---|
| 306 | with_category_nonfree=1 |
---|
| 307 | ;; |
---|
[800] | 308 | test) |
---|
| 309 | ## "test" category only exists in VineSeed |
---|
[3676] | 310 | [ "${VERSION}" = "VineSeed" ] || \ |
---|
[2516] | 311 | echo $"E: No such category exists: $cat" && return 1 |
---|
[800] | 312 | with_category_test=1 |
---|
| 313 | ;; |
---|
[791] | 314 | proposed-updates) |
---|
[800] | 315 | ##!! "proposed-updates" category does not exist in 4.2 |
---|
[3676] | 316 | [ "${VERSION}" = "4.2" ] && \ |
---|
[2516] | 317 | echo $"E: No such category exists: $cat" && return 1 |
---|
[791] | 318 | |
---|
| 319 | with_category_proposed_updates=1 |
---|
| 320 | ;; |
---|
[800] | 321 | security) |
---|
| 322 | ## "security" category does not exist in VineSeed |
---|
[3676] | 323 | [ "${VERSION}" = "VineSeed" ] && \ |
---|
[2516] | 324 | echo $"E: No such category exists: $cat" && return 1 |
---|
[800] | 325 | with_category_security=1 |
---|
| 326 | ;; |
---|
[791] | 327 | *) |
---|
[2516] | 328 | echo $"E: No such category exists: $cat" && return 1 |
---|
[791] | 329 | ;; |
---|
| 330 | esac |
---|
| 331 | done |
---|
| 332 | |
---|
[406] | 333 | ## check build target option ${TARGET} |
---|
[407] | 334 | if [ ! -z "${TARGET}" ]; then |
---|
| 335 | RPM_TARGET_LIST="$(cat /usr/lib/rpm/rpmrc | grep arch_canon: | sed -e "s/arch_canon:[[:blank:]]*\(.*\):.*/\1/")" |
---|
[3742] | 336 | RPM_TARGET_LIST="${RPM_TARGET_LIST} noarch" |
---|
| 337 | if [ -z "$(echo ${RPM_TARGET_LIST} | grep ${TARGET})" ]; then |
---|
[2516] | 338 | echo $"E: rpm build target ${TARGET} is NOT supported" |
---|
| 339 | return 1 |
---|
[407] | 340 | fi |
---|
[406] | 341 | fi |
---|
| 342 | |
---|
[1240] | 343 | ## set ${RPM_PKG_ARCH_LIST} |
---|
[5364] | 344 | RPM_PKG_ARCH_LIST=" \ |
---|
| 345 | RPMS/i386 RPMS/i486 RPMS/i586 RPMS/i686 RPMS/x86_64 RPMS/ppc \ |
---|
| 346 | RPMS/noarch \ |
---|
| 347 | RPMS/armv3l RPMS/armv4l RPMS/armv4tl \ |
---|
| 348 | RPMS/armv5tejl RPMS/armv5tel RPMS/armv6l RPMS/armv7l \ |
---|
| 349 | SRPMS" |
---|
[1240] | 350 | [ -z "${TARGET}" ] || \ |
---|
| 351 | RPM_PKG_ARCH_LIST="RPMS/${TARGET} ${RPM_PKG_ARCH_LIST}" |
---|
| 352 | |
---|
[135] | 353 | fi |
---|
[323] | 354 | |
---|
[1240] | 355 | ## set global variables |
---|
[296] | 356 | BUILD_USER=vbuilder |
---|
| 357 | BUILD_DIR=/home/${BUILD_USER}/rpm |
---|
[5364] | 358 | if [ ${with_profile} -eq 1 ]; then |
---|
| 359 | BUILD_ROOT=${VBOOTSTRAP_DIR}/${PROFILE} |
---|
| 360 | UNIONFS_ROOT=${UNIONFS_DIR}/${PROFILE} |
---|
| 361 | else |
---|
| 362 | BUILD_ROOT=${VBOOTSTRAP_DIR}/${BASE_PROFILE} |
---|
| 363 | UNIONFS_ROOT=${UNIONFS_DIR}/${BASE_PROFILE} |
---|
| 364 | fi |
---|
[452] | 365 | ARCHIVES_DIR=${BUILD_ROOT}/var/cache/apt/archives |
---|
[5364] | 366 | EXTERNAL_ARCHIVES_DIR=${CACHE_DIR}/${BASE_PROFILE}/apt/archives |
---|
[135] | 367 | |
---|
[2468] | 368 | __chroot_sh="/usr/sbin/chroot ${BUILD_ROOT} /bin/sh -c -l" |
---|
[453] | 369 | |
---|
[135] | 370 | mkdir -p $VBOOTSTRAP_DIR |
---|
[1240] | 371 | |
---|
| 372 | return 0 |
---|
[118] | 373 | } |
---|
| 374 | |
---|
[412] | 375 | setup-vbootstrap-rpm(){ |
---|
[1240] | 376 | setup-vbootstrap || return 1 |
---|
[412] | 377 | |
---|
| 378 | ## check ${BUILD_ROOT} |
---|
| 379 | [ -d ${BUILD_ROOT} ] || Build |
---|
[2324] | 380 | ## setarch ix86 if ix86 chroot on x86_64 host |
---|
| 381 | [ $with_ix86_on_x86_64 -eq 1 ] && \ |
---|
[2468] | 382 | __chroot_sh="/usr/sbin/chroot ${BUILD_ROOT} setarch ${VARCH} /bin/sh -c -l" |
---|
[412] | 383 | |
---|
| 384 | DIST_RELEASE=$(cat ${BUILD_ROOT}/etc/vine-release | cut -f3 -d" " | cut -f1 -d.) |
---|
| 385 | |
---|
| 386 | if [ -f $RPM_PKG ]; then |
---|
| 387 | BASE_RPM_PKG=$(basename $RPM_PKG) |
---|
| 388 | cp -f $RPM_PKG $BUILD_ROOT${BUILD_DIR} |
---|
| 389 | else |
---|
| 390 | BASE_RPM_PKG=$RPM_PKG |
---|
| 391 | fi |
---|
[1240] | 392 | |
---|
| 393 | return 0 |
---|
[412] | 394 | } |
---|
| 395 | |
---|
[413] | 396 | ## recover apt-get data on host/chroot |
---|
| 397 | apt-get-update(){ |
---|
| 398 | case $1 in |
---|
| 399 | --host) |
---|
[2522] | 400 | echo -n $"apt-get update on host ... " |
---|
[464] | 401 | apt-get -qq update > /dev/null 2>&1 |
---|
[2522] | 402 | echo $"done." |
---|
[413] | 403 | ;; |
---|
| 404 | --chroot) |
---|
[2522] | 405 | echo -n $"apt-get update on chroot ... " |
---|
[464] | 406 | $__chroot_sh 'apt-get -qq update' > /dev/null 2>&1 |
---|
[2522] | 407 | echo $"done." |
---|
[413] | 408 | ;; |
---|
| 409 | *) |
---|
| 410 | echo apt-get-update: unknown option $1 |
---|
| 411 | exit 1 |
---|
| 412 | ;; |
---|
| 413 | esac |
---|
| 414 | } |
---|
| 415 | |
---|
[454] | 416 | ## mount-chroot {|--umount} [file system|name] |
---|
| 417 | ## support file systems: /home /tmp /sys /proc /dev/shm /dev/pts /dev |
---|
[2654] | 418 | ## support names: vfs archives_dir |
---|
[454] | 419 | ## NOTE: /tmp needs for applications which use X |
---|
| 420 | ## vfs is virtual file systems |
---|
[851] | 421 | ## archives_dir uses to mount ${EXTERNAL_ARCHIVES_DIR} to ${ARCHIVES_DIR} |
---|
| 422 | ## unionfs_dir covers ${BUILD_ROOT} with unionfs |
---|
[454] | 423 | mount-chroot(){ |
---|
[412] | 424 | if [ "$1" = "--umount" ]; then |
---|
[454] | 425 | mount-chroot-umount $2 || return 1 |
---|
[412] | 426 | else |
---|
[454] | 427 | mount-chroot-mount $1 || return 1 |
---|
[412] | 428 | fi |
---|
[454] | 429 | return 0 |
---|
[412] | 430 | } |
---|
| 431 | |
---|
[454] | 432 | ## mount-chroot-umount [file system|name] |
---|
| 433 | mount-chroot-umount(){ |
---|
| 434 | local fs=$1 |
---|
| 435 | case $fs in |
---|
| 436 | /home|/tmp|/sys|/proc|/dev/shm|/dev/pts|/dev) |
---|
| 437 | [ -d ${BUILD_ROOT}${fs} ] || return 1 |
---|
| 438 | [ -z "$(mount | grep ${BUILD_ROOT}${fs})" ] || \ |
---|
| 439 | umount ${BUILD_ROOT}${fs} |
---|
[2654] | 440 | if [ ! -z "$(mount | grep ${BUILD_ROOT}${fs})" ]; then |
---|
| 441 | echo $"Retry lazy unmount ${BUILD_ROOT}${fs} ... " |
---|
| 442 | umount -l ${BUILD_ROOT}${fs} |
---|
| 443 | echo $"done." |
---|
| 444 | fi |
---|
[454] | 445 | ;; |
---|
| 446 | vfs) |
---|
[2718] | 447 | for dir in /sys /proc /dev/shm /dev/pts /dev; do |
---|
| 448 | mount-chroot-umount ${dir} || return 1 |
---|
| 449 | done |
---|
[454] | 450 | ;; |
---|
[725] | 451 | archives_dir) |
---|
[454] | 452 | [ -d ${ARCHIVES_DIR} ] || return 1 |
---|
| 453 | [ -z "$(mount | grep ${ARCHIVES_DIR})" ] || \ |
---|
| 454 | umount ${ARCHIVES_DIR} |
---|
| 455 | ;; |
---|
[485] | 456 | unionfs_dir) |
---|
| 457 | [ -d ${BUILD_ROOT} ] || return 1 |
---|
| 458 | [ -z "$(mount | grep ${BUILD_ROOT} | grep unionfs)" ] || \ |
---|
| 459 | umount ${BUILD_ROOT} |
---|
| 460 | if [ ! -z "$(mount | grep ${BUILD_ROOT} | grep unionfs)" ]; then |
---|
[2654] | 461 | echo $"Retry lazy unmount ${BUILD_ROOT} ... " |
---|
[485] | 462 | umount -l ${BUILD_ROOT} |
---|
[2522] | 463 | echo $"done." |
---|
[485] | 464 | fi |
---|
| 465 | ;; |
---|
[454] | 466 | *) |
---|
| 467 | echo mount-chroot-umount: unknown file system $fs |
---|
| 468 | exit 1 |
---|
| 469 | ;; |
---|
| 470 | esac |
---|
[1240] | 471 | return 0 |
---|
[412] | 472 | } |
---|
| 473 | |
---|
[454] | 474 | ## mount-chroot-mount [file system|name] |
---|
| 475 | mount-chroot-mount(){ |
---|
| 476 | local fs=$1 |
---|
[412] | 477 | |
---|
[454] | 478 | case $fs in |
---|
| 479 | /home) |
---|
[2718] | 480 | [ -d ${BUILD_ROOT}${fs} ] || mkdir -p ${BUILD_ROOT}${fs} |
---|
| 481 | [ -z "$(mount | grep ${BUILD_ROOT}${fs})" ] && \ |
---|
| 482 | mount -o _netdev,rbind ${fs} ${BUILD_ROOT}${fs} |
---|
[454] | 483 | ;; |
---|
[2718] | 484 | /tmp|/dev) |
---|
| 485 | [ -d ${BUILD_ROOT}${fs} ] || mkdir -p ${BUILD_ROOT}${fs} |
---|
| 486 | [ -z "$(mount | grep ${BUILD_ROOT}${fs})" ] && \ |
---|
| 487 | mount --bind -o _netdev ${fs} ${BUILD_ROOT}${fs} |
---|
[454] | 488 | ;; |
---|
[2718] | 489 | /sys) |
---|
[454] | 490 | [ -d ${BUILD_ROOT}${fs} ] || mkdir -p ${BUILD_ROOT}${fs} |
---|
| 491 | [ -z "$(mount | grep ${BUILD_ROOT}${fs})" ] && \ |
---|
[2718] | 492 | mount -o _netdev -t sysfs vbuildersysfs ${BUILD_ROOT}${fs} |
---|
[454] | 493 | ;; |
---|
[2718] | 494 | /proc) |
---|
| 495 | [ -d ${BUILD_ROOT}${fs} ] || mkdir -p ${BUILD_ROOT}${fs} |
---|
| 496 | [ -z "$(mount | grep ${BUILD_ROOT}${fs})" ] && \ |
---|
| 497 | mount -o _netdev -t proc vbuilderproc ${BUILD_ROOT}${fs} |
---|
| 498 | ;; |
---|
| 499 | /dev/shm) |
---|
| 500 | [ -d ${BUILD_ROOT}${fs} ] || mkdir -p ${BUILD_ROOT}${fs} |
---|
| 501 | [ -z "$(mount | grep ${BUILD_ROOT}${fs})" ] && \ |
---|
| 502 | mount -o _netdev -t tmpfs vbuildertmpfs ${BUILD_ROOT}${fs} |
---|
| 503 | ;; |
---|
| 504 | /dev/pts) |
---|
| 505 | [ -d ${BUILD_ROOT}${fs} ] || mkdir -p ${BUILD_ROOT}${fs} |
---|
| 506 | [ -z "$(mount | grep ${BUILD_ROOT}${fs})" ] && \ |
---|
| 507 | mount -o gid=5,mode=620,_netdev -t devpts vbuilderdevpts ${BUILD_ROOT}${fs} |
---|
| 508 | ;; |
---|
[454] | 509 | vfs) |
---|
[2718] | 510 | for dir in /dev /dev/pts /dev/shm /proc /sys; do |
---|
| 511 | mount-chroot-mount ${dir} || return 1 |
---|
| 512 | done |
---|
[454] | 513 | ;; |
---|
[725] | 514 | archives_dir) |
---|
| 515 | [ -d ${EXTERNAL_ARCHIVES_DIR} ] || mkdir -p ${EXTERNAL_ARCHIVES_DIR} |
---|
[454] | 516 | [ -d ${ARCHIVES_DIR} ] || mkdir -p ${ARCHIVES_DIR} |
---|
| 517 | [ -z "$(mount | grep ${ARCHIVES_DIR})" ] && \ |
---|
[2718] | 518 | mount --bind -o _netdev ${EXTERNAL_ARCHIVES_DIR} ${ARCHIVES_DIR} |
---|
[454] | 519 | [ -d ${ARCHIVES_DIR}/partial ] || mkdir -p ${ARCHIVES_DIR}/partial |
---|
| 520 | ;; |
---|
[485] | 521 | unionfs_dir) |
---|
| 522 | if [ $with_unionfs -eq 1 ]; then |
---|
[2711] | 523 | [ -d ${UNIONFS_ROOT} ] || mkdir -p ${UNIONFS_ROOT} |
---|
[5504] | 524 | if ( /sbin/modprobe aufs >& /dev/null ) ; then |
---|
| 525 | [ -z "$(mount | grep ${UNIONFS_ROOT})" ] && \ |
---|
| 526 | mount -t aufs -o br=${UNIONFS_ROOT}=rw:${BUILD_ROOT}=ro aufs ${BUILD_ROOT} |
---|
| 527 | else |
---|
| 528 | [ -z "$(mount | grep ${UNIONFS_ROOT})" ] && \ |
---|
| 529 | mount -t unionfs -o dirs=${UNIONFS_ROOT}=rw:${BUILD_ROOT}=ro unionfs ${BUILD_ROOT} |
---|
| 530 | unionctl ${BUILD_ROOT} --list |
---|
| 531 | fi |
---|
[485] | 532 | fi |
---|
| 533 | ;; |
---|
[455] | 534 | *) |
---|
| 535 | echo mount-chroot-mount: unknown file system $fs |
---|
| 536 | exit 1 |
---|
| 537 | ;; |
---|
[454] | 538 | esac |
---|
[1240] | 539 | return 0 |
---|
[452] | 540 | } |
---|
[412] | 541 | |
---|
[5364] | 542 | ## TODO: support spec-validator |
---|
| 543 | ## spec-validator [spec file] |
---|
| 544 | spec-validator(){ |
---|
| 545 | echo |
---|
| 546 | return 0 |
---|
| 547 | } |
---|
[791] | 548 | |
---|
[5364] | 549 | |
---|
[118] | 550 | ############################################################################## |
---|
| 551 | |
---|
| 552 | Clean(){ |
---|
[1240] | 553 | setup-vbootstrap || return 1 |
---|
[118] | 554 | |
---|
[454] | 555 | # mount-chroot --umount /home |
---|
[2718] | 556 | mount-chroot --umount /tmp |
---|
| 557 | mount-chroot --umount /dev/shm |
---|
| 558 | mount-chroot --umount /dev/pts |
---|
[3021] | 559 | mount-chroot --umount /proc |
---|
[725] | 560 | mount-chroot --umount archives_dir |
---|
[485] | 561 | mount-chroot --umount unionfs_dir |
---|
[413] | 562 | apt-get-update --host |
---|
[406] | 563 | |
---|
[2770] | 564 | ## We remark that we first remove /, and secondly remove /. |
---|
[2769] | 565 | ## If we directly remove /, we obtained some non-empty directories: |
---|
| 566 | ## /dev/.udev/rules.d. |
---|
[485] | 567 | if [ $with_unionfs -eq 1 ]; then |
---|
[2711] | 568 | if [ -d ${UNIONFS_ROOT} ]; then |
---|
| 569 | echo -n $"Cleaning build root ${UNIONFS_ROOT} via unionfs ... " |
---|
[2770] | 570 | rm -rf ${UNIONFS_ROOT} 2>/dev/null |
---|
[2711] | 571 | rm -rf ${UNIONFS_ROOT} |
---|
[2522] | 572 | echo $"done." |
---|
[485] | 573 | fi |
---|
| 574 | else |
---|
| 575 | if [ -d ${BUILD_ROOT} ]; then |
---|
[2522] | 576 | echo -n $"Cleaning build root ${BUILD_ROOT} ... " |
---|
[2770] | 577 | rm -rf ${BUILD_ROOT} 2>/dev/null |
---|
[485] | 578 | rm -rf ${BUILD_ROOT} |
---|
[2522] | 579 | echo $"done." |
---|
[485] | 580 | fi |
---|
[323] | 581 | fi |
---|
[412] | 582 | |
---|
[5364] | 583 | echo $"Cleanup a build farm for ${BUILD_ROOT} done." |
---|
[1240] | 584 | return 0 |
---|
[118] | 585 | } |
---|
| 586 | |
---|
| 587 | Build(){ |
---|
[1240] | 588 | setup-vbootstrap || return 1 |
---|
[118] | 589 | |
---|
[411] | 590 | if [ $with_dist_upgrade -eq 1 ]; then |
---|
| 591 | ## make bootstrap of ${STABLE_VERSION} |
---|
| 592 | /usr/sbin/vbootstrap \ |
---|
[5364] | 593 | $(echo ${BASE_PROFILE} | sed -e "s/VineSeed/${STABLE_VERSION}/") \ |
---|
[5442] | 594 | ${VBOOTSTRAP_FETCH_URL} ${BUILD_ROOT} 2>&1 | \ |
---|
| 595 | egrep -v -e '^W: Duplicate sources.list entry' \ |
---|
| 596 | -e '^W: .*apt-get update' |
---|
[118] | 597 | |
---|
[411] | 598 | ## aim apt-line to VineSeed |
---|
| 599 | sed -i "s/apt ${STABLE_VERSION}/apt VineSeed/g" \ |
---|
| 600 | ${BUILD_ROOT}/etc/apt/sources.list.d/main.list |
---|
| 601 | else |
---|
[5442] | 602 | /usr/sbin/vbootstrap \ |
---|
| 603 | ${BASE_PROFILE} ${VBOOTSTRAP_FETCH_URL} ${BUILD_ROOT} 2>&1 | \ |
---|
| 604 | egrep -v -e '^W: Duplicate sources.list entry' \ |
---|
| 605 | -e '^W: .*apt-get update' |
---|
[411] | 606 | fi |
---|
| 607 | |
---|
[2718] | 608 | mount-chroot /proc |
---|
[725] | 609 | mount-chroot archives_dir |
---|
[2718] | 610 | mount-chroot /dev/pts |
---|
| 611 | mount-chroot /dev/shm |
---|
[454] | 612 | # mount-chroot /tmp |
---|
| 613 | # mount-chroot /home |
---|
[118] | 614 | |
---|
[791] | 615 | ##!! 4.2 has no apt-sourceslist-{plus,nonfree,proposed-updates} packages |
---|
[3676] | 616 | case ${VERSION} in |
---|
[791] | 617 | 4.2) |
---|
[5364] | 618 | sed -i -e "s|@@VBUILDER_VBOOTSTRAP_FETCH_URL@@|${VBOOTSTRAP_FETCH_URL}|g" ${BUILD_ROOT}/etc/apt/sources.list |
---|
| 619 | sed -i -e 's/main plus updates nonfree *$/$(echo ${CATEGORIES} | sed -e "s/,/ /"g) updates/g' ${BUILD_ROOT}/etc/apt/sources.list |
---|
| 620 | $__chroot_sh 'apt-get -qq update && apt-get -qq -y dist-upgrade' |
---|
[800] | 621 | # [ $with_category_security -eq 1 ] && \ |
---|
| 622 | # echo |
---|
[791] | 623 | ;; |
---|
[4530] | 624 | 5.2|@@VBUILDER_STABLE_VERSION@@) |
---|
[5364] | 625 | sed -i -e "s|@@VBUILDER_VBOOTSTRAP_FETCH_URL@@|${VBOOTSTRAP_FETCH_URL}|g" ${BUILD_ROOT}/etc/apt/sources.list.d/main.list |
---|
| 626 | $__chroot_sh 'apt-get -qq update && apt-get -qq -y dist-upgrade' |
---|
[791] | 627 | [ $with_category_plus -eq 1 ] && \ |
---|
[5364] | 628 | $__chroot_sh 'apt-get -qq update && apt-get -qq -y install apt-sourceslist-plus' && \ |
---|
| 629 | sed -i -e "s|@@VBUILDER_VBOOTSTRAP_FETCH_URL@@|${VBOOTSTRAP_FETCH_URL}|g" ${BUILD_ROOT}/etc/apt/sources.list.d/plus.list |
---|
[791] | 630 | [ $with_category_nonfree -eq 1 ] && \ |
---|
[5364] | 631 | $__chroot_sh 'apt-get -qq update && apt-get -qq -y install apt-sourceslist-nonfree' && \ |
---|
| 632 | sed -i -e "s|@@VBUILDER_VBOOTSTRAP_FETCH_URL@@|${VBOOTSTRAP_FETCH_URL}|g" ${BUILD_ROOT}/etc/apt/sources.list.d/nonfree.list |
---|
[791] | 633 | [ $with_category_proposed_updates -eq 1 ] && \ |
---|
[5364] | 634 | $__chroot_sh 'apt-get -qq update && apt-get -qq -y install apt-sourceslist-proposed-updates' && \ |
---|
| 635 | sed -i -e "s|@@VBUILDER_VBOOTSTRAP_FETCH_URL@@|${VBOOTSTRAP_FETCH_URL}|g" ${BUILD_ROOT}/etc/apt/sources.list.d/proposed-updates.list |
---|
[800] | 636 | # [ $with_category_security -eq 1 ] && \ |
---|
| 637 | # echo |
---|
[791] | 638 | ;; |
---|
| 639 | VineSeed) |
---|
[5364] | 640 | sed -i -e "s|@@VBUILDER_VBOOTSTRAP_FETCH_URL@@|${VBOOTSTRAP_FETCH_URL}|g" ${BUILD_ROOT}/etc/apt/sources.list.d/main.list |
---|
| 641 | $__chroot_sh 'apt-get -qq update && apt-get -qq -y dist-upgrade' |
---|
[791] | 642 | [ $with_category_plus -eq 1 ] && \ |
---|
[5364] | 643 | $__chroot_sh 'apt-get -qq update && apt-get -qq -y install apt-sourceslist-plus' && \ |
---|
| 644 | sed -i -e "s|@@VBUILDER_VBOOTSTRAP_FETCH_URL@@|${VBOOTSTRAP_FETCH_URL}|g" ${BUILD_ROOT}/etc/apt/sources.list.d/plus.list |
---|
[791] | 645 | [ $with_category_nonfree -eq 1 ] && \ |
---|
[5364] | 646 | $__chroot_sh 'apt-get -qq update && apt-get -qq -y install apt-sourceslist-nonfree' && \ |
---|
| 647 | sed -i -e "s|@@VBUILDER_VBOOTSTRAP_FETCH_URL@@|${VBOOTSTRAP_FETCH_URL}|g" ${BUILD_ROOT}/etc/apt/sources.list.d/nonfree.list |
---|
[800] | 648 | [ $with_category_test -eq 1 ] && \ |
---|
[5364] | 649 | $__chroot_sh 'apt-get -qq update && apt-get -qq -y install apt-sourceslist-test' && \ |
---|
| 650 | sed -i -e "s|@@VBUILDER_VBOOTSTRAP_FETCH_URL@@|${VBOOTSTRAP_FETCH_URL}|g" ${BUILD_ROOT}/etc/apt/sources.list.d/test.list |
---|
[791] | 651 | ;; |
---|
| 652 | esac |
---|
[423] | 653 | |
---|
[791] | 654 | [ $with_dist_upgrade -eq 1 ] && \ |
---|
[464] | 655 | $__chroot_sh 'apt-get -qq update && apt-get -qq -y dist-upgrade' |
---|
[791] | 656 | |
---|
[464] | 657 | $__chroot_sh 'apt-get -qq -y install build-essential' |
---|
| 658 | $__chroot_sh 'apt-get -qq -y install etcskel shadow-utils' |
---|
[118] | 659 | |
---|
[2662] | 660 | $__chroot_sh 'cd /dev && /sbin/MAKEDEV console' |
---|
[2718] | 661 | $__chroot_sh 'cd /dev && /sbin/MAKEDEV ptmx' |
---|
[2662] | 662 | $__chroot_sh 'cd /dev && /sbin/MAKEDEV null' |
---|
| 663 | $__chroot_sh 'cd /dev && /sbin/MAKEDEV zero' |
---|
| 664 | $__chroot_sh 'cd /dev && /sbin/MAKEDEV random' |
---|
| 665 | $__chroot_sh 'cd /dev && /sbin/MAKEDEV urandom' |
---|
[2718] | 666 | $__chroot_sh 'cd /dev && mkdir -p shm && chmod 777 shm' |
---|
| 667 | $__chroot_sh 'cd /dev && mkdir -p pts && chmod 755 pts' |
---|
[406] | 668 | |
---|
[453] | 669 | $__chroot_sh '/usr/sbin/pwconv' |
---|
| 670 | $__chroot_sh "/usr/sbin/useradd ${BUILD_USER}" |
---|
[323] | 671 | |
---|
[452] | 672 | ##!! for rpm-4.8.0 or higher |
---|
| 673 | ##!! (See http://trac.vinelinux.org/wiki/Vine6/AboutUpdateToolchain) |
---|
[3676] | 674 | if [ "${VERSION}" = "VineSeed" ]; then |
---|
[453] | 675 | $__chroot_sh "sed -i -e 's/^%_topdir/#%_topdir/' /home/${BUILD_USER}/.rpmmacros" |
---|
[452] | 676 | fi |
---|
| 677 | |
---|
[5364] | 678 | ## set local repositories (profile only) |
---|
| 679 | if [ ${with_profile} -eq 1 ]; then |
---|
| 680 | if [ ! -z "${LOCAL_REPOS}" ]; then |
---|
| 681 | cat >${BUILD_ROOT}/etc/apt/sources.list.d/local.list<<EOF |
---|
| 682 | ${LOCAL_REPOS} |
---|
| 683 | EOF |
---|
| 684 | fi |
---|
| 685 | |
---|
| 686 | $__chroot_sh "apt-get update" |
---|
| 687 | |
---|
| 688 | ## additional base packages |
---|
| 689 | [ ! -z "${ADD_BASE_PKGS}" ] && \ |
---|
| 690 | $__chroot_sh "apt-get -y install ${ADD_BASE_PKGS}" |
---|
| 691 | fi |
---|
| 692 | |
---|
[454] | 693 | # mount-chroot --umount /home |
---|
| 694 | # mount-chroot --umount /tmp |
---|
[2718] | 695 | mount-chroot --umount /dev/shm |
---|
| 696 | mount-chroot --umount /dev/pts |
---|
[725] | 697 | mount-chroot --umount archives_dir |
---|
[2718] | 698 | mount-chroot --umount /proc |
---|
[413] | 699 | apt-get-update --host |
---|
[412] | 700 | |
---|
[5364] | 701 | echo $"Making a build farm for ${BUILD_ROOT} done." |
---|
[1240] | 702 | return 0 |
---|
[118] | 703 | } |
---|
| 704 | |
---|
| 705 | RPM_Remove(){ |
---|
[1240] | 706 | setup-vbootstrap-rpm || return 1 |
---|
[485] | 707 | mount-chroot unionfs_dir |
---|
[725] | 708 | mount-chroot archives_dir |
---|
[3021] | 709 | mount-chroot /proc |
---|
[2718] | 710 | mount-chroot /dev/pts |
---|
| 711 | mount-chroot /dev/shm |
---|
[628] | 712 | apt-get-update --chroot |
---|
[118] | 713 | |
---|
[2516] | 714 | [ -f $RPM_PKG ] && \ |
---|
| 715 | echo $"E: $RPM_PKG is not a package name" && return 1 |
---|
[453] | 716 | $__chroot_sh "apt-get -y remove $BASE_RPM_PKG" |
---|
[412] | 717 | |
---|
[2718] | 718 | mount-chroot --umount /dev/shm |
---|
| 719 | mount-chroot --umount /dev/pts |
---|
[3021] | 720 | mount-chroot --umount /proc |
---|
[725] | 721 | mount-chroot --umount archives_dir |
---|
[485] | 722 | mount-chroot --umount unionfs_dir |
---|
[413] | 723 | apt-get-update --host |
---|
[1240] | 724 | |
---|
| 725 | return 0 |
---|
[118] | 726 | } |
---|
| 727 | |
---|
| 728 | RPM_Install(){ |
---|
[1240] | 729 | setup-vbootstrap-rpm || return 1 |
---|
[485] | 730 | mount-chroot unionfs_dir |
---|
[725] | 731 | mount-chroot archives_dir |
---|
[3021] | 732 | mount-chroot /proc |
---|
[2718] | 733 | mount-chroot /dev/pts |
---|
| 734 | mount-chroot /dev/shm |
---|
| 735 | |
---|
[413] | 736 | apt-get-update --chroot |
---|
[118] | 737 | |
---|
[4622] | 738 | [ $with_category_nonfree -eq 1 ] && \ |
---|
| 739 | [ ! -z "$(echo $BASE_RPM_PKG | grep -e 'self-build-' -e 'install-assist-')" ] && \ |
---|
| 740 | $__chroot_sh 'rpm -q --quiet self-build-setup || apt-get -qq -y install self-build-setup' |
---|
| 741 | |
---|
[453] | 742 | $__chroot_sh "cd ${BUILD_DIR} && apt-get -y install $BASE_RPM_PKG" |
---|
[412] | 743 | |
---|
[2718] | 744 | mount-chroot --umount /dev/shm |
---|
| 745 | mount-chroot --umount /dev/pts |
---|
[3021] | 746 | mount-chroot --umount /proc |
---|
[725] | 747 | mount-chroot --umount archives_dir |
---|
[485] | 748 | mount-chroot --umount unionfs_dir |
---|
[413] | 749 | apt-get-update --host |
---|
[1240] | 750 | |
---|
| 751 | return 0 |
---|
[118] | 752 | } |
---|
| 753 | |
---|
| 754 | RPM_Build(){ |
---|
[5364] | 755 | [ ! -f ${RPM_PKG} ] && \ |
---|
| 756 | echo $"E: No such file found: ${RPM_PKG}" && return 1 |
---|
| 757 | |
---|
| 758 | ## check the extension of given $RPM_PKG |
---|
| 759 | local RPM_PKG_EXT=${RPM_PKG##*.} |
---|
| 760 | case ${RPM_PKG_EXT} in |
---|
| 761 | spec) |
---|
| 762 | ## In this case, |
---|
| 763 | ## the file ${RPM_PKG} is a spec file! |
---|
| 764 | # spec-validator ${RPM_PKG} || return 1 |
---|
| 765 | # return 1 |
---|
| 766 | |
---|
| 767 | ## We assign the variable ${RPM_PKG} |
---|
| 768 | ## the src.rpm generated by the spec file ${RPM_PKG}. |
---|
| 769 | RPM_PKG=$(rpm -E "%{_srcrpmdir}")/$(rpm -q --qf "%{name}-%{version}-%{release}\n" --specfile ${RPM_PKG} | head -n 1).src.rpm |
---|
| 770 | ;; |
---|
| 771 | rpm) |
---|
| 772 | RPM_PKG_EXT=$(echo ${RPM_PKG} | sed -e "s|.*\.\(src\.rpm\)$|\1|") |
---|
| 773 | [ "${RPM_PKG_EXT}" != "src.rpm" ] && \ |
---|
| 774 | echo $"E: $RPM_PKG is NOT a source RPM package" && return 1 |
---|
| 775 | ;; |
---|
| 776 | *) |
---|
| 777 | echo $"The action build-rpm cannot work such extension: ${RPM_PKG_EXT}" |
---|
| 778 | return 1 |
---|
| 779 | ;; |
---|
| 780 | esac |
---|
| 781 | |
---|
[1240] | 782 | setup-vbootstrap-rpm || return 1 |
---|
[485] | 783 | mount-chroot unionfs_dir |
---|
[725] | 784 | mount-chroot archives_dir |
---|
[3021] | 785 | mount-chroot /proc |
---|
[2718] | 786 | mount-chroot /dev/pts |
---|
| 787 | mount-chroot /dev/shm |
---|
[628] | 788 | apt-get-update --chroot |
---|
[5364] | 789 | |
---|
| 790 | [ ! -f ${RPM_PKG} ] && \ |
---|
| 791 | echo $"E: No such file found: ${RPM_PKG}" && return 1 |
---|
[118] | 792 | |
---|
[370] | 793 | RPM_PKG_USER=$(stat -c %U $RPM_PKG) |
---|
[371] | 794 | RPM_PKG_GROUP=$(stat -c %G $RPM_PKG) |
---|
[520] | 795 | [ ! -z "${SUDO_UID}" ] && RPM_PKG_USER=${SUDO_UID} |
---|
| 796 | [ ! -z "${SUDO_GID}" ] && RPM_PKG_GROUP=${SUDO_GID} |
---|
[371] | 797 | local __install="install -p -v -o ${RPM_PKG_USER} -g ${RPM_PKG_GROUP}" |
---|
[370] | 798 | |
---|
| 799 | ## make src.rpm for $VERSION |
---|
[453] | 800 | $__chroot_sh "cd ${BUILD_DIR} && su ${BUILD_USER} -c 'rpm -ivh $BASE_RPM_PKG'" |
---|
[1524] | 801 | $__chroot_sh "cd ${BUILD_DIR} && su ${BUILD_USER} -c 'rpmbuild -bs --nodeps --clean --rmsource --rmspec $RPM_OPTS ${BUILD_DIR}/SPECS/*.spec'" |
---|
[370] | 802 | |
---|
[396] | 803 | |
---|
| 804 | ## change ${DIST_RELEASE} |
---|
[4003] | 805 | BASE_RPM_PKG=$(echo $BASE_RPM_PKG | sed -e "s/vl[0-9]*\([A-Za-z]*[0-9A-Za-z]*\)\./vl${DIST_RELEASE}\1\./") |
---|
[396] | 806 | |
---|
| 807 | ## rebuild $BASE_RPM_PKG on ${DIST_RELEASE} |
---|
[969] | 808 | $__chroot_sh "cd ${BUILD_DIR}/SRPMS && apt-get -o APT::Install::Virtual=true -y build-dep $BASE_RPM_PKG" |
---|
[453] | 809 | $__chroot_sh "cd ${BUILD_DIR}/SRPMS && su ${BUILD_USER} -c 'rpmbuild --rebuild $RPM_OPTS $BASE_RPM_PKG'" |
---|
[4622] | 810 | |
---|
| 811 | 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') |
---|
| 812 | |
---|
| 813 | [ $with_category_nonfree -eq 1 ] && \ |
---|
| 814 | [ ! -z "$(echo $BUILT_RPMS_LIST | grep -e 'self-build-' -e 'install-assist-')" ] && \ |
---|
| 815 | $__chroot_sh 'rpm -q --quiet self-build-setup || apt-get -qq -y install self-build-setup' |
---|
| 816 | |
---|
[1267] | 817 | [ $with_no_install -eq 0 ] && \ |
---|
[4622] | 818 | $__chroot_sh "cd ${BUILD_DIR} && apt-get -y install $BUILT_RPMS_LIST" |
---|
[396] | 819 | |
---|
[370] | 820 | ## copy built rpms to ${HOME}/rpm/ for each archtectures |
---|
[2522] | 821 | echo $"Copying built rpms to ${BUILT_RPMS_DIR} for each archtectures ... " |
---|
[4076] | 822 | for i in $RPM_PKG_ARCH_LIST; do |
---|
| 823 | [ -d $BUILD_ROOT${BUILD_DIR}/${i} ] || continue |
---|
| 824 | if [ ! -d ${BUILT_RPMS_DIR}/${VERSION}/${i} ]; then |
---|
| 825 | $__install -d ${BUILT_RPMS_DIR}/${VERSION}/${i}/ |
---|
| 826 | chown -R ${RPM_PKG_USER}:${RPM_PKG_GROUP} ${BUILT_RPMS_DIR} |
---|
[370] | 827 | fi |
---|
[4076] | 828 | find $BUILD_ROOT${BUILD_DIR}/${i} -type f -regex '.*\.rpm' \ |
---|
| 829 | -exec $__install -m0644 {} ${BUILT_RPMS_DIR}/${VERSION}/${i}/ \; |
---|
[370] | 830 | done |
---|
[412] | 831 | |
---|
[2718] | 832 | mount-chroot --umount /dev/shm |
---|
| 833 | mount-chroot --umount /dev/pts |
---|
[3021] | 834 | mount-chroot --umount /proc |
---|
[725] | 835 | mount-chroot --umount archives_dir |
---|
[485] | 836 | mount-chroot --umount unionfs_dir |
---|
[413] | 837 | apt-get-update --host |
---|
[412] | 838 | |
---|
[2522] | 839 | echo $"done." |
---|
[1240] | 840 | return 0 |
---|
[118] | 841 | } |
---|
| 842 | |
---|
[1240] | 843 | RPM_Sign(){ |
---|
[1375] | 844 | [ $with_sign -eq 1 ] || return 1 |
---|
[118] | 845 | |
---|
[2668] | 846 | setup-vbootstrap || return 1 |
---|
| 847 | |
---|
| 848 | [ -d ${BUILD_ROOT} ] || Build |
---|
| 849 | |
---|
| 850 | mount-chroot unionfs_dir |
---|
| 851 | |
---|
[2662] | 852 | echo $"Signing built rpms using ${RPM_SIGN_USER}'s key: " |
---|
[5364] | 853 | 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')" |
---|
[1375] | 854 | |
---|
[2668] | 855 | mount-chroot --umount unionfs_dir |
---|
| 856 | |
---|
[1240] | 857 | return 0 |
---|
| 858 | } |
---|
| 859 | |
---|
[2718] | 860 | Login_Chroot(){ |
---|
| 861 | [ $with_login -eq 1 ] || return 1 |
---|
[1240] | 862 | |
---|
[2718] | 863 | setup-vbootstrap || return 1 |
---|
| 864 | |
---|
| 865 | __chroot="/usr/sbin/chroot ${BUILD_ROOT}" |
---|
| 866 | ## setarch ix86 if ix86 chroot on x86_64 host |
---|
| 867 | [ $with_ix86_on_x86_64 -eq 1 ] && \ |
---|
| 868 | __chroot="/usr/sbin/chroot ${BUILD_ROOT} setarch ${VARCH}" |
---|
| 869 | |
---|
| 870 | |
---|
| 871 | mount-chroot unionfs_dir |
---|
| 872 | mount-chroot archives_dir |
---|
[3021] | 873 | mount-chroot /proc |
---|
[2718] | 874 | mount-chroot /dev/pts |
---|
| 875 | mount-chroot /dev/shm |
---|
| 876 | mount-chroot /tmp |
---|
| 877 | # mount-chroot /home |
---|
| 878 | apt-get-update --chroot |
---|
| 879 | |
---|
| 880 | ## copy host's configurations of /etc |
---|
| 881 | #passwd shadow group gshadow |
---|
| 882 | for i in resolv.conf hosts; do |
---|
| 883 | cp -pf /etc/${i} ${BUILD_ROOT}/etc |
---|
| 884 | done |
---|
| 885 | cp -Ppf /etc/localtime ${BUILD_ROOT}/etc |
---|
| 886 | |
---|
[3678] | 887 | $__chroot /bin/bash |
---|
[2718] | 888 | |
---|
| 889 | # mount-chroot --umount /home |
---|
| 890 | mount-chroot --umount /tmp |
---|
| 891 | mount-chroot --umount /dev/shm |
---|
| 892 | mount-chroot --umount /dev/pts |
---|
[3021] | 893 | mount-chroot --umount /proc |
---|
[2718] | 894 | mount-chroot --umount archives_dir |
---|
| 895 | mount-chroot --umount unionfs_dir |
---|
| 896 | apt-get-update --host |
---|
| 897 | |
---|
| 898 | return 0 |
---|
| 899 | } |
---|
| 900 | |
---|
| 901 | |
---|
[304] | 902 | ############################################################################## |
---|
| 903 | |
---|
[5364] | 904 | initialize-variables || exit 1 |
---|
[304] | 905 | |
---|
[416] | 906 | check-parameter $* || exit 1 |
---|
| 907 | |
---|
[5364] | 908 | setup-vbuilder || exit 1 |
---|
| 909 | |
---|
[118] | 910 | while [ $# -gt 0 ]; do |
---|
[411] | 911 | tmpARG=$1 |
---|
| 912 | case $tmpARG in |
---|
[5364] | 913 | --profile) |
---|
[406] | 914 | shift |
---|
| 915 | ;; |
---|
[5364] | 916 | --version|--arch|--category|--fetch-url|--target|--rpmbuild-define|--rpmbuild-with|--rpmbuild-without|--bootstrap-dir|--unionfs-dir|--cache-dir|--built-rpms-dir) |
---|
| 917 | shift |
---|
| 918 | ;; |
---|
[2718] | 919 | --dist-upgrade|--unionfs|--with-compat32|--sign|--no-install|--login|--debug) |
---|
[406] | 920 | ;; |
---|
[725] | 921 | --build-rpm|build-rpm|--install-rpm|install-rpm|--remove-rpm|remove-rpm) |
---|
| 922 | shift |
---|
| 923 | ;; |
---|
[3675] | 924 | --build|build|--clean|clean) |
---|
[725] | 925 | ;; |
---|
[406] | 926 | *) |
---|
[416] | 927 | echo unknown option $1 |
---|
[406] | 928 | exit 1 |
---|
| 929 | ;; |
---|
| 930 | esac |
---|
| 931 | |
---|
[411] | 932 | case $tmpARG in |
---|
[5364] | 933 | --profile) |
---|
| 934 | ;; |
---|
[406] | 935 | --version) |
---|
[118] | 936 | VERSION=$1 |
---|
| 937 | ;; |
---|
| 938 | --arch) |
---|
| 939 | VARCH=$1 |
---|
| 940 | ;; |
---|
[791] | 941 | --category) |
---|
| 942 | CATEGORIES=$1 |
---|
| 943 | ;; |
---|
[5364] | 944 | --fetch-url) |
---|
| 945 | VBOOTSTRAP_FETCH_URL=$1 |
---|
| 946 | ;; |
---|
[411] | 947 | --dist-upgrade) |
---|
| 948 | with_dist_upgrade=1 |
---|
| 949 | ;; |
---|
[485] | 950 | --unionfs) |
---|
| 951 | with_unionfs=1 |
---|
| 952 | ;; |
---|
[406] | 953 | --target) |
---|
| 954 | TARGET=$1 |
---|
| 955 | RPM_OPTS="${RPM_OPTS} --target $TARGET" |
---|
| 956 | ;; |
---|
[118] | 957 | --with-compat32) |
---|
[406] | 958 | RPM_OPTS="${RPM_OPTS} --with compat32" |
---|
[118] | 959 | ;; |
---|
[2531] | 960 | --rpmbuild-define) |
---|
| 961 | RPM_OPTS="${RPM_OPTS} --define $1" |
---|
| 962 | ;; |
---|
[1476] | 963 | --rpmbuild-with) |
---|
| 964 | RPM_OPTS="${RPM_OPTS} --with $1" |
---|
| 965 | ;; |
---|
[2531] | 966 | --rpmbuild-without) |
---|
| 967 | RPM_OPTS="${RPM_OPTS} --without $1" |
---|
| 968 | ;; |
---|
[1240] | 969 | --sign) |
---|
| 970 | with_sign=1 |
---|
| 971 | ;; |
---|
[1267] | 972 | --no-install) |
---|
| 973 | with_no_install=1 |
---|
| 974 | ;; |
---|
[2718] | 975 | --login) |
---|
| 976 | with_login=1 |
---|
| 977 | ;; |
---|
[709] | 978 | --bootstrap-dir) |
---|
| 979 | VBOOTSTRAP_DIR=$1 |
---|
| 980 | ;; |
---|
[2711] | 981 | --unionfs-dir) |
---|
| 982 | UNIONFS_DIR=$1 |
---|
| 983 | ;; |
---|
[725] | 984 | --cache-dir) |
---|
| 985 | CACHE_DIR=$1 |
---|
| 986 | ;; |
---|
[709] | 987 | --built-rpms-dir) |
---|
| 988 | BUILT_RPMS_DIR=$1 |
---|
| 989 | ;; |
---|
[2718] | 990 | --debug) |
---|
| 991 | with_debug=1 |
---|
| 992 | ;; |
---|
[679] | 993 | --build-rpm|build-rpm) |
---|
[118] | 994 | RPM_PKG=$1 |
---|
[406] | 995 | RPM_Build || exit 1 |
---|
[118] | 996 | ;; |
---|
[679] | 997 | --install-rpm|install-rpm) |
---|
[118] | 998 | RPM_PKG=$1 |
---|
[406] | 999 | RPM_Install || exit 1 |
---|
[118] | 1000 | ;; |
---|
[679] | 1001 | --remove-rpm|remove-rpm) |
---|
[118] | 1002 | RPM_PKG=$1 |
---|
[406] | 1003 | RPM_Remove || exit 1 |
---|
[118] | 1004 | ;; |
---|
[679] | 1005 | --build|build) |
---|
[1240] | 1006 | Build || exit 1 |
---|
[118] | 1007 | ;; |
---|
[679] | 1008 | --clean|clean) |
---|
[1240] | 1009 | Clean || exit 1 |
---|
[118] | 1010 | ;; |
---|
| 1011 | esac |
---|
| 1012 | shift |
---|
| 1013 | done |
---|
| 1014 | |
---|
[3479] | 1015 | RPM_Sign ||: |
---|
[1240] | 1016 | |
---|
[3479] | 1017 | Login_Chroot ||: |
---|
[2718] | 1018 | |
---|
[118] | 1019 | exit |
---|