Skip to content

Instantly share code, notes, and snippets.

@davidlohr
Last active March 13, 2016 21:16
Show Gist options
  • Save davidlohr/83df4897e5c405a46a5f to your computer and use it in GitHub Desktop.
Save davidlohr/83df4897e5c405a46a5f to your computer and use it in GitHub Desktop.

Revisions

  1. davidlohr revised this gist Mar 13, 2016. 1 changed file with 4 additions and 4 deletions.
    8 changes: 4 additions & 4 deletions kbuild-auto.sh
    Original file line number Diff line number Diff line change
    @@ -15,17 +15,17 @@
    # before cloning)
    # [--cleanup] (removes cloned working directory once done)
    #
    # (defaults will always be Linus' master tree).
    #
    # notes:
    # o defaults will always be master branch on Linus' tree.
    # o the script does everything inside working directory where called.
    # examples:
    # ./kbuid-auto.sh --config /boot/config-4.5.0-rc5
    # ./kbuid-auto.sh --repo rcu --config /boot/config-4.5.0-rc5
    # ./kbuid-auto.sh --config /boot/config-4.5.0-rc5 --kernels v4.4,v4.5 --force
    #
    # TODO (wishlist):
    # o Change (grub) bootloader default.
    # o Way changing git protocol if default (git://) fails.
    # o Machine reboot option?
    # o When available, use bkp protocol if default git:// fails.
    # o --repo-url <url> option, for non-tagged repositories.
    #

  2. davidlohr revised this gist Mar 13, 2016. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion kbuild-auto.sh
    Original file line number Diff line number Diff line change
    @@ -115,5 +115,5 @@ do
    done

    if [ "$GIT_REPO_CLEANUP" = "yes" ]; then
    cd .. && rm -rf
    cd .. && rm -rf $GIT_REPO_ALIAS
    fi
  3. davidlohr revised this gist Mar 13, 2016. 1 changed file with 12 additions and 1 deletion.
    13 changes: 12 additions & 1 deletion kbuild-auto.sh
    Original file line number Diff line number Diff line change
    @@ -11,7 +11,9 @@
    # kbuild-auto.sh --config <config-file>
    # [--kernels <master,v4.5,v4.5-rc1,...>]
    # [--repo <linux|tip|rcu|next|...>]
    # [--force]
    # [--force] (removes any exising repository directory
    # before cloning)
    # [--cleanup] (removes cloned working directory once done)
    #
    # (defaults will always be Linus' master tree).
    #
    @@ -31,6 +33,7 @@ KERNEL_DOTCONFIG="" # non-optional arg
    GIT_REPO_ALIAS="linux"
    KERNEL_STR="master"
    GIT_REPO_FORCE=0 # do not overwrite an existing repo
    GIT_REPO_CLEANUP=0 # cleanup after ourselves
    NUMCPUS=$(grep -c '^processor' /proc/cpuinfo)
    MAKE="make -j$((NUMCPUS*2))"

    @@ -60,6 +63,10 @@ while [ "$1" != "" ]; do
    GIT_REPO_ALIAS=$2
    shift 2
    ;;
    --cleanup)
    GIT_REPO_CLEANUP="yes"
    shift 1
    ;;
    --force)
    GIT_REPO_FORCE="yes"
    shift 1
    @@ -106,3 +113,7 @@ do
    # ^^ can return (ignorable) symbol warnings.
    $MAKE && $MAKE modules && $MAKE modules_install && $MAKE install
    done

    if [ "$GIT_REPO_CLEANUP" = "yes" ]; then
    cd .. && rm -rf
    fi
  4. davidlohr revised this gist Mar 13, 2016. 1 changed file with 1 addition and 0 deletions.
    1 change: 1 addition & 0 deletions kbuild-auto.sh
    Original file line number Diff line number Diff line change
    @@ -42,6 +42,7 @@ GIT_REPO_ARR["next"]=git://git.kernel.org/pub/scm/linux/kernel/git/next/linux-ne
    GIT_REPO_ARR["rcu"]=git://git.kernel.org/pub/scm/linux/kernel/git/paulmck/linux-rcu.git
    GIT_REPO_ARR["net"]=git://git.kernel.org/pub/scm/linux/kernel/git/davem/net.git
    GIT_REPO_ARR["block"]=git://git.kernel.org/pub/scm/linux/kernel/git/axboe/linux-block.git
    # -- akpm
    GIT_REPO_ARR["mmotm"]=git://git.cmpxchg.org/linux-mmotm.git
    GIT_REPO_ARR["mmots"]=git://git.cmpxchg.org/linux-mmots.git

  5. davidlohr revised this gist Mar 13, 2016. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion kbuild-auto.sh
    Original file line number Diff line number Diff line change
    @@ -79,7 +79,6 @@ fi

    # zypper in -y git-core gcc openssl-devel
    GIT_CLONE_REPO=${GIT_REPO_ARR[$GIT_REPO_ALIAS]}
    IFS=',' read -a KERNEL_ARR <<< "$KERNEL_STR"

    if [ "$GIT_CLONE_REPO" = "" ]; then
    echo "$0: '$GIT_REPO_ALIAS' is not a valid repository alias (--repo)"
    @@ -98,6 +97,7 @@ cp $KERNEL_DOTCONFIG $GIT_REPO_ALIAS/.config && cd $GIT_REPO_ALIAS
    #
    # Lets do it!
    #
    IFS=',' read -a KERNEL_ARR <<< "$KERNEL_STR"
    for KERNEL in ${KERNEL_ARR[@]}
    do
    # echo "Checking out and building '${KERNEL}'"
  6. davidlohr revised this gist Mar 13, 2016. 1 changed file with 2 additions and 0 deletions.
    2 changes: 2 additions & 0 deletions kbuild-auto.sh
    Original file line number Diff line number Diff line change
    @@ -40,6 +40,8 @@ GIT_REPO_ARR["linux"]=git://git.kernel.org/pub/scm/linux/kernel/git/torvalds/lin
    GIT_REPO_ARR["tip"]=git://git.kernel.org/pub/scm/linux/kernel/git/tip/tip.git
    GIT_REPO_ARR["next"]=git://git.kernel.org/pub/scm/linux/kernel/git/next/linux-next.git
    GIT_REPO_ARR["rcu"]=git://git.kernel.org/pub/scm/linux/kernel/git/paulmck/linux-rcu.git
    GIT_REPO_ARR["net"]=git://git.kernel.org/pub/scm/linux/kernel/git/davem/net.git
    GIT_REPO_ARR["block"]=git://git.kernel.org/pub/scm/linux/kernel/git/axboe/linux-block.git
    GIT_REPO_ARR["mmotm"]=git://git.cmpxchg.org/linux-mmotm.git
    GIT_REPO_ARR["mmots"]=git://git.cmpxchg.org/linux-mmots.git

  7. davidlohr revised this gist Mar 13, 2016. No changes.
  8. davidlohr revised this gist Mar 13, 2016. 1 changed file with 1 addition and 2 deletions.
    3 changes: 1 addition & 2 deletions kbuild-auto.sh
    Original file line number Diff line number Diff line change
    @@ -81,8 +81,7 @@ IFS=',' read -a KERNEL_ARR <<< "$KERNEL_STR"

    if [ "$GIT_CLONE_REPO" = "" ]; then
    echo "$0: '$GIT_REPO_ALIAS' is not a valid repository alias (--repo)"
    echo -ne "$0: Available repositories are:"
    echo "$0: ${!GIT_REPO_ARR[@]}"
    echo "$0: Available repositories are: ${!GIT_REPO_ARR[@]}"
    exit 1
    fi

  9. davidlohr revised this gist Mar 13, 2016. 1 changed file with 4 additions and 3 deletions.
    7 changes: 4 additions & 3 deletions kbuild-auto.sh
    Original file line number Diff line number Diff line change
    @@ -10,20 +10,21 @@
    # Usage:
    # kbuild-auto.sh --config <config-file>
    # [--kernels <master,v4.5,v4.5-rc1,...>]
    # [--repo <linux|tip|rcu|next>]
    # [--repo-url <url>]
    # [--repo <linux|tip|rcu|next|...>]
    # [--force]
    #
    # (defaults will always be Linus' master tree).
    #
    # examples:
    # ./kbuid-auto.sh --config /boot/config-4.5.0-rc5
    # ./kbuid-auto.sh --repo rcu --config /boot/config-4.5.0-rc5
    # ./kbuid-auto.sh --config /boot/config-4.5.0-rc5 --kernels v4.4,v4.5 --force
    #
    # TODO (wishlist):
    # o Change (grub) bootloader default.
    # o Way changing git protocol if default (git://) fails.
    # o Machine reboot option?
    # o --repo-url <url> option, for non-tagged repositories.
    #

    KERNEL_DOTCONFIG="" # non-optional arg
    @@ -80,7 +81,7 @@ IFS=',' read -a KERNEL_ARR <<< "$KERNEL_STR"

    if [ "$GIT_CLONE_REPO" = "" ]; then
    echo "$0: '$GIT_REPO_ALIAS' is not a valid repository alias (--repo)"
    echo "$0: Available repositories are:"
    echo -ne "$0: Available repositories are:"
    echo "$0: ${!GIT_REPO_ARR[@]}"
    exit 1
    fi
  10. davidlohr revised this gist Mar 13, 2016. 1 changed file with 1 addition and 3 deletions.
    4 changes: 1 addition & 3 deletions kbuild-auto.sh
    Original file line number Diff line number Diff line change
    @@ -81,9 +81,7 @@ IFS=',' read -a KERNEL_ARR <<< "$KERNEL_STR"
    if [ "$GIT_CLONE_REPO" = "" ]; then
    echo "$0: '$GIT_REPO_ALIAS' is not a valid repository alias (--repo)"
    echo "$0: Available repositories are:"
    for alias in "${GIT_REPO_ARR[@]}"; do
    echo "0: ${GIT_REPO_ARR[$alias]} --- $alias";
    done
    echo "$0: ${!GIT_REPO_ARR[@]}"
    exit 1
    fi

  11. davidlohr revised this gist Mar 13, 2016. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion kbuild-auto.sh
    Original file line number Diff line number Diff line change
    @@ -82,7 +82,7 @@ if [ "$GIT_CLONE_REPO" = "" ]; then
    echo "$0: '$GIT_REPO_ALIAS' is not a valid repository alias (--repo)"
    echo "$0: Available repositories are:"
    for alias in "${GIT_REPO_ARR[@]}"; do
    echo "0:\t$alias --- ${GIT_REPO_ARR[$alias]}";
    echo "0: ${GIT_REPO_ARR[$alias]} --- $alias";
    done
    exit 1
    fi
  12. davidlohr revised this gist Mar 13, 2016. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion kbuild-auto.sh
    Original file line number Diff line number Diff line change
    @@ -82,7 +82,7 @@ if [ "$GIT_CLONE_REPO" = "" ]; then
    echo "$0: '$GIT_REPO_ALIAS' is not a valid repository alias (--repo)"
    echo "$0: Available repositories are:"
    for alias in "${GIT_REPO_ARR[@]}"; do
    echo "0:\t$alias --- ${GIT_REPO_ARR[$i]}";
    echo "0:\t$alias --- ${GIT_REPO_ARR[$alias]}";
    done
    exit 1
    fi
  13. davidlohr revised this gist Mar 13, 2016. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion kbuild-auto.sh
    Original file line number Diff line number Diff line change
    @@ -81,7 +81,7 @@ IFS=',' read -a KERNEL_ARR <<< "$KERNEL_STR"
    if [ "$GIT_CLONE_REPO" = "" ]; then
    echo "$0: '$GIT_REPO_ALIAS' is not a valid repository alias (--repo)"
    echo "$0: Available repositories are:"
    for alias in "${KGIT_REPO_ARR[@]}"; do
    for alias in "${GIT_REPO_ARR[@]}"; do
    echo "0:\t$alias --- ${GIT_REPO_ARR[$i]}";
    done
    exit 1
  14. davidlohr revised this gist Mar 13, 2016. 1 changed file with 2 additions and 2 deletions.
    4 changes: 2 additions & 2 deletions kbuild-auto.sh
    Original file line number Diff line number Diff line change
    @@ -81,8 +81,8 @@ IFS=',' read -a KERNEL_ARR <<< "$KERNEL_STR"
    if [ "$GIT_CLONE_REPO" = "" ]; then
    echo "$0: '$GIT_REPO_ALIAS' is not a valid repository alias (--repo)"
    echo "$0: Available repositories are:"
    for i in "${!KERNEL_ARR[@]}"; do
    echo "\t$i --- ${KERNEL_ARR[$i]}";
    for alias in "${KGIT_REPO_ARR[@]}"; do
    echo "0:\t$alias --- ${GIT_REPO_ARR[$i]}";
    done
    exit 1
    fi
  15. davidlohr revised this gist Mar 13, 2016. 1 changed file with 8 additions and 2 deletions.
    10 changes: 8 additions & 2 deletions kbuild-auto.sh
    Original file line number Diff line number Diff line change
    @@ -39,6 +39,8 @@ GIT_REPO_ARR["linux"]=git://git.kernel.org/pub/scm/linux/kernel/git/torvalds/lin
    GIT_REPO_ARR["tip"]=git://git.kernel.org/pub/scm/linux/kernel/git/tip/tip.git
    GIT_REPO_ARR["next"]=git://git.kernel.org/pub/scm/linux/kernel/git/next/linux-next.git
    GIT_REPO_ARR["rcu"]=git://git.kernel.org/pub/scm/linux/kernel/git/paulmck/linux-rcu.git
    GIT_REPO_ARR["mmotm"]=git://git.cmpxchg.org/linux-mmotm.git
    GIT_REPO_ARR["mmots"]=git://git.cmpxchg.org/linux-mmots.git

    while [ "$1" != "" ]; do
    case "$1" in
    @@ -72,11 +74,16 @@ if [ ! -f $KERNEL_DOTCONFIG ] || [ "$KERNEL_DOTCONFIG" = "" ]; then
    exit 1
    fi

    # zypper in -y git-core gcc
    # zypper in -y git-core gcc openssl-devel
    GIT_CLONE_REPO=${GIT_REPO_ARR[$GIT_REPO_ALIAS]}
    IFS=',' read -a KERNEL_ARR <<< "$KERNEL_STR"

    if [ "$GIT_CLONE_REPO" = "" ]; then
    echo "$0: '$GIT_REPO_ALIAS' is not a valid repository alias (--repo)"
    echo "$0: Available repositories are:"
    for i in "${!KERNEL_ARR[@]}"; do
    echo "\t$i --- ${KERNEL_ARR[$i]}";
    done
    exit 1
    fi

    @@ -91,7 +98,6 @@ cp $KERNEL_DOTCONFIG $GIT_REPO_ALIAS/.config && cd $GIT_REPO_ALIAS
    #
    # Lets do it!
    #
    IFS=',' read -a KERNEL_ARR <<< "$KERNEL_STR"
    for KERNEL in ${KERNEL_ARR[@]}
    do
    # echo "Checking out and building '${KERNEL}'"
  16. davidlohr revised this gist Mar 13, 2016. 1 changed file with 3 additions and 3 deletions.
    6 changes: 3 additions & 3 deletions kbuild-auto.sh
    Original file line number Diff line number Diff line change
    @@ -3,9 +3,9 @@
    # Copyright (C) 2016 Davidlohr Bueso.
    #
    # Download and build/install one or more flavors of the Linux kernel.
    # Do what you please with this, but expect you better be root if you
    # expect it to do anything useful. Also, probably very SUSE specific,
    # this is my only working env.
    # Do what you please with this, but you better be root if you expect
    # it to do anything useful. Also, probably very SUSE specific, this
    # is my only working env.
    #
    # Usage:
    # kbuild-auto.sh --config <config-file>
  17. davidlohr revised this gist Mar 12, 2016. 1 changed file with 2 additions and 2 deletions.
    4 changes: 2 additions & 2 deletions kbuild-auto.sh
    Original file line number Diff line number Diff line change
    @@ -10,7 +10,7 @@
    # Usage:
    # kbuild-auto.sh --config <config-file>
    # [--kernels <master,v4.5,v4.5-rc1,...>]
    # [--repo <linux|tip|rcu|next]>]
    # [--repo <linux|tip|rcu|next>]
    # [--repo-url <url>]
    # [--force]
    #
    @@ -86,7 +86,7 @@ if [ "$GIT_REPO_FORCE" = "yes" ]; then
    fi

    git clone $GIT_CLONE_REPO $GIT_REPO_ALIAS
    cp $KERNEL_DOTCONFIG "$GIT_REPO_ALIAS/.config" && cd $GIT_REPO_ALIAS
    cp $KERNEL_DOTCONFIG $GIT_REPO_ALIAS/.config && cd $GIT_REPO_ALIAS

    #
    # Lets do it!
  18. davidlohr revised this gist Mar 12, 2016. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion kbuild-auto.sh
    Original file line number Diff line number Diff line change
    @@ -4,7 +4,7 @@
    #
    # Download and build/install one or more flavors of the Linux kernel.
    # Do what you please with this, but expect you better be root if you
    # expect it to do anything useful. # Also, probably very SUSE specific,
    # expect it to do anything useful. Also, probably very SUSE specific,
    # this is my only working env.
    #
    # Usage:
  19. davidlohr created this gist Mar 12, 2016.
    101 changes: 101 additions & 0 deletions kbuild-auto.sh
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,101 @@
    #!/bin/bash
    #
    # Copyright (C) 2016 Davidlohr Bueso.
    #
    # Download and build/install one or more flavors of the Linux kernel.
    # Do what you please with this, but expect you better be root if you
    # expect it to do anything useful. # Also, probably very SUSE specific,
    # this is my only working env.
    #
    # Usage:
    # kbuild-auto.sh --config <config-file>
    # [--kernels <master,v4.5,v4.5-rc1,...>]
    # [--repo <linux|tip|rcu|next]>]
    # [--repo-url <url>]
    # [--force]
    #
    # (defaults will always be Linus' master tree).
    #
    # examples:
    # ./kbuid-auto.sh --config /boot/config-4.5.0-rc5
    # ./kbuid-auto.sh --repo rcu --config /boot/config-4.5.0-rc5
    #
    # TODO (wishlist):
    # o Change (grub) bootloader default.
    # o Way changing git protocol if default (git://) fails.
    # o Machine reboot option?
    #

    KERNEL_DOTCONFIG="" # non-optional arg
    GIT_REPO_ALIAS="linux"
    KERNEL_STR="master"
    GIT_REPO_FORCE=0 # do not overwrite an existing repo
    NUMCPUS=$(grep -c '^processor' /proc/cpuinfo)
    MAKE="make -j$((NUMCPUS*2))"

    # Linus' and other common used trees for kernel development.
    declare -A GIT_REPO_ARR
    GIT_REPO_ARR["linux"]=git://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
    GIT_REPO_ARR["tip"]=git://git.kernel.org/pub/scm/linux/kernel/git/tip/tip.git
    GIT_REPO_ARR["next"]=git://git.kernel.org/pub/scm/linux/kernel/git/next/linux-next.git
    GIT_REPO_ARR["rcu"]=git://git.kernel.org/pub/scm/linux/kernel/git/paulmck/linux-rcu.git

    while [ "$1" != "" ]; do
    case "$1" in
    --config)
    KERNEL_DOTCONFIG=$2
    shift 2
    ;;
    --kernels)
    KERNEL_STR=$2
    shift 2
    ;;
    --repo)
    GIT_REPO_ALIAS=$2
    shift 2
    ;;
    --force)
    GIT_REPO_FORCE="yes"
    shift 1
    ;;
    *)
    echo Unrecognised option: $1
    shift
    esac
    done

    #
    # Input sanitation
    #
    if [ ! -f $KERNEL_DOTCONFIG ] || [ "$KERNEL_DOTCONFIG" = "" ]; then
    echo "$0: Must pass a valid base configuration file (--config)"
    exit 1
    fi

    # zypper in -y git-core gcc
    GIT_CLONE_REPO=${GIT_REPO_ARR[$GIT_REPO_ALIAS]}

    if [ "$GIT_CLONE_REPO" = "" ]; then
    echo "$0: '$GIT_REPO_ALIAS' is not a valid repository alias (--repo)"
    exit 1
    fi

    if [ "$GIT_REPO_FORCE" = "yes" ]; then
    echo "$0: Deleting any previous '$GIT_REPO_ALIAS' directory"
    rm -rf $GIT_REPO_ALIAS # do not bother checking if it exists
    fi

    git clone $GIT_CLONE_REPO $GIT_REPO_ALIAS
    cp $KERNEL_DOTCONFIG "$GIT_REPO_ALIAS/.config" && cd $GIT_REPO_ALIAS

    #
    # Lets do it!
    #
    IFS=',' read -a KERNEL_ARR <<< "$KERNEL_STR"
    for KERNEL in ${KERNEL_ARR[@]}
    do
    # echo "Checking out and building '${KERNEL}'"
    git checkout $KERNEL && make olddefconfig
    # ^^ can return (ignorable) symbol warnings.
    $MAKE && $MAKE modules && $MAKE modules_install && $MAKE install
    done