diff options
author | Cem Keylan <cem@ckyln.com> | 2020-05-31 01:52:15 +0300 |
---|---|---|
committer | Konstantin Ryabitsev <konstantin@linuxfoundation.org> | 2020-06-01 12:32:46 -0400 |
commit | 8fd2fb389bcf886e6dfa3f6b3abe0396599ecafe (patch) | |
tree | cd1d6f38ef063eae7d354e3ad34ebcc2d056c265 | |
parent | d817474dfa35bc79809183920ae075d3ed727549 (diff) | |
download | korg-helpers-8fd2fb389bcf886e6dfa3f6b3abe0396599ecafe.tar.gz |
POSIX compatibility for linux-bundle-clone
Made some minor changes to make the script POSIX compliant
and some nitpicks to simplify the script.
Removed the if statements and replaced them with logical operators.
Also used default variable assignments to skip some checks to make
the script smaller.
Changed the temporary name of the bundle as some implementations of
mktemp (such as busybox) do not allow any name after the 'XXXXXXX'
part.
Signed-off-by: Konstantin Ryabitsev <konstantin@linuxfoundation.org>
-rwxr-xr-x | linux-bundle-clone | 38 |
1 files changed, 16 insertions, 22 deletions
diff --git a/linux-bundle-clone b/linux-bundle-clone index ec9ac8a..167ffb7 100755 --- a/linux-bundle-clone +++ b/linux-bundle-clone @@ -1,27 +1,22 @@ -#!/bin/bash +#!/bin/sh # linux-bundle-clone # ------------------ # Use this script to clone a Linux repository using a CDN-hosted bundle. # This is the recommended way to clone Linux in a CI environment where # the full repository needs to be cloned every time. -REMOTE=${1} -if [[ -z ${REMOTE} ]]; then +[ "${REMOTE:=$1}" ] || { echo "Please specify the remote to clone" echo "Example: ${0} https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git linux master" exit 1 -fi +} -TARGET=${2} -if [[ -z ${TARGET} ]]; then +[ "${TARGET:=$2}" ] || { echo "Please specify the target directory" echo "Example: ${0} https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git linux master" exit 1 -fi +} -CHECKOUT=${3} -if [[ -z ${CHECKOUT} ]]; then - CHECKOUT=master -fi +CHECKOUT=${3:-master} # You can also use "http" if you are behind a caching proxy and want to # benefit from a locally stored copy. Initial time to first byte may be @@ -37,30 +32,29 @@ CDNBUNDLE="https://cdn.kernel.org/pub/scm/.bundles/pub/scm/linux/kernel/git/torv # We'll put the bundle into a safe temp location, but WARNING -- it's a # 1Gb+ file, so if you have limited space in /tmp, you should consider # changing the path here. See "man mktemp". -BUNDLELOCAL=$(mktemp /tmp/linux.XXXXXXXXXX.bundle) +BUNDLELOCAL=$(mktemp /tmp/linux-bundle.XXXXXXXXXX) echo "Getting the bundle file" -if ! curl -L ${CDNBUNDLE} -o ${BUNDLELOCAL}; then +curl -L "${CDNBUNDLE}" -o "${BUNDLELOCAL}" || { echo "Getting the clone bundle failed." # clean up to not litter huge files around - rm -f ${BUNDLELOCAL} + rm -f "${BUNDLELOCAL}" exit 1 -fi +} echo "Cloning from the bundle file" -if ! git clone ${BUNDLELOCAL} ${TARGET}; then +git clone "${BUNDLELOCAL}" "${TARGET}" || { echo "Cloning from bundle failed." echo "The bundle is in ${BUNDLELOCAL}" exit 1 -fi +} # We're done with the bundle now -rm -f ${BUNDLELOCAL} +rm -f "${BUNDLELOCAL}" -cd ${TARGET} +cd "${TARGET}" echo "Fetching latest objects" -git remote remove origin -git remote add origin ${REMOTE} +git remote set-url origin "${REMOTE}" git remote update origin -git checkout ${CHECKOUT} +git checkout "${CHECKOUT}" |