Changeset 920


Ignore:
Timestamp:
Jan 12, 2008 11:54:21 AM (5 years ago)
Author:
jrollins
Message:

debirf: big changes to add subcommand architecture. also added
"enter" subcommand and "no-initrd" option to "make" subcommand.

Location:
trunk/debirf
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/debirf/debian/changelog

    r919 r920  
    22 
    33  * changed name of main build script to 'debirf' from 'make-debirf' 
     4  * added subcommand architecture (make, enter, help) (closes CMRG #65) 
     5  * and "enter" subcommand to enter root (closes CMRG #73) 
    46  * removed separate specification of debirf root directory 
    57  * added install-manpages module (no longer installing manpages by default) 
    6   * pruned more unnecessary packages 
     8  * pruned more unnecessary packages from make 
    79  * remove build-debirf-kernel, since no longer needed 
    810  * improved install-kernel module to only download need kernel package 
     
    1416  * new install-runit module, jumps through hoops to overcome limitations 
    1517    of runit postinst script (closes CMRG #71) 
     18  * added "no-initrd" option to make subcommand 
    1619 
    17  -- Jameson Rollins <jrollins@fifthhorseman.net>  Fri, 11 Jan 2008 15:35:26 -0500 
     20 -- Jameson Rollins <jrollins@fifthhorseman.net>  Sat, 12 Jan 2008 11:49:45 -0500 
    1821 
    1922debirf (0.13-1) unstable; urgency=low 
  • trunk/debirf/fs/usr/bin/debirf

    r918 r920  
    4141usage() { 
    4242    cat <<EOF 
    43 Usage: $CMD [options] profile 
     43Usage: $CMD <subcommand> [options] [args] 
    4444Create a debirf kernel and initramfs.  The 'profile' is a path to a debirf 
    4545profile directory. 
    4646 
    47 options: 
    48   -h|--help               this help message 
    49   -c|--check-vars         check variables before make 
    50   -n|--new                create new root, even if old one exists 
    51   -o|--overwrite          debootstrap on top of old root if it exists 
    52   -s|--skip               skip debootstrap step if old root exists 
    53   -r|--root-build         use real chroot to build instead of fakechroot 
    54                           (requires superuser privileges or CAP_SYS_CHROOT) 
    55   -w|--no-warning         skip superuser warning 
    56   -i|--initrd-only        remake initramfs from existing root 
    57   -k|--kernel=KERNEL      install KERNEL .deb, instead of default kernel 
     47subcommands: 
     48  make (m) PROFILE        build debirf profile 
     49    -c|--check-vars         check variables before make 
     50    -n|--new                create new root, even if old one exists 
     51    -o|--overwrite          debootstrap on top of old root if it exists 
     52    -s|--skip               skip debootstrap step if old root exists 
     53    -r|--root-build         use real chroot to build instead of fakechroot 
     54                            (requires superuser privileges or CAP_SYS_CHROOT) 
     55    -w|--no-warning         skip superuser warning 
     56    -i|--no-initrd          do not make initramfs 
     57    -d|--initrd-only        just remake initramfs from existing root 
     58    -k|--kernel=KERNEL      install KERNEL .deb, instead of default kernel 
     59  enter (e) PROFILE       enter debirf profile to make manual changes 
     60  help (h,?)              this help 
     61 
    5862EOF 
    5963} 
     
    188192} 
    189193 
    190 ############################################################### 
    191 ### MAIN 
    192  
    193 # option parsing 
    194 TEMP=$(getopt --options -hcnosrwik: --longoptions help,check-vars,new,overwrite,skip,root-build,no-warning,initrd-only,kernel: -n "$CMD" -- "$@") 
    195  
    196 if [ $? != 0 ] ; then 
    197     echo "Invalid options." >&2  
    198     usage 
    199     exit 1 
    200 fi 
    201  
    202 # Note the quotes around `$TEMP': they are essential! 
    203 eval set -- "$TEMP" 
    204  
    205 while true ; do 
    206     case "$1" in 
    207         -h|--help) 
    208             usage 
    209             exit 0 
    210             ;; 
    211         -c|--check-vars) 
    212             CHECK_VARS=true 
    213             shift 1 
    214             ;; 
    215         -n|--new) 
    216             WRITE_MODE=rewrite 
    217             shift 1 
    218             ;; 
    219         -o|--overwrite) 
    220             WRITE_MODE=overwrite 
    221             shift 1 
    222             ;; 
    223         -s|--skip) 
    224             WRITE_MODE=skip 
    225             shift 1 
    226             ;; 
    227         -r|--root-build) 
    228             ROOT_BUILD=true 
    229             shift 1 
    230             ;; 
    231         -w|--no-warning) 
    232             ROOT_WARNING=false 
    233             shift 1 
    234             ;; 
    235         -i|--initrd-only) 
    236             STAGE_ROOT=false 
    237             STAGE_MODULES=false 
    238             shift 1 
    239             ;; 
    240         -k|--kernel) 
    241             DEBIRF_KERNEL_PACKAGE="$2" 
    242             shift 2 
    243             ;; 
    244         --) 
    245             shift 
    246             ;; 
    247         *) 
    248             if (( $# < 1 )) ; then 
    249                 echo "Improper number of input arguments." 
    250                 usage 
    251                 exit 1 
    252             fi 
    253             DEBIRF_PROFILE="$1" 
    254             break 
    255             ;; 
    256     esac 
    257 done 
    258  
    259 if [ $(id -u) = '0' ] ; then 
    260     cat <<EOF 
     194# setup profile environment 
     195setup_environment() { 
     196    # source debirf.conf defaults 
     197    source /usr/share/debirf/debirf.conf.defaults 
     198     
     199    # check profile 
     200    if [ -d "$DEBIRF_PROFILE" ] ; then 
     201        echo "Loading profile '$DEBIRF_PROFILE'..." 
     202        DEBIRF_CONF="$DEBIRF_PROFILE/debirf.conf" 
     203        DEBIRF_MODULES="$DEBIRF_PROFILE/modules" 
     204    else 
     205        echo "Profile '$DEBIRF_PROFILE' not found." 
     206        usage_profile 
     207        exit 1 
     208    fi 
     209     
     210    # source profile debirf.conf 
     211    if [ -f "$DEBIRF_CONF" ] ; then 
     212        source "$DEBIRF_CONF" 
     213    else 
     214        echo "Configuration file '$DEBIRF_CONF' not found." 
     215        usage_profile 
     216        exit 1 
     217    fi 
     218 
     219    # check modules directory 
     220    if [ ! -d "$DEBIRF_MODULES" ] || [ -z "$(ls "$DEBIRF_MODULES")" ] ; then 
     221        echo "Modules directoy '$DEBIRF_MODULES' does not exist or is empty." 
     222        usage_profile 
     223        exit 1 
     224    fi 
     225    for MODULE in $(find "$DEBIRF_MODULES") ; do 
     226        if [ ! -s "$MODULE" ] ; then 
     227            failure "Module '$MODULE' is a broken link or empty file." 
     228        fi 
     229    done 
     230     
     231    # check buildd 
     232    if [ -z "$DEBIRF_BUILDD" ] ; then 
     233        failure "DEBIRF_BUILDD is not set." 
     234    fi 
     235 
     236    # set root directory 
     237    DEBIRF_ROOT="$DEBIRF_BUILDD/root" 
     238 
     239    # set fakechroot save file 
     240    DEBIRF_FAKEROOT_STATE="$DEBIRF_BUILDD/.fakeroot-state.${DEBIRF_LABEL}" 
     241    if [ "$ROOT_BUILD" != 'true' ] ; then 
     242        > "$DEBIRF_FAKEROOT_STATE" 
     243    fi 
     244     
     245    # check variables 
     246    if [ "$CHECK_VARS" ] ; then 
     247        echo "Debirf variables:" 
     248        for var in ${!DEBIRF_*}; do 
     249            if [ $var ] ; then 
     250                export $var 
     251            else 
     252                failure "Variable '$var' not properly set." 
     253            fi 
     254        done 
     255        env | /bin/grep "^DEBIRF_" 
     256        read -p "enter to continue: " OK 
     257    fi 
     258} 
     259 
     260# make profile 
     261make() { 
     262    # option parsing 
     263    TEMP=$(getopt --options -hcnosrwidk: --longoptions help,check-vars,new,overwrite,skip,root-build,no-warning,no-initrd,initrd-only,kernel: -n "$CMD" -- "$@") 
     264 
     265    if [ $? != 0 ] ; then 
     266        echo "Invalid options." >&2  
     267        usage 
     268        exit 1 
     269    fi 
     270     
     271    # Note the quotes around `$TEMP': they are essential! 
     272    eval set -- "$TEMP" 
     273 
     274    while true ; do 
     275        case "$1" in 
     276            -c|--check-vars) 
     277                CHECK_VARS=true 
     278                shift 1 
     279                ;; 
     280            -n|--new) 
     281                WRITE_MODE=rewrite 
     282                shift 1 
     283                ;; 
     284            -o|--overwrite) 
     285                WRITE_MODE=overwrite 
     286                shift 1 
     287                ;; 
     288            -s|--skip) 
     289                WRITE_MODE=skip 
     290                shift 1 
     291                ;; 
     292            -r|--root-build) 
     293                ROOT_BUILD=true 
     294                shift 1 
     295                ;; 
     296            -w|--no-warning) 
     297                ROOT_WARNING=false 
     298                shift 1 
     299                ;; 
     300            -i|--no-initrd) 
     301                STAGE_INITRD=false 
     302                shift 1 
     303                ;; 
     304            -d|--initrd-only) 
     305                STAGE_ROOT=false 
     306                STAGE_MODULES=false 
     307                shift 1 
     308                ;; 
     309            -k|--kernel) 
     310                DEBIRF_KERNEL_PACKAGE="$2" 
     311                shift 2 
     312                ;; 
     313            --) 
     314                shift 
     315                ;; 
     316            *) 
     317                if (( $# < 1 )) ; then 
     318                    echo "Improper number of input arguments." 
     319                    usage 
     320                    exit 1 
     321                fi 
     322                DEBIRF_PROFILE="$1" 
     323                break 
     324                ;; 
     325        esac 
     326    done 
     327     
     328    if [ $(id -u) = '0' ] ; then 
     329        cat <<EOF 
    261330Warning: You are running debirf as root.  There is a potential 
    262331for improperly written modules to damage your system. 
    263332EOF 
    264     if [ "$ROOT_WARNING" = 'true' ] ; then 
    265         read -p "Are you sure you wish to continue? [y|N]: " OK; OK=${OK:=N} 
    266         if [ "${OK/y/Y}" != 'Y' ] ; then 
    267             failure "aborting." 
    268         fi 
    269     fi 
    270 fi 
    271  
    272 if [ "$DEBIRF_KERNEL_PACKAGE" ] ; then 
    273     if [ -f "$DEBIRF_KERNEL_PACKAGE" ] ; then 
    274         echo "Using kernel package '$DEBIRF_KERNEL_PACKAGE'." 
    275     else 
    276         failure "Kernel package '$DEBIRF_KERNEL_PACKAGE' not found." 
    277     fi 
    278 fi 
    279  
    280 # source debirf.conf defaults 
    281 source /usr/share/debirf/debirf.conf.defaults 
    282  
    283 # check profile 
    284 if [ -d "$DEBIRF_PROFILE" ] ; then 
    285     echo "Loading profile '$DEBIRF_PROFILE'..." 
    286     DEBIRF_CONF="$DEBIRF_PROFILE/debirf.conf" 
    287     DEBIRF_MODULES="$DEBIRF_PROFILE/modules" 
    288 else 
    289     echo "Profile '$DEBIRF_PROFILE' not found." 
    290     usage_profile 
    291     exit 1 
    292 fi 
    293  
    294 # source profile debirf.conf 
    295 if [ -f "$DEBIRF_CONF" ] ; then 
    296     source "$DEBIRF_CONF" 
    297 else 
    298     echo "Configuration file '$DEBIRF_CONF' not found." 
    299     usage_profile 
    300     exit 1 
    301 fi 
    302  
    303 # check modules directory 
    304 if [ ! -d "$DEBIRF_MODULES" ] || [ -z "$(ls "$DEBIRF_MODULES")" ] ; then 
    305     echo "Modules directoy '$DEBIRF_MODULES' does not exist or is empty." 
    306     usage_profile 
    307     exit 1 
    308 fi 
    309 for MODULE in $(find "$DEBIRF_MODULES") ; do 
    310     if [ ! -s "$MODULE" ] ; then 
    311         failure "Module '$MODULE' is a broken link or empty file." 
    312     fi 
    313 done 
    314  
    315 # check buildd 
    316 if [ -z "$DEBIRF_BUILDD" ] ; then 
    317     failure "DEBIRF_BUILDD is not set." 
    318 fi 
    319  
    320 # set root directory 
    321 DEBIRF_ROOT="$DEBIRF_BUILDD/root" 
    322  
    323 # set fakechroot save file 
    324 DEBIRF_FAKEROOT_STATE="$DEBIRF_BUILDD/.fakeroot-state.${DEBIRF_LABEL}" 
    325 if [ "$ROOT_BUILD" != 'true' ] ; then 
    326     > "$DEBIRF_FAKEROOT_STATE" 
    327 fi 
    328  
    329 # check variables 
    330 if [ "$CHECK_VARS" ] ; then 
    331     echo "Debirf variables:" 
     333        if [ "$ROOT_WARNING" = 'true' ] ; then 
     334            read -p "Are you sure you wish to continue? [y|N]: " OK; OK=${OK:=N} 
     335            if [ "${OK/y/Y}" != 'Y' ] ; then 
     336                failure "aborting." 
     337            fi 
     338        fi 
     339    fi 
     340 
     341    setup_environment 
     342 
     343    if [ "$DEBIRF_KERNEL_PACKAGE" ] ; then 
     344        if [ -f "$DEBIRF_KERNEL_PACKAGE" ] ; then 
     345            echo "Using kernel package '$DEBIRF_KERNEL_PACKAGE'." 
     346        else 
     347            failure "Kernel package '$DEBIRF_KERNEL_PACKAGE' not found." 
     348        fi 
     349    fi 
     350     
     351    ### BUILD ROOT 
     352    if [ "$STAGE_ROOT" = 'true' ] ; then 
     353         
     354        # determine write mode 
     355        if [ -d "$DEBIRF_ROOT" ] ; then 
     356            echo "Debirf root already exists." 
     357            if [ -z "$WRITE_MODE" ] ; then 
     358                echo "Select one of the following:" 
     359                CASE1='new: delete the old root and create a new one' 
     360                CASE2='overwrite: leave the old root and debootstrap on top of it' 
     361                CASE3='skip: skip building the root and go right to installing modules' 
     362                CASE4='exit' 
     363                select CASE in "$CASE1" "$CASE2" "$CASE3" "$CASE4" ; do 
     364                    case "$REPLY" in 
     365                        1) 
     366                            WRITE_MODE=rewrite 
     367                            ;; 
     368                        2) 
     369                            WRITE_MODE=overwrite 
     370                            ;; 
     371                        3) 
     372                            WRITE_MODE=skip 
     373                            ;; 
     374                        *) 
     375                            failure "aborting." 
     376                            ;; 
     377                    esac 
     378                    break 
     379                done 
     380            fi 
     381        else 
     382            WRITE_MODE=new 
     383        fi 
     384        case "$WRITE_MODE" in 
     385            'new') 
     386                msg "creating debirf root..." 
     387                create_debootstrap 
     388                ;; 
     389            'rewrite') 
     390                msg "clearing old debirf root..." 
     391                rm -rf "$DEBIRF_ROOT" 
     392                msg "creating debirf root..." 
     393                create_debootstrap 
     394                ;; 
     395            'overwrite') 
     396                msg "overwriting old debirf root..." 
     397                create_debootstrap 
     398                ;; 
     399            'skip') 
     400                msg "skipping debootstrap..." 
     401                ;; 
     402            *) 
     403                failure "aborting." 
     404                ;; 
     405        esac 
     406         
     407        # fix the dev tree if running as non-priv user (fakechroot debootstrap) 
     408        fix_dev 
     409         
     410    else 
     411        echo "Not building root." 
     412    fi 
     413    ### END BUILD ROOT 
     414     
     415    ### RUN MODULES 
     416    if [ "$STAGE_MODULES" = 'true' ] ; then 
     417        msg "executing modules..." 
     418        run_modules 
     419        msg "modules complete." 
     420    else 
     421        echo "Not running modules." 
     422    fi 
     423    ### END RUN MODULES 
     424 
     425    ### BUILD INITRD 
     426    if [ "$STAGE_INITRD" = 'true' ] ; then 
     427        if [ ! -d "$DEBIRF_ROOT" ] ; then 
     428            failure "Debirf root '$DEBIRF_ROOT' not found." 
     429        fi 
     430        # determine initrd name 
     431        KERNEL_VERS=$(ls -1 "$DEBIRF_ROOT/lib/modules" | head -n1) 
     432        DEBIRF_INITRD="${DEBIRF_BUILDD}/${DEBIRF_LABEL}_${DEBIRF_DISTRO}_${KERNEL_VERS}.cgz" 
     433         
     434        msg "creating debirf initrd ('$DEBIRF_METHOD')..." 
     435        create_initrd_${DEBIRF_METHOD} "$DEBIRF_INITRD" 
     436         
     437        # final output 
     438        DEBIRF_KERNEL=$(ls "$DEBIRF_BUILDD" | grep "vmlinu" | grep "$KERNEL_VERS$") 
     439        msg "debirf initrd created." 
     440        if [ "$DEBIRF_BUILDD/$DEBIRF_KERNEL" ] ; then 
     441            msg "kernel: $DEBIRF_BUILDD/$DEBIRF_KERNEL" 
     442        fi 
     443        msg "initrd: $DEBIRF_INITRD" 
     444    else 
     445        echo "Not creating initramfs." 
     446    fi 
     447    ### END BUILD INITRD 
     448} 
     449 
     450# enter profile root 
     451enter() { 
     452    DEBIRF_PROFILE="$1" 
     453    shift 
     454 
     455    setup_environment 
     456 
     457    # export all the DEBIRF_* environment variables: 
    332458    for var in ${!DEBIRF_*}; do 
    333         if [ $var ] ; then 
    334             export $var 
    335         else 
    336             failure "Variable '$var' not properly set." 
    337         fi 
    338     done 
    339     env | /bin/grep "^DEBIRF_" 
    340     read -p "enter to continue: " OK 
    341 fi 
    342  
    343 ### BUILD ROOT 
    344 if [ "$STAGE_ROOT" = 'true' ] ; then 
    345  
    346 # determine write mode 
    347 if [ -d "$DEBIRF_ROOT" ] ; then 
    348     echo "Debirf root already exists." 
    349     if [ -z "$WRITE_MODE" ] ; then 
    350         echo "Select one of the following:" 
    351         CASE1='new: delete the old root and create a new one' 
    352         CASE2='overwrite: leave the old root and debootstrap on top of it' 
    353         CASE3='skip: skip building the root and go right to installing modules' 
    354         CASE4='exit' 
    355         select CASE in "$CASE1" "$CASE2" "$CASE3" "$CASE4" ; do 
    356             case "$REPLY" in 
    357                 1) 
    358                     WRITE_MODE=rewrite 
    359                     ;; 
    360                 2) 
    361                     WRITE_MODE=overwrite 
    362                     ;; 
    363                 3) 
    364                     WRITE_MODE=skip 
    365                     ;; 
    366                 *) 
    367                     failure "aborting." 
    368                     ;; 
    369             esac 
    370             break 
    371         done 
    372     fi 
    373 else 
    374     WRITE_MODE=new 
    375 fi 
    376 case "$WRITE_MODE" in 
    377     'new') 
    378         msg "creating debirf root..." 
    379         create_debootstrap 
    380         ;; 
    381     'rewrite') 
    382         msg "clearing old debirf root..." 
    383         rm -rf "$DEBIRF_ROOT" 
    384         msg "creating debirf root..." 
    385         create_debootstrap 
    386         ;; 
    387     'overwrite') 
    388         msg "overwriting old debirf root..." 
    389         create_debootstrap 
    390         ;; 
    391     'skip') 
    392         msg "skipping debootstrap..." 
    393         ;; 
     459        export $var 
     460    done 
     461 
     462    if [ "$1" ] ; then 
     463        fakeroot_if_needed debirf_exec "$@" 
     464    else 
     465        fakeroot_if_needed debirf_exec bash 
     466    fi 
     467} 
     468 
     469############################################################### 
     470### MAIN 
     471 
     472COMMAND="$1" 
     473[ "$COMMAND" ] || failure "Type '$CMD help' for usage." 
     474shift 
     475 
     476case $COMMAND in 
     477    'make'|'m') 
     478        make "$@" 
     479        ;; 
     480    'enter'|'e') 
     481        enter "$@" 
     482        ;; 
     483    'help'|'h'|'?') 
     484        usage 
     485        ;; 
    394486    *) 
    395         failure "aborting." 
    396         ;; 
     487        failure "Unknown command: '$COMMAND' 
     488Type '$CMD help' for usage." 
     489        ;; 
    397490esac 
    398  
    399 # fix the dev tree if running as non-priv user (fakechroot debootstrap) 
    400 fix_dev 
    401  
    402 else 
    403     echo "Not building root." 
    404 fi 
    405 ### END BUILD ROOT 
    406  
    407 ### RUN MODULES 
    408 if [ "$STAGE_MODULES" = 'true' ] ; then 
    409     msg "executing modules..." 
    410     run_modules 
    411     msg "modules complete." 
    412 else 
    413     echo "Not running modules." 
    414 fi 
    415 ### END RUN MODULES 
    416  
    417 ### BUILD INITRD 
    418 if [ "$STAGE_INITRD" = 'true' ] ; then 
    419     if [ ! -d "$DEBIRF_ROOT" ] ; then 
    420         failure "Debirf root '$DEBIRF_ROOT' not found." 
    421     fi 
    422     # determine initrd name 
    423     KERNEL_VERS=$(ls -1 "$DEBIRF_ROOT/lib/modules" | head -n1) 
    424     DEBIRF_INITRD="${DEBIRF_BUILDD}/${DEBIRF_LABEL}_${DEBIRF_DISTRO}_${KERNEL_VERS}.cgz" 
    425  
    426     msg "creating debirf initrd ('$DEBIRF_METHOD')..." 
    427     create_initrd_${DEBIRF_METHOD} "$DEBIRF_INITRD" 
    428  
    429     # final output 
    430     DEBIRF_KERNEL=$(ls "$DEBIRF_BUILDD" | grep "vmlinu" | grep "$KERNEL_VERS$") 
    431     msg "debirf initrd created." 
    432     if [ "$DEBIRF_BUILDD/$DEBIRF_KERNEL" ] ; then 
    433         msg "kernel: $DEBIRF_BUILDD/$DEBIRF_KERNEL" 
    434     fi 
    435     msg "initrd: $DEBIRF_INITRD" 
    436 else 
    437     echo "Not creating initramfs." 
    438 fi 
    439 ### END BUILD INITRD 
Note: See TracChangeset for help on using the changeset viewer.