fix some print message

fix some print message

#!/usr/bin/env bash

# bsroot.sh creates the $PWD/bsroot directory, which is supposed to be
# scp-ed to the bootstrapper server as /bsroot.

if [[ "$#" -lt 1 || "$#" -gt 2 ]]; then
    echo "Usage: bsroot.sh <cluster-desc.yml> [\$SEXTANT_DIR/bsroot]"
    exit 1
fi

# Remember fullpaths, so that it is not required to run bsroot.sh from its local Git repo.
realpath() {
    [[ $1 = /* ]] && echo "$1" || echo "$PWD/${1#./}"
}

SEXTANT_DIR=$(dirname $(realpath $0))
CLOUD_CONFIG_TEMPLATE=$SEXTANT_DIR/cloud-config-server/template/cloud-config.template
INSTALL_CEPH_SCRIPT_DIR=$SEXTANT_DIR/install-ceph
CLUSTER_DESC=$(realpath $1)

# Check sextant dir
if [[ "$SEXTANT_DIR" != "$GOPATH/src/github.com/k8sp/sextant" ]]; then
    echo "\$SEXTANT_DIR=$SEXTANT_DIR differs from $GOPATH/src/github.com/k8sp/sextant."
    echo "Please set GOPATH environment variable and use 'go get' to retrieve sextant."
    exit 1
fi

if [[ "$#" == 2 ]]; then
    BSROOT=$2
else
    BSROOT=$SEXTANT_DIR/bsroot
fi

if [[ -d $BSROOT ]]; then
    echo "$BSROOT already exists. Overwrite without removing it."
else
    mkdir -p $BSROOT
fi

BS_IP=`grep "bootstrapper:" $CLUSTER_DESC | awk '{print $2}' | sed 's/ //g'`
if [[ "$?" -ne 0 ||  "$BS_IP" == "" ]]; then
    echo "Failed parsing cluster-desc file $CLUSTER_DESC for bootstrapper IP".
    exit 1
fi
echo "Using bootstrapper server IP $BS_IP"

KUBE_MASTER_HOSTNAME=`head -n $(grep -n 'kube_master\s*:\s*y' $CLUSTER_DESC | cut -d: -f1) $CLUSTER_DESC | grep mac: | tail | grep -o '..:..:..:..:..:..' | tr ':' '-'`
if [[ "$?" -ne 0 || "$KUBE_MASTER_HOSTNAME" == "" ]]; then
  echo "The cluster-desc file should container kube-master node."
  exit 1
fi

HYPERKUBE_VERSION=`grep "hyperkube:" $CLUSTER_DESC | grep -o '".*hyperkube.*:.*"' | sed 's/".*://; s/"//'`

source $SEXTANT_DIR/bsroot_lib.bash

check_prerequisites() {
    printf "Checking prerequisites ... "
    err=0
    for tool in wget tar gpg docker tr go make; do
        command -v $tool >/dev/null 2>&1 || { echo "Install $tool before run this script"; err=1; }
    done
    if [[ $err -ne 0 ]]; then
        exit 1
    fi
    echo "Done"
}

download_pxe_images() {
    mkdir -p $BSROOT/tftpboot

    printf "Downloading syslinux ... "
    wget --quiet -c -P $BSROOT/tftpboot https://www.kernel.org/pub/linux/utils/boot/syslinux/syslinux-6.03.tar.gz || { echo "Failed"; exit 1; }
    cd $BSROOT/tftpboot
    tar xzf syslinux-6.03.tar.gz || { echo "Failed"; exit 1; }
    cp syslinux-6.03/bios/core/pxelinux.0 $BSROOT/tftpboot || { echo "Failed"; exit 1; }
    cp syslinux-6.03/bios/com32/menu/vesamenu.c32 $BSROOT/tftpboot || { echo "Failed"; exit 1; }
    cp syslinux-6.03/bios/com32/elflink/ldlinux/ldlinux.c32 $BSROOT/tftpboot || { echo "Failed"; exit 1; }
    rm -rf syslinux-6.03 || { echo "Failed"; exit 1; } # Clean the untarred.
    echo "Done"

    printf "Importing CoreOS signing key ... "
    wget --quiet -c -P $BSROOT/tftpboot https://coreos.com/security/image-signing-key/CoreOS_Image_Signing_Key.asc || { echo "Failed"; exit 1; }
    gpg --import --keyid-format LONG $BSROOT/tftpboot/CoreOS_Image_Signing_Key.asc > /dev/null 2>&1 || { echo "Failed"; exit 1; }
    echo "Done"

    printf "Downloading CoreOS PXE vmlinuz image ... "
    wget --quiet -c -P $BSROOT/tftpboot https://stable.release.core-os.net/amd64-usr/current/coreos_production_pxe.vmlinuz || { echo "Failed"; exit 1; }
    wget --quiet -c -P $BSROOT/tftpboot https://stable.release.core-os.net/amd64-usr/current/coreos_production_pxe.vmlinuz.sig || { echo "Failed"; exit 1; }
    cd $BSROOT/tftpboot
    gpg --verify coreos_production_pxe.vmlinuz.sig > /dev/null 2>&1 || { echo "Failed"; exit 1; }
    echo "Done"

    printf "Downloading CoreOS PXE CPIO image ... "
    wget --quiet -c -P $BSROOT/tftpboot https://stable.release.core-os.net/amd64-usr/current/coreos_production_pxe_image.cpio.gz || { echo "Failed"; exit 1; }
    wget --quiet -c -P $BSROOT/tftpboot https://stable.release.core-os.net/amd64-usr/current/coreos_production_pxe_image.cpio.gz.sig || { echo "Failed"; exit 1; }
    gpg --verify coreos_production_pxe_image.cpio.gz.sig > /dev/null 2>&1 || { echo "Failed"; exit 1; }
    echo "Done"
}

generate_pxe_config() {
    printf "Generating pxelinux.cfg ... "
    mkdir -p $BSROOT/tftpboot/pxelinux.cfg
    cat > $BSROOT/tftpboot/pxelinux.cfg/default <<EOF
default coreos

label coreos
  kernel coreos_production_pxe.vmlinuz
  append initrd=coreos_production_pxe_image.cpio.gz cloud-config-url=http://$BS_IP/static/cloud-config/install.sh coreos.autologin
EOF
    echo "Done"
}

generate_registry_config() {
    printf "Generating Docker registry config file ... "
    mkdir -p $BSROOT/registry_data
    [ ! -d $BSROOT/config ] && mkdir -p $BSROOT/config
    cat > $BSROOT/config/registry.yml <<EOF
version: 0.1
log:
  fields:
    service: registry
storage:
  cache:
    blobdescriptor: inmemory
  filesystem:
    rootdirectory: /bsroot/registry_data
http:
  addr: :5000
  headers:
    X-Content-Type-Options: [nosniff]
  tls:
    certificate: /bsroot/tls/bootstrapper.crt
    key: /bsroot/tls/bootstrapper.key
health:
  storagedriver:
    enabled: true
    interval: 10s
    threshold: 3
EOF
    echo "Done"
}

prepare_cc_server_contents() {
    mkdir -p $BSROOT/html/static/ceph
    cp $INSTALL_CEPH_SCRIPT_DIR/install-mon.sh $BSROOT/html/static/ceph/install-mon.sh
    cp $INSTALL_CEPH_SCRIPT_DIR/install-osd.sh $BSROOT/html/static/ceph/install-osd.sh

    mkdir -p $BSROOT/html/static/cloud-config

    # Fetch release binary tarball from github accroding to the versions
    # defined in "cluster-desc.yml"
    hyperkube_version=`grep "hyperkube:" $CLUSTER_DESC | grep -o '".*hyperkube.*:.*"' | sed 's/".*://; s/"//'`
    printf "Downloading and kubelet and kubectl of release ${hyperkube_version} ... "
    wget --quiet -c -O $BSROOT/html/static/kubelet https://storage.googleapis.com/kubernetes-release/release/$hyperkube_version/bin/linux/amd64/kubelet
    chmod +x $BSROOT/html/static/kubelet
    echo "Done"

    # setup-network-environment will fetch the default system IP infomation
    # when using cloud-config file to initiate a kubernetes cluster node
    printf "Downloading setup-network-environment file ... "
    wget --quiet -c -O $BSROOT/html/static/setup-network-environment-1.0.1 https://github.com/kelseyhightower/setup-network-environment/releases/download/1.0.1/setup-network-environment || { echo "Failed"; exit 1; }
    echo "Done"

    printf "Copying cloud-config template and cluster-desc.yml ... "
    cp $CLOUD_CONFIG_TEMPLATE $BSROOT/config/ || { echo "Failed"; exit 1; }
    cp $CLUSTER_DESC $BSROOT/config/cluster-desc.yml || { echo "Failed"; exit 1; }
    echo "Done"

    printf "Copying bsroot_lib.bash ... "
    cp $SEXTANT_DIR/bsroot_lib.bash $BSROOT/ || { echo "Failed"; exit 1; }
    echo "Done"

    printf "Generating install.sh ... "
    cat > $BSROOT/html/static/cloud-config/install.sh <<EOF
#!/bin/bash
#Obtain devices
devices=\$(lsblk -l |awk '\$6=="disk"{print \$1}')
# Zap all devices
# NOTICE: dd zero to device mbr will not affect parted printed table,
#         so use parted to remove the part tables
for d in \$devices
do
  for v_partition in \$(parted -s /dev/\${d} print|awk '/^ / {print \$1}')
  do
     parted -s /dev/\${d} rm \${v_partition}
  done
done

# FIXME: default to install coreos on /dev/sda
default_iface=\$(awk '\$2 == 00000000 { print \$1  }' /proc/net/route | uniq)

printf "Default interface: \${default_iface}\n"
default_iface=\`echo \${default_iface} | awk '{ print \$1 }'\`

mac_addr=\`ip addr show dev \${default_iface} | awk '\$1 ~ /^link\// { print \$2 }'\`
printf "Interface: \${default_iface} MAC address: \${mac_addr}\n"

wget -O \${mac_addr}.yml http://$BS_IP/cloud-config/\${mac_addr}
sudo coreos-install -d /dev/sda -c \${mac_addr}.yml -b http://$BS_IP/static -V current && sudo reboot
EOF
    echo "Done"

    printf "Checking new CoreOS version ... "
    VERSION=$(curl -s https://stable.release.core-os.net/amd64-usr/current/version.txt | grep 'COREOS_VERSION=' | cut -f 2 -d '=')
    if [[ $VERSION == "" ]]; then
        echo "Failed"; exit 1;
    fi
    echo "Done"

    printf "Updating CoreOS images ... "
    if [[ ! -d $BSROOT/html/static/$VERSION ]]; then
        mkdir -p $BSROOT/html/static/$VERSION
    fi

    wget --quiet -c -P $BSROOT/html/static/$VERSION https://stable.release.core-os.net/amd64-usr/current/version.txt
    wget --quiet -c -P $BSROOT/html/static/$VERSION https://stable.release.core-os.net/amd64-usr/current/coreos_production_image.bin.bz2 || { echo "Failed"; exit 1; }
    wget --quiet -c -P $BSROOT/html/static/$VERSION https://stable.release.core-os.net/amd64-usr/current/coreos_production_image.bin.bz2.sig || { echo "Failed"; exit 1; }
    cd $BSROOT/html/static/$VERSION
    gpg --verify coreos_production_image.bin.bz2.sig > /dev/null 2>&1 || { echo "Failed"; exit 1; }
    cd $BSROOT/html/static
    ln -sf ./$VERSION current || { echo "Failed"; exit 1; }
    echo "Done"
}

build_bootstrapper_image() {

    local THIS_OS=$(go env | grep 'GOOS=' | cut -f 2 -d '=')
    local THIS_ARCH=$(go env | grep 'GOARCH=' | cut -f 2 -d '=')

    printf "Cross-compiling Sextant Go programs ... "
    rm -f $SEXTANT_DIR/docker/cloud-config-server >/dev/null 2>&1
    # CGO_ENABLED=0 builds fully statically-linked
    # programs. https://github.com/wangkuiyi/build-statically-linked-go-programs.
    CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go install \
               github.com/k8sp/sextant/cloud-config-server \
        || { echo "Failed"; exit 1; }
    echo "Done"

    if [[ $THIS_OS != '"linux"' || $THIS_ARCH != '"amd64"' ]]; then
        cp $GOPATH/bin/linux_amd64/cloud-config-server $SEXTANT_DIR/docker
    else
        cp $GOPATH/bin/cloud-config-server $SEXTANT_DIR/docker
    fi

    printf "Cross-compiling Docker registry ... "
    rm -f $SEXTANT_DIR/docker/registry >/dev/null 2>&1
    go get -u -d github.com/docker/distribution/cmd/registry \
        && cd $GOPATH/src/github.com/docker/distribution \
        && make CGO_ENABLED=0 GOOS=linux GOARCH=amd64 PREFIX=$GOPATH clean $GOPATH/bin/registry >/dev/null 2>&1\
        || { echo "Failed"; exit 1; }
    echo "Done"

    cp $GOPATH/bin/registry $SEXTANT_DIR/docker

    printf "Building bootstrapper image ... "
    cd $SEXTANT_DIR/docker
    docker build -t bootstrapper . > /dev/null 2>&1 || { echo "Failed"; exit 1; }
    docker save bootstrapper:latest > $BSROOT/bootstrapper.tar || { echo "Failed"; exit 1; }
    # NOTE: we need to run docker load on the bootstrapper server
    # to load these saved images.
    echo "Done"

    cp $SEXTANT_DIR/start_bootstrapper_container.sh \
       $BSROOT/start_bootstrapper_container.sh 2>&1 || { echo "Failed"; exit 1; }
    chmod +x $BSROOT/start_bootstrapper_container.sh
}

download_k8s_images() {
    for DOCKER_IMAGE in $(set | grep '^cluster_desc_images_' | grep -o '".*"' | sed 's/"//g'); do
        # NOTE: if we updated remote image but didn't update its tag,
        # the following lines wouldn't pull because there is a local
        # image with the same tag.
        if ! docker images --format '{{.Repository}}:{{.Tag}}' | grep $DOCKER_IMAGE > /dev/null; then
            printf "Pulling image ${DOCKER_IMAGE} ... "
            docker pull $DOCKER_IMAGE > /dev/null 2>&1 || { echo "Failed"; exit 1; }
            echo "Done"
        fi

        local DOCKER_TAR_FILE=$BSROOT/`echo $DOCKER_IMAGE.tar | sed "s/:/_/g" |awk -F'/' '{print $2}'`
        if [[ ! -f $DOCKER_TAR_FILE ]]; then
            printf "Exporting $DOCKER_TAR_FILE ... "
            docker save $DOCKER_IMAGE > $DOCKER_TAR_FILE.progress || { echo "Failed"; exit 1; }
            mv $DOCKER_TAR_FILE.progress $DOCKER_TAR_FILE
            echo "Done"
        fi
    done
}

generate_tls_assets() {
    mkdir -p $BSROOT/tls
    cd $BSROOT/tls
    rm -rf $BSROOT/tls/*

    printf "Generating CA TLS assets ... "
    openssl genrsa -out ca-key.pem 2048 > /dev/null 2>&1 || { echo "Failed"; exit 1; }
    openssl req -x509 -new -nodes -key ca-key.pem -days 10000 -out ca.pem -subj "/CN=kube-ca"  > /dev/null 2>&1 || { echo "Failed"; exit 1; }
    echo "Done"

    printf "Generating bootstrapper TLS assets ... "
    openssl genrsa -out bootstrapper.key 2048 > /dev/null 2>&1 || { echo "Failed"; exit 1; }
    openssl req -new -key bootstrapper.key -out bootstrapper.csr -subj "/CN=bootstrapper" > /dev/null 2>&1 || { echo "Failed"; exit 1; }
    openssl x509 -req -in bootstrapper.csr -CA ca.pem -CAkey ca-key.pem -CAcreateserial -out bootstrapper.crt -days 365 > /dev/null 2>&1 || { echo "Failed"; exit 1; }
    echo "Done"
}

prepare_setup_kubectl() {
  printf "Preparing setup kubectl ... "
  sed "s/<KUBE_MASTER_HOSTNAME>/$KUBE_MASTER_HOSTNAME/g" $SEXTANT_DIR/setup-kubectl.bash | \
    sed "s/<HYPERKUBE_VERSION>/$HYPERKUBE_VERSION/g" \
    > $BSROOT/setup_kubectl.bash 2>&1 || { echo "Prepare setup kubectl failed."; exit 1; }
  chmod +x $BSROOT/setup_kubectl.bash
  echo "Done"
}

generate_addons_config() {
    printf "Building addons..."
    rm $GOPATH/bin/addons >/dev/null 2>&1
    go install github.com/k8sp/sextant/addons || { echo "Failed"; exit 1; }
    echo "Done"
    printf "Generating configuration files ..."
    $GOPATH/bin/addons -cluster-desc-file $CLUSTER_DESC \
        -template-file $SEXTANT_DIR/addons/template/ingress.template \
        -config-file $BSROOT/html/static/ingress.yaml || \
        { echo 'Failed to generate ingress.yaml !' ; exit 1; }

    $GOPATH/bin/addons -cluster-desc-file $CLUSTER_DESC \
        -template-file $SEXTANT_DIR/addons/template/skydns.template \
        -config-file $BSROOT/html/static/skydns.yaml || \
        { echo 'Failed to generate skydns.yaml !' ; exit 1; }

    $GOPATH/bin/addons -cluster-desc-file $CLUSTER_DESC \
        -template-file $SEXTANT_DIR/addons/template/skydns-service.template \
        -config-file $BSROOT/html/static/skydns-service.yaml || \
        { echo 'Failed to generate skydns-service.yaml !' ; exit 1; }

    $GOPATH/bin/addons -cluster-desc-file $CLUSTER_DESC \
        -template-file $SEXTANT_DIR/addons/template/dnsmasq.conf.template \
        -config-file $BSROOT/config/dnsmasq.conf || \
        { echo 'Failed to generate dnsmasq.conf !' ; exit 1; }

    echo "Done"
}

check_prerequisites
load_yaml $CLUSTER_DESC cluster_desc_
download_pxe_images
generate_pxe_config
generate_registry_config
prepare_cc_server_contents
download_k8s_images
build_bootstrapper_image
generate_tls_assets
prepare_setup_kubectl
generate_addons_config

#!/usr/bin/env bash

# bsroot.sh creates the $PWD/bsroot directory, which is supposed to be
# scp-ed to the bootstrapper server as /bsroot.

if [[ "$#" -lt 1 || "$#" -gt 2 ]]; then
    echo "Usage: bsroot.sh <cluster-desc.yml> [\$SEXTANT_DIR/bsroot]"
    exit 1
fi

# Remember fullpaths, so that it is not required to run bsroot.sh from its local Git repo.
realpath() {
    [[ $1 = /* ]] && echo "$1" || echo "$PWD/${1#./}"
}

SEXTANT_DIR=$(dirname $(realpath $0))
CLOUD_CONFIG_TEMPLATE=$SEXTANT_DIR/cloud-config-server/template/cloud-config.template
INSTALL_CEPH_SCRIPT_DIR=$SEXTANT_DIR/install-ceph
CLUSTER_DESC=$(realpath $1)

# Check sextant dir
if [[ "$SEXTANT_DIR" != "$GOPATH/src/github.com/k8sp/sextant" ]]; then
    echo "\$SEXTANT_DIR=$SEXTANT_DIR differs from $GOPATH/src/github.com/k8sp/sextant."
    echo "Please set GOPATH environment variable and use 'go get' to retrieve sextant."
    exit 1
fi

if [[ "$#" == 2 ]]; then
    BSROOT=$2
else
    BSROOT=$SEXTANT_DIR/bsroot
fi

if [[ -d $BSROOT ]]; then
    echo "$BSROOT already exists. Overwrite without removing it."
else
    mkdir -p $BSROOT
fi

BS_IP=`grep "bootstrapper:" $CLUSTER_DESC | awk '{print $2}' | sed 's/ //g'`
if [[ "$?" -ne 0 ||  "$BS_IP" == "" ]]; then
    echo "Failed parsing cluster-desc file $CLUSTER_DESC for bootstrapper IP".
    exit 1
fi
echo "Using bootstrapper server IP $BS_IP"

KUBE_MASTER_HOSTNAME=`head -n $(grep -n 'kube_master\s*:\s*y' $CLUSTER_DESC | cut -d: -f1) $CLUSTER_DESC | grep mac: | tail | grep -o '..:..:..:..:..:..' | tr ':' '-'`
if [[ "$?" -ne 0 || "$KUBE_MASTER_HOSTNAME" == "" ]]; then
  echo "The cluster-desc file should container kube-master node."
  exit 1
fi

HYPERKUBE_VERSION=`grep "hyperkube:" $CLUSTER_DESC | grep -o '".*hyperkube.*:.*"' | sed 's/".*://; s/"//'`

source $SEXTANT_DIR/bsroot_lib.bash

check_prerequisites() {
    printf "Checking prerequisites ... "
    err=0
    for tool in wget tar gpg docker tr go make; do
        command -v $tool >/dev/null 2>&1 || { echo "Install $tool before run this script"; err=1; }
    done
    if [[ $err -ne 0 ]]; then
        exit 1
    fi
    echo "Done"
}

download_pxe_images() {
    mkdir -p $BSROOT/tftpboot

    printf "Downloading syslinux ... "
    wget --quiet -c -P $BSROOT/tftpboot https://www.kernel.org/pub/linux/utils/boot/syslinux/syslinux-6.03.tar.gz || { echo "Failed"; exit 1; }
    cd $BSROOT/tftpboot
    tar xzf syslinux-6.03.tar.gz || { echo "Failed"; exit 1; }
    cp syslinux-6.03/bios/core/pxelinux.0 $BSROOT/tftpboot || { echo "Failed"; exit 1; }
    cp syslinux-6.03/bios/com32/menu/vesamenu.c32 $BSROOT/tftpboot || { echo "Failed"; exit 1; }
    cp syslinux-6.03/bios/com32/elflink/ldlinux/ldlinux.c32 $BSROOT/tftpboot || { echo "Failed"; exit 1; }
    rm -rf syslinux-6.03 || { echo "Failed"; exit 1; } # Clean the untarred.
    echo "Done"

    printf "Importing CoreOS signing key ... "
    wget --quiet -c -P $BSROOT/tftpboot https://coreos.com/security/image-signing-key/CoreOS_Image_Signing_Key.asc || { echo "Failed"; exit 1; }
    gpg --import --keyid-format LONG $BSROOT/tftpboot/CoreOS_Image_Signing_Key.asc > /dev/null 2>&1 || { echo "Failed"; exit 1; }
    echo "Done"

    printf "Downloading CoreOS PXE vmlinuz image ... "
    wget --quiet -c -P $BSROOT/tftpboot https://stable.release.core-os.net/amd64-usr/current/coreos_production_pxe.vmlinuz || { echo "Failed"; exit 1; }
    wget --quiet -c -P $BSROOT/tftpboot https://stable.release.core-os.net/amd64-usr/current/coreos_production_pxe.vmlinuz.sig || { echo "Failed"; exit 1; }
    cd $BSROOT/tftpboot
    gpg --verify coreos_production_pxe.vmlinuz.sig > /dev/null 2>&1 || { echo "Failed"; exit 1; }
    echo "Done"

    printf "Downloading CoreOS PXE CPIO image ... "
    wget --quiet -c -P $BSROOT/tftpboot https://stable.release.core-os.net/amd64-usr/current/coreos_production_pxe_image.cpio.gz || { echo "Failed"; exit 1; }
    wget --quiet -c -P $BSROOT/tftpboot https://stable.release.core-os.net/amd64-usr/current/coreos_production_pxe_image.cpio.gz.sig || { echo "Failed"; exit 1; }
    gpg --verify coreos_production_pxe_image.cpio.gz.sig > /dev/null 2>&1 || { echo "Failed"; exit 1; }
    echo "Done"
}

generate_pxe_config() {
    printf "Generating pxelinux.cfg ... "
    mkdir -p $BSROOT/tftpboot/pxelinux.cfg
    cat > $BSROOT/tftpboot/pxelinux.cfg/default <<EOF
default coreos

label coreos
  kernel coreos_production_pxe.vmlinuz
  append initrd=coreos_production_pxe_image.cpio.gz cloud-config-url=http://$BS_IP/static/cloud-config/install.sh coreos.autologin
EOF
    echo "Done"
}

generate_registry_config() {
    printf "Generating Docker registry config file ... "
    mkdir -p $BSROOT/registry_data
    [ ! -d $BSROOT/config ] && mkdir -p $BSROOT/config
    cat > $BSROOT/config/registry.yml <<EOF
version: 0.1
log:
  fields:
    service: registry
storage:
  cache:
    blobdescriptor: inmemory
  filesystem:
    rootdirectory: /bsroot/registry_data
http:
  addr: :5000
  headers:
    X-Content-Type-Options: [nosniff]
  tls:
    certificate: /bsroot/tls/bootstrapper.crt
    key: /bsroot/tls/bootstrapper.key
health:
  storagedriver:
    enabled: true
    interval: 10s
    threshold: 3
EOF
    echo "Done"
}

prepare_cc_server_contents() {
    mkdir -p $BSROOT/html/static/ceph
    cp $INSTALL_CEPH_SCRIPT_DIR/install-mon.sh $BSROOT/html/static/ceph/install-mon.sh
    cp $INSTALL_CEPH_SCRIPT_DIR/install-osd.sh $BSROOT/html/static/ceph/install-osd.sh

    mkdir -p $BSROOT/html/static/cloud-config

    # Fetch release binary tarball from github accroding to the versions
    # defined in "cluster-desc.yml"
    hyperkube_version=`grep "hyperkube:" $CLUSTER_DESC | grep -o '".*hyperkube.*:.*"' | sed 's/".*://; s/"//'`
    printf "Downloading and kubelet and kubectl of release ${hyperkube_version} ... "
    wget --quiet -c -O $BSROOT/html/static/kubelet https://storage.googleapis.com/kubernetes-release/release/$hyperkube_version/bin/linux/amd64/kubelet
    chmod +x $BSROOT/html/static/kubelet
    echo "Done"

    # setup-network-environment will fetch the default system IP infomation
    # when using cloud-config file to initiate a kubernetes cluster node
    printf "Downloading setup-network-environment file ... "
    wget --quiet -c -O $BSROOT/html/static/setup-network-environment-1.0.1 https://github.com/kelseyhightower/setup-network-environment/releases/download/1.0.1/setup-network-environment || { echo "Failed"; exit 1; }
    echo "Done"

    printf "Copying cloud-config template and cluster-desc.yml ... "
    cp $CLOUD_CONFIG_TEMPLATE $BSROOT/config/ || { echo "Failed"; exit 1; }
    cp $CLUSTER_DESC $BSROOT/config/cluster-desc.yml || { echo "Failed"; exit 1; }
    echo "Done"

    printf "Copying bsroot_lib.bash ... "
    cp $SEXTANT_DIR/bsroot_lib.bash $BSROOT/ || { echo "Failed"; exit 1; }
    echo "Done"

    #printf "Copying addon templates ... "
    #cp $SEXTANT_DIR/addons/template/ingress.template $BSROOT/config/ingress.template || { echo "Failed"; exit 1; }
    #cp $SEXTANT_DIR/addons/template/skydns.template $BSROOT/config/skydns.template || { echo "Failed"; exit 1; }
    #cp $SEXTANT_DIR/addons/template/skydns-service.template $BSROOT/config/skydns-service.template || { echo "Failed"; exit 1; }
    #cp $SEXTANT_DIR/addons/template/dnsmasq.conf.template $BSROOT/config/dnsmasq.conf.template || { echo "Failed"; exit 1; }
    #echo "Done"

    printf "Generating install.sh ... "
    cat > $BSROOT/html/static/cloud-config/install.sh <<EOF
#!/bin/bash
#Obtain devices
devices=\$(lsblk -l |awk '\$6=="disk"{print \$1}')
# Zap all devices
# NOTICE: dd zero to device mbr will not affect parted printed table,
#         so use parted to remove the part tables
for d in \$devices
do
  for v_partition in \$(parted -s /dev/\${d} print|awk '/^ / {print \$1}')
  do
     parted -s /dev/\${d} rm \${v_partition}
  done
done

# FIXME: default to install coreos on /dev/sda
default_iface=\$(awk '\$2 == 00000000 { print \$1  }' /proc/net/route | uniq)

printf "Default interface: \${default_iface}\n"
default_iface=\`echo \${default_iface} | awk '{ print \$1 }'\`

mac_addr=\`ip addr show dev \${default_iface} | awk '\$1 ~ /^link\// { print \$2 }'\`
printf "Interface: \${default_iface} MAC address: \${mac_addr}\n"

wget -O \${mac_addr}.yml http://$BS_IP/cloud-config/\${mac_addr}
sudo coreos-install -d /dev/sda -c \${mac_addr}.yml -b http://$BS_IP/static -V current && sudo reboot
EOF
    echo "Done"

    printf "Checking new CoreOS version ... "
    VERSION=$(curl -s https://stable.release.core-os.net/amd64-usr/current/version.txt | grep 'COREOS_VERSION=' | cut -f 2 -d '=')
    if [[ $VERSION == "" ]]; then
        echo "Failed"; exit 1;
    fi
    echo "Done"

    printf "Updating CoreOS images ... "
    if [[ ! -d $BSROOT/html/static/$VERSION ]]; then
        mkdir -p $BSROOT/html/static/$VERSION
    fi

    wget --quiet -c -P $BSROOT/html/static/$VERSION https://stable.release.core-os.net/amd64-usr/current/version.txt
    wget --quiet -c -P $BSROOT/html/static/$VERSION https://stable.release.core-os.net/amd64-usr/current/coreos_production_image.bin.bz2 || { echo "Failed"; exit 1; }
    wget --quiet -c -P $BSROOT/html/static/$VERSION https://stable.release.core-os.net/amd64-usr/current/coreos_production_image.bin.bz2.sig || { echo "Failed"; exit 1; }
    cd $BSROOT/html/static/$VERSION
    gpg --verify coreos_production_image.bin.bz2.sig > /dev/null 2>&1 || { echo "Failed"; exit 1; }
    cd $BSROOT/html/static
    ln -sf ./$VERSION current || { echo "Failed"; exit 1; }
    echo "Done"
}

build_bootstrapper_image() {

    local THIS_OS=$(go env | grep 'GOOS=' | cut -f 2 -d '=')
    local THIS_ARCH=$(go env | grep 'GOARCH=' | cut -f 2 -d '=')

    printf "Cross-compiling Sextant Go programs ... "
    rm -f $SEXTANT_DIR/docker/cloud-config-server >/dev/null 2>&1
    # CGO_ENABLED=0 builds fully statically-linked
    # programs. https://github.com/wangkuiyi/build-statically-linked-go-programs.
    CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go install \
               github.com/k8sp/sextant/cloud-config-server \
        || { echo "Failed"; exit 1; }
    echo "Done"

    if [[ $THIS_OS != '"linux"' || $THIS_ARCH != '"amd64"' ]]; then
        cp $GOPATH/bin/linux_amd64/cloud-config-server $SEXTANT_DIR/docker
    else
        cp $GOPATH/bin/cloud-config-server $SEXTANT_DIR/docker
    fi

    printf "Cross-compiling Docker registry ... "
    rm -f $SEXTANT_DIR/docker/registry >/dev/null 2>&1
    go get -u -d github.com/docker/distribution/cmd/registry \
        && cd $GOPATH/src/github.com/docker/distribution \
        && make CGO_ENABLED=0 GOOS=linux GOARCH=amd64 PREFIX=$GOPATH clean $GOPATH/bin/registry >/dev/null 2>&1\
        || { echo "Failed"; exit 1; }
    echo "Done"

    cp $GOPATH/bin/registry $SEXTANT_DIR/docker

    printf "Building bootstrapper image ... "
    cd $SEXTANT_DIR/docker
    docker build -t bootstrapper . > /dev/null 2>&1 || { echo "Failed"; exit 1; }
    docker save bootstrapper:latest > $BSROOT/bootstrapper.tar || { echo "Failed"; exit 1; }
    # NOTE: we need to run docker load on the bootstrapper server
    # to load these saved images.
    echo "Done"

    cp $SEXTANT_DIR/start_bootstrapper_container.sh \
       $BSROOT/start_bootstrapper_container.sh 2>&1 || { echo "Failed"; exit 1; }
    chmod +x $BSROOT/start_bootstrapper_container.sh
}

download_k8s_images() {
    for DOCKER_IMAGE in $(set | grep '^cluster_desc_images_' | grep -o '".*"' | sed 's/"//g'); do
        # NOTE: if we updated remote image but didn't update its tag,
        # the following lines wouldn't pull because there is a local
        # image with the same tag.
        if ! docker images --format '{{.Repository}}:{{.Tag}}' | grep $DOCKER_IMAGE > /dev/null; then
            printf "Pulling image ${DOCKER_IMAGE} ... "
            docker pull $DOCKER_IMAGE > /dev/null 2>&1 || { echo "Failed"; exit 1; }
            echo "Done"
        fi

        local DOCKER_TAR_FILE=$BSROOT/`echo $DOCKER_IMAGE.tar | sed "s/:/_/g" |awk -F'/' '{print $2}'`
        if [[ ! -f $DOCKER_TAR_FILE ]]; then
            printf "Exporting $DOCKER_TAR_FILE ... "
            docker save $DOCKER_IMAGE > $DOCKER_TAR_FILE.progress || { echo "Failed"; exit 1; }
            mv $DOCKER_TAR_FILE.progress $DOCKER_TAR_FILE
            echo "Done"
        fi
    done
}

generate_tls_assets() {
    mkdir -p $BSROOT/tls
    cd $BSROOT/tls
    rm -rf $BSROOT/tls/*

    printf "Generating CA TLS assets ... "
    openssl genrsa -out ca-key.pem 2048 > /dev/null 2>&1 || { echo "Failed"; exit 1; }
    openssl req -x509 -new -nodes -key ca-key.pem -days 10000 -out ca.pem -subj "/CN=kube-ca"  > /dev/null 2>&1 || { echo "Failed"; exit 1; }
    echo "Done"

    printf "Generating bootstrapper TLS assets ... "
    openssl genrsa -out bootstrapper.key 2048 > /dev/null 2>&1 || { echo "Failed"; exit 1; }
    openssl req -new -key bootstrapper.key -out bootstrapper.csr -subj "/CN=bootstrapper" > /dev/null 2>&1 || { echo "Failed"; exit 1; }
    openssl x509 -req -in bootstrapper.csr -CA ca.pem -CAkey ca-key.pem -CAcreateserial -out bootstrapper.crt -days 365 > /dev/null 2>&1 || { echo "Failed"; exit 1; }
    echo "Done"
}

prepare_setup_kubectl() {
  printf "Preparing setup kubectl ... "
  sed "s/<KUBE_MASTER_HOSTNAME>/$KUBE_MASTER_HOSTNAME/g" $SEXTANT_DIR/setup-kubectl.bash | \
    sed "s/<HYPERKUBE_VERSION>/$HYPERKUBE_VERSION/g" \
    > $BSROOT/setup_kubectl.bash 2>&1 || { echo "Prepare setup kubectl failed."; exit 1; }
  chmod +x $BSROOT/setup_kubectl.bash
  echo "Done"
}

generate_addons_config() {
    printf "Build addon ..."
    rm $GOPATH/bin/addons >/dev/null 2>&1
    go install github.com/k8sp/sextant/addons || { echo "Failed"; exit 1; }
    echo "Done"
    printf "Generate addons config ..."
    $GOPATH/bin/addons -cluster-desc-file $CLUSTER_DESC \
        -template-file $SEXTANT_DIR/addons/template/ingress.template \
        -config-file $BSROOT/html/static/ingress.yaml || \
        { echo 'gen ingress failed!' ; exit 1; }

    $GOPATH/bin/addons -cluster-desc-file $CLUSTER_DESC \
        -template-file $SEXTANT_DIR/addons/template/skydns.template \
        -config-file $BSROOT/html/static/skydns.yaml || \
        { echo 'gen skydns failed!' ; exit 1; }

    $GOPATH/bin/addons -cluster-desc-file $CLUSTER_DESC \
        -template-file $SEXTANT_DIR/addons/template/skydns-service.template \
        -config-file $BSROOT/html/static/skydns-service.yaml || \
        { echo 'gen skydns-service failed!' ; exit 1; }

    $GOPATH/bin/addons -cluster-desc-file $CLUSTER_DESC \
        -template-file $SEXTANT_DIR/addons/template/dnsmasq.conf.template \
        -config-file $BSROOT/config/dnsmasq.conf || \
        { echo 'gen dnsmasq.conf failed!' ; exit 1; }

    echo "Done"
}

check_prerequisites
load_yaml $CLUSTER_DESC cluster_desc_
download_pxe_images
generate_pxe_config
generate_registry_config
prepare_cc_server_contents
download_k8s_images
build_bootstrapper_image
generate_tls_assets
prepare_setup_kubectl
generate_addons_config


Remove an out-of-date comment

Remove an out-of-date comment

#!/usr/bin/env bash

# bsroot.sh creates the $PWD/bsroot directory, which is supposed to be
# scp-ed to the bootstrapper server as /bsroot.

if [[ "$#" -lt 1 || "$#" -gt 2 ]]; then
    echo "Usage: bsroot.sh <cluster-desc.yml> [\$SEXTANT_DIR/bsroot]"
    exit 1
fi

# Remember fullpaths, so that it is not required to run bsroot.sh from its local Git repo.
realpath() {
    [[ $1 = /* ]] && echo "$1" || echo "$PWD/${1#./}"
}

CLOUD_CONFIG_TEMPLATE=$(realpath $(dirname $0)/cloud-config-server/template/cloud-config.template)
CLUSTER_DESC=$(realpath $1)
INSTALL_CEPH_SCRIPT_DIR=$(realpath $(dirname $0)/install-ceph)
SEXTANT_DIR=$(realpath $(dirname $0))

if [[ "$#" == 2 ]]; then
    BSROOT=$2
else
    BSROOT=$SEXTANT_DIR/bsroot
fi

if [[ -d $BSROOT ]]; then
    echo "$BSROOT already exists.  Overwrite without removing it."
fi

BS_IP=`grep "bootstrapper:" $CLUSTER_DESC | awk '{print $2}' | sed 's/ //g'`
if [[ "$?" -ne 0 ||  "$BS_IP" == "" ]]; then
    echo "Failed parsing cluster-desc file $CLUSTER_DESC for bootstrapper IP".
    exit 1
fi
echo "Using bootstrapper server IP $BS_IP"

KUBE_MASTER_HOSTNAME=`head -n $(grep -n 'kube_master\s*:\s*y' $CLUSTER_DESC | cut -d: -f1) $CLUSTER_DESC | grep mac: | tail | grep -o '..:..:..:..:..:..' | tr ':' '-'`
if [[ "$?" -ne 0 || "$KUBE_MASTER_HOSTNAME" == "" ]]; then
  echo "The cluster-desc file should container kube-master node."
  exit 1
fi

HYPERKUBE_VERSION=`grep "hyperkube:" $CLUSTER_DESC | grep -o '".*hyperkube.*:.*"' | sed 's/".*://; s/"//'`

check_prerequisites() {
    printf "Checking prerequisites ... "
    err=0
    for tool in wget tar gpg docker tr; do
        command -v $tool >/dev/null 2>&1 || { echo "Install $tool before run this script"; err=1; }
    done
    if [[ $err -ne 0 ]]; then
        exit 1
    fi
    echo "Done"
}

download_pxe_images() {
    mkdir -p $BSROOT/tftpboot

    printf "Downloading syslinux ... "
    wget --quiet -c -P $BSROOT/tftpboot https://www.kernel.org/pub/linux/utils/boot/syslinux/syslinux-6.03.tar.gz || { echo "Failed"; exit 1; }
    cd $BSROOT/tftpboot
    tar xzf syslinux-6.03.tar.gz || { echo "Failed"; exit 1; }
    cp syslinux-6.03/bios/core/pxelinux.0 $BSROOT/tftpboot || { echo "Failed"; exit 1; }
    cp syslinux-6.03/bios/com32/menu/vesamenu.c32 $BSROOT/tftpboot || { echo "Failed"; exit 1; }
    cp syslinux-6.03/bios/com32/elflink/ldlinux/ldlinux.c32 $BSROOT/tftpboot || { echo "Failed"; exit 1; }
    rm -rf syslinux-6.03 || { echo "Failed"; exit 1; } # Clean the untarred.
    echo "Done"

    printf "Importing CoreOS signing key ... "
    wget --quiet -c -P $BSROOT/tftpboot https://coreos.com/security/image-signing-key/CoreOS_Image_Signing_Key.asc || { echo "Failed"; exit 1; }
    gpg --import --keyid-format LONG $BSROOT/tftpboot/CoreOS_Image_Signing_Key.asc > /dev/null 2>&1 || { echo "Failed"; exit 1; }
    echo "Done"

    printf "Downloading CoreOS PXE vmlinuz image ... "
    wget --quiet -c -P $BSROOT/tftpboot https://stable.release.core-os.net/amd64-usr/current/coreos_production_pxe.vmlinuz || { echo "Failed"; exit 1; }
    wget --quiet -c -P $BSROOT/tftpboot https://stable.release.core-os.net/amd64-usr/current/coreos_production_pxe.vmlinuz.sig || { echo "Failed"; exit 1; }
    cd $BSROOT/tftpboot
    gpg --verify coreos_production_pxe.vmlinuz.sig > /dev/null 2>&1 || { echo "Failed"; exit 1; }
    echo "Done"

    printf "Downloading CoreOS PXE CPIO image ... "
    wget --quiet -c -P $BSROOT/tftpboot https://stable.release.core-os.net/amd64-usr/current/coreos_production_pxe_image.cpio.gz || { echo "Failed"; exit 1; }
    wget --quiet -c -P $BSROOT/tftpboot https://stable.release.core-os.net/amd64-usr/current/coreos_production_pxe_image.cpio.gz.sig || { echo "Failed"; exit 1; }
    gpg --verify coreos_production_pxe_image.cpio.gz.sig > /dev/null 2>&1 || { echo "Failed"; exit 1; }
    echo "Done"
}

generate_pxe_config() {
    printf "Generating pxelinux.cfg ... "
    mkdir -p $BSROOT/tftpboot/pxelinux.cfg
    cat > $BSROOT/tftpboot/pxelinux.cfg/default <<EOF
default coreos

label coreos
  kernel coreos_production_pxe.vmlinuz
  append initrd=coreos_production_pxe_image.cpio.gz cloud-config-url=http://$BS_IP/static/cloud-config/install.sh coreos.autologin
EOF
    echo "Done"
}

generate_dnsmasq_config() {
    printf "Generating dnsmasq.conf ... "
    mkdir -p $BSROOT/config
    # TODO(yi): Ad-hoc domain name k8s.baifendian.com here.  Try parsing it from cluster-desc.yml.
    # TODO(yi): Ad-hoc DHCP IP range. Try parsing it from cluster-desc.yml.
    cat > $BSROOT/config/dnsmasq.conf <<EOF
  interface=eth0
  bind-interfaces
  domain=k8s.baifendian.com
  user=root
  dhcp-range=192.168.8.102,192.168.8.200,255.255.255.0,12h
  log-dhcp

  dhcp-boot=pxelinux.0

  dhcp-option=3,192.168.8.101

  dhcp-option=6,192.168.8.101,8.8.8.8
  no-hosts
  expand-hosts
  no-resolv

  local=/k8s.baifendian.com/
  domain-needed

  dhcp-option=28,192.168.8.255

  #dhcp-option=42,0.0.0.0
  pxe-prompt="Press F8 for menu.", 5
  pxe-service=x86PC, "Install CoreOS from network server", pxelinux
  enable-tftp
  tftp-root=/bsroot/tftpboot
EOF
    echo "Done"
}

generate_registry_config() {
    printf "Generating Docker registry config file ... "
    mkdir -p $BSROOT/registry_data
    [ ! -d $BSROOT/config ] && mkdir -p $BSROOT/config
    cat > $BSROOT/config/registry.yml <<EOF
version: 0.1
log:
  fields:
    service: registry
storage:
  cache:
    blobdescriptor: inmemory
  filesystem:
    rootdirectory: /bsroot/registry_data
http:
  addr: :5000
  headers:
    X-Content-Type-Options: [nosniff]
  tls:
    certificate: /bsroot/tls/bootstrapper.crt
    key: /bsroot/tls/bootstrapper.key
health:
  storagedriver:
    enabled: true
    interval: 10s
    threshold: 3
EOF
    echo "Done"
}

prepare_cc_server_contents() {
    mkdir -p $BSROOT/html/static/ceph
    cp $INSTALL_CEPH_SCRIPT_DIR/install-mon.sh $BSROOT/html/static/ceph/install-mon.sh
    cp $INSTALL_CEPH_SCRIPT_DIR/install-osd.sh $BSROOT/html/static/ceph/install-osd.sh

    mkdir -p $BSROOT/html/static/cloud-config

    # Fetch release binary tarball from github accroding to the versions
    # defined in "cluster-desc.yml"
    hyperkube_version=`grep "hyperkube:" $CLUSTER_DESC | grep -o '".*hyperkube.*:.*"' | sed 's/".*://; s/"//'`
    printf "Downloading and kubelet and kubectl of release ${hyperkube_version} ... "
    wget --quiet -c -O $BSROOT/html/static/kubelet https://storage.googleapis.com/kubernetes-release/release/$hyperkube_version/bin/linux/amd64/kubelet
    chmod +x $BSROOT/html/static/kubelet
    echo "Done"

    # setup-network-environment will fetch the default system IP infomation
    # when using cloud-config file to initiate a kubernetes cluster node
    printf "Downloading setup-network-environment file ... "
    wget --quiet -c -O $BSROOT/html/static/setup-network-environment-1.0.1 https://github.com/kelseyhightower/setup-network-environment/releases/download/1.0.1/setup-network-environment || { echo "Failed"; exit 1; }
    echo "Done"

    printf "Copying cloud-config template and cluster-desc.yml ... "
    cp $CLOUD_CONFIG_TEMPLATE $BSROOT/config/ || { echo "Failed"; exit 1; }
    cp $CLUSTER_DESC $BSROOT/config/cluster-desc.yml || { echo "Failed"; exit 1; }
    echo "Done"

    printf "Copying addon templates ... "
    cp $SEXTANT_DIR/addons/template/ingress.template $BSROOT/config/ingress.template || { echo "Failed"; exit 1; }
    cp $SEXTANT_DIR/addons/template/skydns.template $BSROOT/config/skydns.template || { echo "Failed"; exit 1; }
    cp $SEXTANT_DIR/addons/template/skydns-service.template $BSROOT/config/skydns-service.template || { echo "Failed"; exit 1; }
    cp $SEXTANT_DIR/addons/template/dnsmasq.conf.template $BSROOT/config/dnsmasq.conf.template || { echo "Failed"; exit 1; }
    echo "Done"

    printf "Generating install.sh ... "
    cat > $BSROOT/html/static/cloud-config/install.sh <<EOF
#!/bin/bash
#Obtain devices
devices=\$(lsblk -l |awk '\$6=="disk"{print \$1}')
# Zap all devices
# NOTICE: dd zero to device mbr will not affect parted printed table,
#         so use parted to remove the part tables
for d in \$devices
do
  for v_partition in \$(parted -s /dev/\${d} print|awk '/^ / {print \$1}')
  do
     parted -s /dev/\${d} rm \${v_partition}
  done
done

# FIXME: default to install coreos on /dev/sda
default_iface=\$(awk '\$2 == 00000000 { print \$1  }' /proc/net/route | uniq)

printf "Default interface: \${default_iface}\n"
default_iface=\`echo \${default_iface} | awk '{ print \$1 }'\`

mac_addr=\`ip addr show dev \${default_iface} | awk '\$1 ~ /^link\// { print \$2 }'\`
printf "Interface: \${default_iface} MAC address: \${mac_addr}\n"

wget -O \${mac_addr}.yml http://$BS_IP/cloud-config/\${mac_addr}
sudo coreos-install -d /dev/sda -c \${mac_addr}.yml -b http://$BS_IP/static -V current && sudo reboot
EOF
    echo "Done"

    printf "Checking new CoreOS version ... "
    VERSION=$(curl -s https://stable.release.core-os.net/amd64-usr/current/version.txt | grep 'COREOS_VERSION=' | cut -f 2 -d '=')
    if [[ $VERSION == "" ]]; then
        echo "Failed"; exit 1;
    fi
    echo "Done"

    printf "Updating CoreOS images ... "
    if [[ ! -d $BSROOT/html/static/$VERSION ]]; then
        mkdir -p $BSROOT/html/static/$VERSION
    fi

    wget --quiet -c -P $BSROOT/html/static/$VERSION https://stable.release.core-os.net/amd64-usr/current/version.txt
    wget --quiet -c -P $BSROOT/html/static/$VERSION https://stable.release.core-os.net/amd64-usr/current/coreos_production_image.bin.bz2 || { echo "Failed"; exit 1; }
    wget --quiet -c -P $BSROOT/html/static/$VERSION https://stable.release.core-os.net/amd64-usr/current/coreos_production_image.bin.bz2.sig || { echo "Failed"; exit 1; }
    cd $BSROOT/html/static/$VERSION
    gpg --verify coreos_production_image.bin.bz2.sig > /dev/null 2>&1 || { echo "Failed"; exit 1; }
    cd $BSROOT/html/static
    ln -sf ./$VERSION current || { echo "Failed"; exit 1; }
    echo "Done"
}

download_k8s_images () {
  DOCKER_IMAGES=("hyperkube" \
    "pause" \
    "flannel" \
    "ingress" \
    "kube2sky" \
    "healthz" \
    "addon_manager" \
    "skydns" \
    "ceph");
  cd $BSROOT
  len=${#DOCKER_IMAGES[@]}
  for ((i=0;i<len;i++)); do
    DOCKER_IMAGE=`grep "${DOCKER_IMAGES[i]}:" $CLUSTER_DESC | awk '{print $2}' | sed 's/ //g' | sed -e 's/^"//' -e 's/"$//'`
    printf "Downloading image ${DOCKER_IMAGE} ..."
    docker pull $DOCKER_IMAGE > /dev/null 2>&1 || { echo "Failed"; exit 1; }
    DOCKER_TAR_FILE=`echo $DOCKER_IMAGE.tar | sed "s/:/_/g" |awk -F'/' '{print $2}'`
    docker save $DOCKER_IMAGE > $DOCKER_TAR_FILE || { echo "Failed"; exit 1; }
    echo "Done"
  done

  printf "Building bootstrapper image ... "
  cd $SEXTANT_DIR/docker
  bash $SEXTANT_DIR/docker/build.bash > /dev/null 2>&1 || { echo "Failed"; exit 1; }
  docker save bootstrapper:latest > $BSROOT/bootstrapper.tar || { echo "Failed"; exit 1; }
  echo "Done"
  # NOTE: we need to run docker load on the bootstrapper server
  # to load these saved images.

  cp $SEXTANT_DIR/start_bootstrapper_container.sh \
    $BSROOT/start_bootstrapper_container.sh 2>&1 || { echo "Failed"; exit 1; }
  chmod +x $BSROOT/start_bootstrapper_container.sh
}

generate_tls_assets() {
    mkdir -p $BSROOT/tls
    cd $BSROOT/tls
    rm -rf $BSROOT/tls/*

    printf "Generating CA TLS assets ... "
    openssl genrsa -out ca-key.pem 2048 > /dev/null 2>&1 || { echo "Failed"; exit 1; }
    openssl req -x509 -new -nodes -key ca-key.pem -days 10000 -out ca.pem -subj "/CN=kube-ca"  > /dev/null 2>&1 || { echo "Failed"; exit 1; }
    echo "Done"

    printf "Generating bootstrapper TLS assets ... "
    openssl genrsa -out bootstrapper.key 2048 > /dev/null 2>&1 || { echo "Failed"; exit 1; }
    openssl req -new -key bootstrapper.key -out bootstrapper.csr -subj "/CN=bootstrapper" > /dev/null 2>&1 || { echo "Failed"; exit 1; }
    openssl x509 -req -in bootstrapper.csr -CA ca.pem -CAkey ca-key.pem -CAcreateserial -out bootstrapper.crt -days 365 > /dev/null 2>&1 || { echo "Failed"; exit 1; }
    echo "Done"
}

prepare_setup_kubectl() {
  printf "Preparing setup kubectl ... "
  sed "s/<KUBE_MASTER_HOSTNAME>/$KUBE_MASTER_HOSTNAME/g" $SEXTANT_DIR/setup-kubectl.bash | \
    sed "s/<HYPERKUBE_VERSION>/$HYPERKUBE_VERSION/g" \
    > $BSROOT/setup_kubectl.bash 2>&1 || { echo "Prepare setup kubectl failed."; exit 1; }
  chmod +x $BSROOT/setup_kubectl.bash
  echo "Done"
}

check_prerequisites
download_pxe_images
generate_pxe_config
generate_dnsmasq_config
generate_registry_config
prepare_cc_server_contents
download_k8s_images
generate_tls_assets
prepare_setup_kubectl

#!/usr/bin/env bash

# bsroot.sh creates the $PWD/bsroot directory, which is supposed to be
# scp-ed to the bootstrapper server as /bsroot.

if [[ "$#" -lt 1 || "$#" -gt 2 ]]; then
    echo "Usage: bsroot.sh <cluster-desc.yml> [\$SEXTANT_DIR/bsroot]"
    exit 1
fi

# Remember fullpaths, so that it is not required to run bsroot.sh from its local Git repo.
realpath() {
    [[ $1 = /* ]] && echo "$1" || echo "$PWD/${1#./}"
}

CLOUD_CONFIG_TEMPLATE=$(realpath $(dirname $0)/cloud-config-server/template/cloud-config.template)
CLUSTER_DESC=$(realpath $1)
INSTALL_CEPH_SCRIPT_DIR=$(realpath $(dirname $0)/install-ceph)
SEXTANT_DIR=$(realpath $(dirname $0))

if [[ "$#" == 2 ]]; then
    BSROOT=$2
else
    BSROOT=$SEXTANT_DIR/bsroot
fi

if [[ -d $BSROOT ]]; then
    echo "$BSROOT already exists.  Overwrite without removing it."
fi

BS_IP=`grep "bootstrapper:" $CLUSTER_DESC | awk '{print $2}' | sed 's/ //g'`
if [[ "$?" -ne 0 ||  "$BS_IP" == "" ]]; then
    echo "Failed parsing cluster-desc file $CLUSTER_DESC for bootstrapper IP".
    exit 1
fi
echo "Using bootstrapper server IP $BS_IP"

KUBE_MASTER_HOSTNAME=`head -n $(grep -n 'kube_master\s*:\s*y' $CLUSTER_DESC | cut -d: -f1) $CLUSTER_DESC | grep mac: | tail | grep -o '..:..:..:..:..:..' | tr ':' '-'`
if [[ "$?" -ne 0 || "$KUBE_MASTER_HOSTNAME" == "" ]]; then
  echo "The cluster-desc file should container kube-master node."
  exit 1
fi

HYPERKUBE_VERSION=`grep "hyperkube:" $CLUSTER_DESC | grep -o '".*hyperkube.*:.*"' | sed 's/".*://; s/"//'`

check_prerequisites() {
    printf "Checking prerequisites ... "
    err=0
    for tool in wget tar gpg docker tr; do
        command -v $tool >/dev/null 2>&1 || { echo "Install $tool before run this script"; err=1; }
    done
    if [[ $err -ne 0 ]]; then
        exit 1
    fi
    echo "Done"
}

download_pxe_images() {
    mkdir -p $BSROOT/tftpboot

    printf "Downloading syslinux ... "
    wget --quiet -c -P $BSROOT/tftpboot https://www.kernel.org/pub/linux/utils/boot/syslinux/syslinux-6.03.tar.gz || { echo "Failed"; exit 1; }
    cd $BSROOT/tftpboot
    tar xzf syslinux-6.03.tar.gz || { echo "Failed"; exit 1; }
    cp syslinux-6.03/bios/core/pxelinux.0 $BSROOT/tftpboot || { echo "Failed"; exit 1; }
    cp syslinux-6.03/bios/com32/menu/vesamenu.c32 $BSROOT/tftpboot || { echo "Failed"; exit 1; }
    cp syslinux-6.03/bios/com32/elflink/ldlinux/ldlinux.c32 $BSROOT/tftpboot || { echo "Failed"; exit 1; }
    rm -rf syslinux-6.03 || { echo "Failed"; exit 1; } # Clean the untarred.
    echo "Done"

    printf "Importing CoreOS signing key ... "
    wget --quiet -c -P $BSROOT/tftpboot https://coreos.com/security/image-signing-key/CoreOS_Image_Signing_Key.asc || { echo "Failed"; exit 1; }
    gpg --import --keyid-format LONG $BSROOT/tftpboot/CoreOS_Image_Signing_Key.asc > /dev/null 2>&1 || { echo "Failed"; exit 1; }
    echo "Done"

    printf "Downloading CoreOS PXE vmlinuz image ... "
    wget --quiet -c -P $BSROOT/tftpboot https://stable.release.core-os.net/amd64-usr/current/coreos_production_pxe.vmlinuz || { echo "Failed"; exit 1; }
    wget --quiet -c -P $BSROOT/tftpboot https://stable.release.core-os.net/amd64-usr/current/coreos_production_pxe.vmlinuz.sig || { echo "Failed"; exit 1; }
    cd $BSROOT/tftpboot
    gpg --verify coreos_production_pxe.vmlinuz.sig > /dev/null 2>&1 || { echo "Failed"; exit 1; }
    echo "Done"

    printf "Downloading CoreOS PXE CPIO image ... "
    wget --quiet -c -P $BSROOT/tftpboot https://stable.release.core-os.net/amd64-usr/current/coreos_production_pxe_image.cpio.gz || { echo "Failed"; exit 1; }
    wget --quiet -c -P $BSROOT/tftpboot https://stable.release.core-os.net/amd64-usr/current/coreos_production_pxe_image.cpio.gz.sig || { echo "Failed"; exit 1; }
    gpg --verify coreos_production_pxe_image.cpio.gz.sig > /dev/null 2>&1 || { echo "Failed"; exit 1; }
    echo "Done"
}

generate_pxe_config() {
    printf "Generating pxelinux.cfg ... "
    mkdir -p $BSROOT/tftpboot/pxelinux.cfg
    cat > $BSROOT/tftpboot/pxelinux.cfg/default <<EOF
default coreos

label coreos
  kernel coreos_production_pxe.vmlinuz
  append initrd=coreos_production_pxe_image.cpio.gz cloud-config-url=http://$BS_IP/static/cloud-config/install.sh coreos.autologin
EOF
    echo "Done"
}

generate_dnsmasq_config() {
    printf "Generating dnsmasq.conf ... "
    mkdir -p $BSROOT/config
    # TODO(yi): Ad-hoc domain name k8s.baifendian.com here.  Try parsing it from cluster-desc.yml.
    # TODO(yi): Ad-hoc DHCP IP range. Try parsing it from cluster-desc.yml.
    cat > $BSROOT/config/dnsmasq.conf <<EOF
  interface=eth0
  bind-interfaces
  domain=k8s.baifendian.com
  user=root
  dhcp-range=192.168.8.102,192.168.8.200,255.255.255.0,12h
  log-dhcp

  dhcp-boot=pxelinux.0

  dhcp-option=3,192.168.8.101

  dhcp-option=6,192.168.8.101,8.8.8.8
  no-hosts
  expand-hosts
  no-resolv

  local=/k8s.baifendian.com/
  domain-needed

  dhcp-option=28,192.168.8.255

  #dhcp-option=42,0.0.0.0
  pxe-prompt="Press F8 for menu.", 5
  pxe-service=x86PC, "Install CoreOS from network server", pxelinux
  enable-tftp
  tftp-root=/bsroot/tftpboot
EOF
    echo "Done"
}

generate_registry_config() {
    printf "Generating Docker registry config file ... "
    mkdir -p $BSROOT/registry_data
    [ ! -d $BSROOT/config ] && mkdir -p $BSROOT/config
    cat > $BSROOT/config/registry.yml <<EOF
version: 0.1
log:
  fields:
    service: registry
storage:
  cache:
    blobdescriptor: inmemory
  filesystem:
    rootdirectory: /bsroot/registry_data
http:
  addr: :5000
  headers:
    X-Content-Type-Options: [nosniff]
  tls:
    certificate: /bsroot/tls/bootstrapper.crt
    key: /bsroot/tls/bootstrapper.key
health:
  storagedriver:
    enabled: true
    interval: 10s
    threshold: 3
EOF
    echo "Done"
}

prepare_cc_server_contents() {
    mkdir -p $BSROOT/html/static/ceph
    cp $INSTALL_CEPH_SCRIPT_DIR/install-mon.sh $BSROOT/html/static/ceph/install-mon.sh
    cp $INSTALL_CEPH_SCRIPT_DIR/install-osd.sh $BSROOT/html/static/ceph/install-osd.sh

    mkdir -p $BSROOT/html/static/cloud-config

    # Fetch release binary tarball from github accroding to the versions
    # defined in "cluster-desc.yml"
    hyperkube_version=`grep "hyperkube:" $CLUSTER_DESC | grep -o '".*hyperkube.*:.*"' | sed 's/".*://; s/"//'`
    printf "Downloading and kubelet and kubectl of release ${hyperkube_version} ... "
    wget --quiet -c -O $BSROOT/html/static/kubelet https://storage.googleapis.com/kubernetes-release/release/$hyperkube_version/bin/linux/amd64/kubelet
    chmod +x $BSROOT/html/static/kubelet
    echo "Done"

    # setup-network-environment will fetch the default system IP infomation
    # when using cloud-config file to initiate a kubernetes cluster node
    printf "Downloading setup-network-environment file ... "
    wget --quiet -c -O $BSROOT/html/static/setup-network-environment-1.0.1 https://github.com/kelseyhightower/setup-network-environment/releases/download/1.0.1/setup-network-environment || { echo "Failed"; exit 1; }
    echo "Done"

    printf "Copying cloud-config template and cluster-desc.yml ... "
    cp $CLOUD_CONFIG_TEMPLATE $BSROOT/config/ || { echo "Failed"; exit 1; }
    cp $CLUSTER_DESC $BSROOT/config/cluster-desc.yml || { echo "Failed"; exit 1; }
    echo "Done"

    printf "Copying addon templates ... "
    cp $SEXTANT_DIR/addons/template/ingress.template $BSROOT/config/ingress.template || { echo "Failed"; exit 1; }
    cp $SEXTANT_DIR/addons/template/skydns.template $BSROOT/config/skydns.template || { echo "Failed"; exit 1; }
    cp $SEXTANT_DIR/addons/template/skydns-service.template $BSROOT/config/skydns-service.template || { echo "Failed"; exit 1; }
    cp $SEXTANT_DIR/addons/template/dnsmasq.conf.template $BSROOT/config/dnsmasq.conf.template || { echo "Failed"; exit 1; }
    echo "Done"

    printf "Generating install.sh ... "
    cat > $BSROOT/html/static/cloud-config/install.sh <<EOF
#!/bin/bash
#Obtain devices
devices=\$(lsblk -l |awk '\$6=="disk"{print \$1}')
# Zap all devices
# NOTICE: dd zero to device mbr will not affect parted printed table,
#         so use parted to remove the part tables
for d in \$devices
do
  for v_partition in \$(parted -s /dev/\${d} print|awk '/^ / {print \$1}')
  do
     parted -s /dev/\${d} rm \${v_partition}
  done
done

# FIXME: default to install coreos on /dev/sda
default_iface=\$(awk '\$2 == 00000000 { print \$1  }' /proc/net/route | uniq)

printf "Default interface: \${default_iface}\n"
default_iface=\`echo \${default_iface} | awk '{ print \$1 }'\`

mac_addr=\`ip addr show dev \${default_iface} | awk '\$1 ~ /^link\// { print \$2 }'\`
printf "Interface: \${default_iface} MAC address: \${mac_addr}\n"

wget -O \${mac_addr}.yml http://$BS_IP/cloud-config/\${mac_addr}
sudo coreos-install -d /dev/sda -c \${mac_addr}.yml -b http://$BS_IP/static -V current && sudo reboot
EOF
    echo "Done"

    printf "Checking new CoreOS version ... "
    VERSION=$(curl -s https://stable.release.core-os.net/amd64-usr/current/version.txt | grep 'COREOS_VERSION=' | cut -f 2 -d '=')
    if [[ $VERSION == "" ]]; then
        echo "Failed"; exit 1;
    fi
    echo "Done"

    printf "Updating CoreOS images ... "
    if [[ ! -d $BSROOT/html/static/$VERSION ]]; then
        mkdir -p $BSROOT/html/static/$VERSION
    fi

    wget --quiet -c -P $BSROOT/html/static/$VERSION https://stable.release.core-os.net/amd64-usr/current/version.txt
    wget --quiet -c -P $BSROOT/html/static/$VERSION https://stable.release.core-os.net/amd64-usr/current/coreos_production_image.bin.bz2 || { echo "Failed"; exit 1; }
    wget --quiet -c -P $BSROOT/html/static/$VERSION https://stable.release.core-os.net/amd64-usr/current/coreos_production_image.bin.bz2.sig || { echo "Failed"; exit 1; }
    cd $BSROOT/html/static/$VERSION
    gpg --verify coreos_production_image.bin.bz2.sig > /dev/null 2>&1 || { echo "Failed"; exit 1; }
    cd $BSROOT/html/static
    ln -sf ./$VERSION current || { echo "Failed"; exit 1; }
    echo "Done"
}

download_k8s_images () {
  # TODO: should DOCKER_IMAGES from cluster-desc
  DOCKER_IMAGES=("hyperkube" \
    "pause" \
    "flannel" \
    "ingress" \
    "kube2sky" \
    "healthz" \
    "addon_manager" \
    "skydns" \
    "ceph");
  cd $BSROOT
  len=${#DOCKER_IMAGES[@]}
  for ((i=0;i<len;i++)); do
    DOCKER_IMAGE=`grep "${DOCKER_IMAGES[i]}:" $CLUSTER_DESC | awk '{print $2}' | sed 's/ //g' | sed -e 's/^"//' -e 's/"$//'`
    printf "Downloading image ${DOCKER_IMAGE} ..."
    docker pull $DOCKER_IMAGE > /dev/null 2>&1 || { echo "Failed"; exit 1; }
    DOCKER_TAR_FILE=`echo $DOCKER_IMAGE.tar | sed "s/:/_/g" |awk -F'/' '{print $2}'`
    docker save $DOCKER_IMAGE > $DOCKER_TAR_FILE || { echo "Failed"; exit 1; }
    echo "Done"
  done

  printf "Building bootstrapper image ... "
  cd $SEXTANT_DIR/docker
  bash $SEXTANT_DIR/docker/build.bash > /dev/null 2>&1 || { echo "Failed"; exit 1; }
  docker save bootstrapper:latest > $BSROOT/bootstrapper.tar || { echo "Failed"; exit 1; }
  echo "Done"
  # NOTE: we need to run docker load on the bootstrapper server
  # to load these saved images.

  cp $SEXTANT_DIR/start_bootstrapper_container.sh \
    $BSROOT/start_bootstrapper_container.sh 2>&1 || { echo "Failed"; exit 1; }
  chmod +x $BSROOT/start_bootstrapper_container.sh
}

generate_tls_assets() {
    mkdir -p $BSROOT/tls
    cd $BSROOT/tls
    rm -rf $BSROOT/tls/*

    printf "Generating CA TLS assets ... "
    openssl genrsa -out ca-key.pem 2048 > /dev/null 2>&1 || { echo "Failed"; exit 1; }
    openssl req -x509 -new -nodes -key ca-key.pem -days 10000 -out ca.pem -subj "/CN=kube-ca"  > /dev/null 2>&1 || { echo "Failed"; exit 1; }
    echo "Done"

    printf "Generating bootstrapper TLS assets ... "
    openssl genrsa -out bootstrapper.key 2048 > /dev/null 2>&1 || { echo "Failed"; exit 1; }
    openssl req -new -key bootstrapper.key -out bootstrapper.csr -subj "/CN=bootstrapper" > /dev/null 2>&1 || { echo "Failed"; exit 1; }
    openssl x509 -req -in bootstrapper.csr -CA ca.pem -CAkey ca-key.pem -CAcreateserial -out bootstrapper.crt -days 365 > /dev/null 2>&1 || { echo "Failed"; exit 1; }
    echo "Done"
}

prepare_setup_kubectl() {
  printf "Preparing setup kubectl ... "
  sed "s/<KUBE_MASTER_HOSTNAME>/$KUBE_MASTER_HOSTNAME/g" $SEXTANT_DIR/setup-kubectl.bash | \
    sed "s/<HYPERKUBE_VERSION>/$HYPERKUBE_VERSION/g" \
    > $BSROOT/setup_kubectl.bash 2>&1 || { echo "Prepare setup kubectl failed."; exit 1; }
  chmod +x $BSROOT/setup_kubectl.bash
  echo "Done"
}

check_prerequisites
download_pxe_images
generate_pxe_config
generate_dnsmasq_config
generate_registry_config
prepare_cc_server_contents
download_k8s_images
generate_tls_assets
prepare_setup_kubectl


Create ec2_env.sh

Create ec2_env.sh

#!/bin/bash

export AWS_ACCESS_KEY=<>
export AWS_SECRET_KEY=<>
export JAVA_HOME=<>
export EC2_HOME=<>
export PATH=$PATH:$EC2_HOME/bin

error: pathspec 'source/scripts/ec2_env.sh' did not match any file(s) known to git


minor

minor

if [ "$#" -ne 4 ]; then
  echo $0 " rootfile consfile etamin towerid"
  exit
fi

export ROTTFILENAME=$1
export OUTFILENAME="output_check_pca_const.out"
export CONSTFILE=$2
export TOWERID=$4

echo "Using " $ROTTFILENAME " and const file " $CONSTFILE " out " $OUTFILENAME " towerid " $TOWERID
> $OUTFILENAME

#declare -a arr=("3.0;7.0" "7.0;12.0" "12.0;18.0" "18.0;25.0" "25.0;50.0" "50.0;100.0" "100.0;200.0")
declare -a arr=("3.0;7.0")

echo "Rphi plane" >> $OUTFILENAME
for i in "${arr[@]}"
do
  echo $i " Gev mu+" >> $OUTFILENAME
  export FFILE="results_rphi_"$i"_p.txt"
  FILENAME=${FFILE//;/_}
  echo $FILENAME
  ./generatepca_split -k --rphi-plane --charge-sign=+ --pt-range="$i" -D $TOWERID $ROTTFILENAME >> $OUTFILENAME
  ./fitpca_split -N -c "$CONSTFILE" -k --rphi-plane --charge-sign=+ --pt-range="$i" -D $TOWERID $ROTTFILENAME >> $OUTFILENAME
  rm -f results.txt
  echo ""

  echo $i " Gev mu-" >> $OUTFILENAME
  export FFILE="results_rphi_"$i"_n.txt"
  FILENAME=${FFILE//;/_}
  echo $FILENAME
  ./generatepca_split -k --rphi-plane --charge-sign=- --pt-range="$i" -D $TOWERID $ROTTFILENAME >> $OUTFILENAME
  ./fitpca_split -N -c "$CONSTFILE" -k --rphi-plane --charge-sign=- --pt-range="$i" -D $TOWERID $ROTTFILENAME >> $OUTFILENAME
  rm -f results.txt
  echo ""
done

echo "RZ plane"

export k=$3
#for i in `seq 1 20`;
for i in `seq 1 1`;
do
  export start=$k
  k=$(echo "$k + 0.05" | bc | awk '{printf "%f", $0}')
  echo "Eta range: " $start " "  $k >> $OUTFILENAME
  export rage=$start";"$k
  ./generatepca_split -x --rz-plane --eta-range="$rage" -k -D $TOWERID $ROTTFILENAME >> $OUTFILENAME
  ./fitpca_split -N -c "$CONSTFILE" -x --rz-plane --eta-range="$rage" -k -D $TOWERID $ROTTFILENAME >> $OUTFILENAME
  rm -f results.txt
  echo ""
done

error: pathspec 'utilities/check_barrell_quick_overview.sh' did not match any file(s) known to git


Create a zip file too

Create a zip file too

git-svn-id: 9146c88ff6d39b48099bf954d15d68f687b3fa69@9670 28e8926c-6b08-0410-baaa-805c5e19b8d6

#! /bin/sh

TMP=/tmp

# /mnt/scratch is a tmpfs mount point for faster builds on schubby
if [ -w "/mnt/scratch" ] ; then
	TMP=/mnt/scratch
fi

PROACTIVE_DIR=$1
VERSION=$2
JAVA_HOME=$3

TMP_DIR=""

echo " [i] PROACTIVE_DIR: $PROACTIVE_DIR"
echo " [i] VERSION:       $VERSION"
echo " [i] JAVA_HOME:     $JAVA_HOME"
echo " [i] TMP:           $TMP"
function warn_and_exit {
	echo "$1" 1>&2
	exit 1
}

function warn_print_usage_and_exit {
	echo "$1" 1>&2
	echo "" 1>&2
	echo "Usage: $0 PROACTIVE_DIR VERSION JAVA_HOME" 1>&2
	exit 1
}

if [ -z "$PROACTIVE_DIR" ] ; then
	warn_print_usage_and_exit "PROACTIVE_DIR is not defined"
fi

if [ -z "$VERSION" ] ; then
	warn_print_usage_and_exit "VERSION is not defined"
fi

if [ -z "$JAVA_HOME" ] ; then
	warn_print_usage_and_exit "JAVA_HOME is not defined"
fi
export JAVA_HOME=${JAVA_HOME}

TMP_DIR="${TMP}/ProActive-${VERSION}"
output=$(mkdir ${TMP_DIR} 2>&1)
if [ "$?" -ne 0 ] ; then
	if [ -e ${TMP_DIR} ] ; then
		echo " [w] ${TMP_DIR} already exists. Delete it !"
		rm -Rf ${TMP_DIR}
		mkdir ${TMP_DIR}
		if [ "$?" -ne 0 ] ; then
			warn_and_exit "Cannot create ${TMP_DIR}: $output"
		fi
	else
		warn_and_exit "Cannot create ${TMP_DIR}"
	fi
fi

cp -Rf ${PROACTIVE_DIR} ${TMP_DIR}

cd ${TMP_DIR} || warn_and_exit "Cannot move in ${TMP_DIR}"
if [ "$(find src/ -name "*.java" | xargs grep serialVersionUID | grep -v `echo $VERSION | sed 's@\(.\)\.\(.\)\..@\1\2@'` | wc -l)" -gt 0 ] ; then
	if [ -z "${RELAX}" ] ; then
		warn_and_exit " [E] serialVersionUID are NOT defined"
	fi
fi

cd compile || warn_and_exit "Cannot move in compile"
./build clean
./build -Dversion="${VERSION}" deploy.all
./build -Dversion="${VERSION}" manualPdf

cd ${TMP_DIR} || warn_and_exit "Cannot move in ${TMP_DIR}"
echo " [i] Clean"

# Subversion
find . -type d -a -name ".svn" -exec rm -Rf {} \;

# Git
rm -Rf .git

# Remove useless parts of ProActive
rm ./doc-src/ProActiveRefBook.doc
rm ./doc-src/guided_tour/examples/SimpleHelloWorld/lib/ProActive.jar
rm -Rf p2p/
rm -Rf lib/client.jar dist/lib/client.jar
find . -type f -a -name "*.svg" -exec rm {} \; # svg are converted in png by hands

# Remove non GPL stuff
rm -Rf ./compile/lib/clover.*

# Remove temporary files
rm compile/junit*properties
rm -Rf classes/
rm -Rf docs/tmp/
rm -Rf doc-src/*_snippets/

sed -i "s/{version}/$VERSION/" README.txt

tar cvfz ${TMP}/ProActive-${VERSION}.tar.gz ${TMP_DIR}

cd ${TMP}
zip -r ProActive-${VERSION}.zip ProActive-${VERSION}


Add init.d startup script for the B2BUA front.

# b2bua_radius - this script starts and stops the b2bua_radius daemon
#
# chkconfig:   - 85 15
# description:  b2bua_radius is RADIUS-enabled SIP
#		B2BUA
# processname: b2bua_radius
# config:      /etc/sysconfig/b2bua_radius
# pidfile:     /var/run/b2bua_radius.pid

# Source function library.
. /etc/rc.d/init.d/functions

# Source networking configuration.
. /etc/sysconfig/network

# Check that networking is up.
[ "$NETWORKING" = "no" ] && exit 0

b2bua_radius="/home/maxim/b2bua/sippy/b2bua_radius.py"
prog=$(basename $b2bua_radius)

sysconfig="/etc/sysconfig/$prog"
lockfile="/var/lock/subsys/b2bua_radius"
pidfile="/var/run/${prog}.pid"

B2BUA_OPTIONS="--digest_auth=on --accept_ips=202.85.243.105,202.85.245.137 \
  -A 0 --sip_proxy=202.85.245.137 -P ${pidfile} \
  --nat_traversal=on --pass_headers=Remote-Party-ID,Allow,Supported \
  --rtp_proxy_clients="/var/run/rtpproxy.sock""

[ -f $sysconfig ] && . $sysconfig

start() {
    [ -x $b2bua_radius ] || exit 5
    echo -n $"Starting $prog: "
    daemon python2.6 $b2bua_radius ${B2BUA_OPTIONS}
    retval=$?
    echo
    [ $retval -eq 0 ] && touch $lockfile
    return $retval
}

stop() {
    echo -n $"Stopping $prog: "
    killproc -p $pidfile $prog
    retval=$?
    echo
    [ $retval -eq 0 ] && rm -f $lockfile
    return $retval
}

restart() {
    configtest_q || return 6
    stop
    start
}

reload() {
    configtest_q || return 6
    echo -n $"Reloading $prog: "
    killproc -p $pidfile $prog -HUP
    echo
}

rh_status() {
    status $prog
}

rh_status_q() {
    rh_status >/dev/null 2>&1
}

# Upgrade the binary with no downtime.
upgrade() {
    local oldbin_pidfile="${pidfile}.oldbin"

    configtest_q || return 6
    echo -n $"Upgrading $prog: "
    killproc -p $pidfile $prog -USR2
    retval=$?
    sleep 1
    if [[ -f ${oldbin_pidfile} && -f ${pidfile} ]];  then
        killproc -p $oldbin_pidfile $prog -QUIT
        success $"$prog online upgrade"
        echo
        return 0
    else
        failure $"$prog online upgrade"
        echo
        return 1
    fi
}

# Tell b2bua_radius to reopen logs
reopen_logs() {
    configtest_q || return 6
    echo -n $"Reopening $prog logs: "
    killproc -p $pidfile $prog -USR1
    retval=$?
    echo
    return $retval
}

case "$1" in
    start)
        rh_status_q && exit 0
        $1
        ;;
    stop)
        rh_status_q || exit 0
        $1
        ;;
    restart|configtest|reopen_logs)
        $1
        ;;
    force-reload|upgrade)
        rh_status_q || exit 7
        upgrade
        ;;
    reload)
        rh_status_q || exit 7
        $1
        ;;
    status|status_q)
        rh_$1
        ;;
    condrestart|try-restart)
        rh_status_q || exit 7
        restart
        ;;
    *)
        echo $"Usage: $0 {start|stop|reload|configtest|status|force-reload|upgrade|restart|reopen_logs}"
        exit 2
esac

error: pathspec 'init.d/b2bua_radius_front.sh' did not match any file(s) known to git


remove incorrect license

remove incorrect license

remote: Support for password authentication was removed on August 13, 2021.
remote: Please see https://docs.github.com/en/get-started/getting-started-with-git/about-remote-repositories#cloning-with-https-urls for information on currently recommended modes of authentication.
fatal: Authentication failed for 'https://github.com/Tasktop/code2cloud.ops.git/'


a shell script for preprocessing steps

a shell script for preprocessing steps

#!/bin/bash

$INPUT1 = $1
$INPUT2 = $2

#$INPUT1 = "europarl-v7.sv-en.uniq.mixedpipeline_en.conll"
#$INPUT2 = "europarl-v7_sv.lemmatized.txt"
# First, process parallel sentences:
python convert_to_text.py $INPUT1 $INPUT2

# Second, align words
# executable fast_align (https://github.com/clab/fast_align)
./fast_align \-i $INPUT1\_\_$INPUT2\.out.parallel.txt \-d \-o \-v > $INPUT1\_\_$INPUT2\.out.parallel.forward.align
./fast_align \-i $INPUT1\_\_$INPUT2\.out.parallel.txt \-d \-o \-v \-r > $INPUT1\_\_$INPUT2\.out.parallel.reverse.align

# Finally, create the final product:
python combine_alignments.py $INPUT1\.out.raw.txt $INPUT1\_\_$INPUT2\.out.parallel.txt $INPUT1\_\_$INPUT2\.out.parallel.forward.align $INPUT1\_\_$INPUT2\.out.parallel.reverse.align

error: pathspec 'src/python/script.sh' did not match any file(s) known to git


Add doctorjs install script.

Add doctorjs install script.

#!/bin/bash -
#
# TODO: Complete this script

install_jsdoctor() {
    cd $HOME/lib
    git clone git@github.com:mozilla/doctorjs.git
    cd doctorjs
    make install
}

install_jsdoctor

error: pathspec 'scripts/setup/install/doctorjs.sh' did not match any file(s) known to git


Small fix for versioning doc build (#7371)

#!/bin/bash

web_url="$1"
web_folder="VersionedWeb"
local_build="latest"
web_branch="$2"
git clone $web_url $web_folder
cd $web_folder
git checkout $web_branch
cd ..
mkdir "$local_build"

# Fetch tag information
tag_list_file="tag_list.txt"
cp "$web_folder/tag.txt" "$tag_list_file"
tag_list=()
while read -r line
do
    tag_list+=("$line")
done < "$tag_list_file"
latest_tag=${tag_list[0]}
echo "latest_tag is: $latest_tag"
commit_id=$(git rev-parse HEAD)
curr_tag=${TAG}
curr_tag=${curr_tag:5}
echo "Current tag is $curr_tag"
if [[ "$curr_tag" != 'master' ]] && [ $curr_tag != $latest_tag ]
then
    latest_tag=$curr_tag
fi

# Build new released tag
if [ $latest_tag != ${tag_list[0]} ]
then
    echo "Building new tag"
    git submodule update
    make docs || exit 1
    echo -e "$latest_tag\n$(cat $tag_list_file)" > "$tag_list_file"
    cat $tag_list_file
    tests/ci_build/ci_build.sh doc python docs/build_version_doc/AddVersion.py --file_path "docs/_build/html/" \
                                          --current_version "$latest_tag" --root_url "http://mxnet.incubator.apache.org/"
    cp -a "docs/_build/html/." "$local_build"
    cp $tag_list_file "$local_build/tag.txt"
    rm -rf "$web_folder/.git"
    cp -a "$web_folder/versions/." "$local_build/versions"
    mkdir "$local_build/versions/${tag_list[0]}"
    cp -a "$web_folder/." "$local_build/versions/${tag_list[0]}" || exit 1
    rm -rf "$local_build/versions/${tag_list[0]}/versions"
    rm -rf "$web_folder/*"
    cp -a "$local_build/." "$web_folder"
fi

# Build latest master
git checkout master
git checkout -- .
git submodule update
echo "Building master"
make docs || exit 1

rm -rfv "$web_folder/versions/master/*"
cp -a "docs/_build/html/." "$web_folder/versions/master"
tests/ci_build/ci_build.sh doc python docs/build_version_doc/AddVersion.py --file_path "$web_folder/versions/master" \
                                      --root_url "http://mxnet.incubator.apache.org/"

# Update version list for all previous version website
if [ $latest_tag != ${tag_list[0]} ]
then
    total=${#tag_list[*]}
    for (( i=0; i<=$(( $total -1 )); i++ ))
    do
        tests/ci_build/ci_build.sh doc python docs/build_version_doc/AddVersion.py --file_path "$web_folder/versions/${tag_list[$i]}" \
                                              --current_version "${tag_list[$i]}" --root_url "http://mxnet.incubator.apache.org/"
    done
fi

#!/bin/bash

web_url="$1"
web_folder="VersionedWeb"
local_build="latest"
web_branch="$2"
git clone $web_url $web_folder
cd $web_folder
git checkout -b $web_branch "origin/$web_branch"
cd ..
mkdir "$local_build"

# Fetch tag information
tag_list_file="tag_list.txt"
cp "$web_folder/tag.txt" "$tag_list_file"
tag_list=()
while read -r line
do
    tag_list+=("$line")
done < "$tag_list_file"
latest_tag=${tag_list[0]}
echo "latest_tag is: $latest_tag"
commit_id=$(git rev-parse HEAD)
curr_tag=${TAG}
curr_tag=${curr_tag:5}
echo "Current tag is $curr_tag"
if [[ "$curr_tag" != 'master' ]] && [ $curr_tag != $latest_tag ]
then
    latest_tag=$curr_tag
fi

# Build new released tag
if [ $latest_tag != ${tag_list[0]} ]
then
    echo "Building new tag"
    git submodule update
    make docs || exit 1
    echo -e "$latest_tag\n$(cat $tag_list_file)" > "$tag_list_file"
    cat $tag_list_file
    tests/ci_build/ci_build.sh doc python docs/build_version_doc/AddVersion.py --file_path "docs/_build/html/" \
                                          --current_version "$latest_tag" --root_url "http://mxnet.incubator.apache.org/"
    cp -a "docs/_build/html/." "$local_build"
    cp $tag_list_file "$local_build/tag.txt"
    rm -rf "$web_folder/.git"
    cp -a "$web_folder/versions/." "$local_build/versions"
    mkdir "$local_build/versions/${tag_list[0]}"
    cp -a "$web_folder/." "$local_build/versions/${tag_list[0]}" || exit 1
    rm -rf "$local_build/versions/${tag_list[0]}/versions"
    rm -rf "$web_folder/*"
    cp -a "$local_build/." "$web_folder"
fi

# Build latest master
git checkout VersionedDoc
git checkout -- .
git submodule update
echo "Building master"
make docs || exit 1

rm -rfv "$web_folder/versions/master/*"
cp -a "docs/_build/html/." "$web_folder/versions/master"
tests/ci_build/ci_build.sh doc python docs/build_version_doc/AddVersion.py --file_path "$web_folder/versions/master" \
                                      --root_url "http://mxnet.incubator.apache.org/"

# Update version list for all previous version website
if [ $latest_tag != ${tag_list[0]} ]
then
    total=${#tag_list[*]}
    for (( i=0; i<=$(( $total -1 )); i++ ))
    do
        tests/ci_build/ci_build.sh doc python docs/build_version_doc/AddVersion.py --file_path "$web_folder/versions/${tag_list[$i]}" \
                                              --current_version "${tag_list[$i]}" --root_url "http://mxnet.incubator.apache.org/"
    done
fi


Moving compute_yield.sh Deleting fast_beta.sage from its old location

remote: Support for password authentication was removed on August 13, 2021.
remote: Please see https://docs.github.com/en/get-started/getting-started-with-git/about-remote-repositories#cloning-with-https-urls for information on currently recommended modes of authentication.
fatal: Authentication failed for 'https://github.com/mancoast/cado-nfs.git/'


Add copy-kube-artifacts.sh script

Add copy-kube-artifacts.sh script

#!/bin/bash

set -o errexit
set -o nounset
set -o pipefail

OS_ROOT=$(dirname "${BASH_SOURCE}")/..
source "${OS_ROOT}/hack/common.sh"

# Go to the top of the tree.
cd "${OS_ROOT}"

KUBE_ROOT=${1:-""}
KUBE_GODEP_ROOT="${OS_ROOT}/Godeps/_workspace/src/github.com/GoogleCloudPlatform/kubernetes"

if [ -z "$KUBE_ROOT" ]; then
  echo "usage: copy-kube-artifacts.sh <kubernetes root dir>"
  exit 255
fi

special_files="README.md
api/swagger-spec/v1.json
examples/examples_test.go
examples/walkthrough/README.md
examples/iscsi/README.md
examples/simple-yaml.md
"

descriptor_dirs="cmd/integration
examples/
examples/guestbook
examples/guestbook-go
examples/walkthrough
examples/update-demo
examples/persistent-volumes/volumes
examples/persistent-volumes/claims
examples/persistent-volumes/simpletest
examples/iscsi
examples/glusterfs
examples/liveness
examples/rbd/secret
examples/rbd
examples/cassandra
examples/celery-rabbitmq
examples/cluster-dns
examples/downward-api
examples/elasticsearch
examples/explorer
examples/hazelcast
examples/kubernetes-namespaces
examples/limitrange
examples/logging-demo
examples/meteor
examples/mysql-wordpress-pd
examples/nfs
examples/node-selection
examples/openshift-origin
examples/phabricator
examples/redis
examples/resourcequota
examples/rethinkdb
examples/secrets
examples/spark
examples/storm"

for file in $special_files
do
  dir=`dirname $file`
  mkdir -p $KUBE_GODEP_ROOT/$dir

  cp -v $KUBE_ROOT/$file $KUBE_GODEP_ROOT/$file
done

for dir in $descriptor_dirs
do
  mkdir -p $KUBE_GODEP_ROOT/$dir
  files_to_copy=`find $KUBE_ROOT/$dir -maxdepth 1 -name '*.json' -o -name '*.yaml'`

  for file in $files_to_copy
  do
    cp -vf $file $KUBE_GODEP_ROOT/$dir
  done
done

error: pathspec 'hack/copy-kube-artifacts.sh' did not match any file(s) known to git


ask for import

ask for import

remote: Support for password authentication was removed on August 13, 2021.
remote: Please see https://docs.github.com/en/get-started/getting-started-with-git/about-remote-repositories#cloning-with-https-urls for information on currently recommended modes of authentication.
fatal: Authentication failed for 'https://github.com/Osslack/HANA_SSBM.git/'


remote: Support for password authentication was removed on August 13, 2021.
remote: Please see https://docs.github.com/en/get-started/getting-started-with-git/about-remote-repositories#cloning-with-https-urls for information on currently recommended modes of authentication.
fatal: Authentication failed for 'https://github.com/sharkspeed/dororis.git/'


no more 'about' argument in the sample script

#!/usr/bin/env bash
#
# Sample usage of the 'bash-utils' library
#
set -eETu
set -o pipefail

source bash-utils || { echo "> ${BASH_SOURCE[0]}:${LINENO}: bash-utils not found!" >&2; exit 1; };

CMD_NAME='script-model-sample'
CMD_VERSION='0.0.0'
CMD_COPYRIGHT='(CC-BY) 2015 Pierre Cassat & contributors'
CMD_LICENSE='Creative Commons 4.0 BY license <http://creativecommons.org/licenses/by/4.0/legalcode>'
CMD_SOURCES='Sources & updates: <http://gitlab.com/piwi/bash-utils.git>'
CMD_DESCRIPTION="A sample script from *bash* scripts' model."
CMD_HELP="Example of usage:
    ./sample.sh usage
    ./sample.sh help
    ./sample.sh version
    ./sample.sh version --quiet
    ./sample.sh -v -a arg1 -b=arg2 args --force argument2
    ./sample.sh --test1=...* globb # argument must be a globbing pattern
    ./sample.sh --test1 ...* globb # this one will fail as globbing pattern is substituted from terminal
    ./sample.sh error
    ./sample.sh try
    ./sample.sh -v warning
    ./sample.sh -v warning 2>/dev/null

Available options:
    -a|--test1=ARG      option with required argument
    -b|--test2[=ARG]    option with optional argument
    -v|--verbose        increase script's verbosity
    -q|--quiet          decrease script's verbosity
    -f|--force          do not prompt for choices if a default choice exists
    -x|--debug          see some debugging information
    --dry-run           process a dry-run

Use arguments 'usage', 'about' or 'version' for application information.";
CMD_OPTS_SHORT=(':' f q v x V h 'a:' 'b::')
CMD_OPTS_LONG=(debug dry-run force quiet verbose version help 'test1:' 'test2::')
TO_DEBUG=(
    CMD_PROG CMD_ROOT CMD_HOST CMD_USER CMD_CWD CMD_PID CMD_OS
    CMD_CALL VERBOSE QUIET DEBUG FORCE DRY_RUN TEST1 TEST2
)
declare -x TEST1=''
declare -x TEST2=''

# write colorized texts
# inspired by <http://natelandau.com/bash-scripting-utilities/>
# usage: `e_*** <strings>`
e_header()
{
    parse_color_tags "\n<bold><lightmagenta>==========  $@  ==========</bold></lightmagenta>"
}
e_arrow()
{
    parse_color_tags "➜ $@"
}
e_success()
{
    parse_color_tags "<lightgreen>✔ $@</lightgreen>"
}
e_error()
{
    parse_color_tags "<red>✖ $@</red>"
}
e_warning()
{
    parse_color_tags "<yellow>➜ $@</yellow>"
}
e_underline()
{
    parse_color_tags "<underline><bold>$@</bold></underline>"
}
e_bold()
{
    parse_color_tags "<bold>$@</bold>"
}
e_note()
{
    parse_color_tags "<underline><bold><cyan>Note:</underline></bold></cyan>  <cyan>$@</cyan>"
}

[ $# -eq 0 ] && usage_info && exit 1;
rearrange_options "$@"
[ -n "$CMD_REQ" ] && eval set -- "$CMD_REQ";
common_options "$@"
while [ $# -gt 0 ]; do
    case "$1" in
        -f | -q | -v | -x | -h | -V | --version | --help | --force | --quiet | --verbose | --debug | --dry-run ) true;;
        -a | --test1 ) OPTARG="$(echo "$2" | cut -d'=' -f2)"; TEST1="${OPTARG}"; shift;;
        -b | --test2 ) OPTARG="$(echo "$2" | cut -d'=' -f2)"; TEST2="${OPTARG:-default}"; shift;;
        -- ) shift; break;;
        * )  error "unknown option '$1'";;
    esac
    shift
done
$DEBUG && debug;

comment "original request was rebuilt as: $CMD_CALL"
$VERBOSE && comment "verbose mode is enabled";
$QUIET && comment "quiet mode is enabled";
$DEBUG && comment "debug mode is enabled";
$FORCE && comment "force mode is enabled";
$DRY_RUN && comment "dry-run mode is enabled";

# test cases
case "${1:-}" in

    debug)    debug        && exit 0;;
    help)     help_info    && exit 0;;
    usage)    usage_info   && exit 0;;
    version)  version_info && exit 0;;

    # debug arguments
    args)
        debug
        ;;

    # test an error
    error )
        f() { abqsdffhjfqskdlfjqfhs; }
        f 1 2
        ;;

    # test a try/catch statement
    try)
        echo 'test'
        try "ls bin/*.bash"
        try "echo test"
        try "grep some-string /non/existent/file | sort"
        ;;

    # test a globbing pattern as argument (for option a)
    globb)
        for f in $TEST1; do
            echo "f: $f"
        done
        ;;

    # test warning
    warning)
        warning 'my warning message'
        echo 'classic message'
        ;;

    # test colors
    colors)
        use colored-output

        e_header "I am a sample script"
        e_success "I am a success message"
        e_error "I am an error message"
        e_warning "I am a warning message"
        e_underline "I am underlined text"
        e_bold "I am bold text"
        e_note "I am a note"

        padder="$(printf '%0.1s' "-"{1..120})"
        loremipsum='lorem ipsum sit amet'

        [ -z "$TEXTOPTIONS" ] && declare -a TEXTOPTIONS=("$(get_env_array_TEXTOPTIONS)")
        title="TEXTOPTIONS"
        printf "%*.*s | %s %*.*s\n" 0 16 "$padder" "$title" 0 $((80 - ${#title})) "$padder"
        for i in "${TEXTOPTIONS[@]}"; do
            [ "$i" = 'normal' ] && continue;
            text="<${i}>${loremipsum}</${i}>"
            printf "%16s | %20s | %s\n" "$i" "$(parse_color_tags "$text")" "$text"
        done

        title="TEXTCOLORS (foregrounds)"
        [ -z "$TEXTCOLORS" ] && declare -a TEXTCOLORS=("$(get_env_array_TEXTCOLORS)")
        printf "%*.*s | %s %*.*s\n" 0 16 "$padder" "$title" 0 $((80 - ${#title})) "$padder"
        for i in "${TEXTCOLORS[@]}"; do
            [ "$i" = 'normal' ] && continue;
            text="<${i}>${loremipsum}</${i}>"
            printf "%16s | %20s | %s\n" "$i" "$(parse_color_tags "$text")" "$text"
        done

        title="TEXTCOLORS (backgrounds)"
        printf "%*.*s | %s %*.*s\n" 0 16 "$padder" "$title" 0 $((80 - ${#title})) "$padder"
        for i in "${TEXTCOLORS[@]}"; do
            [ "$i" = 'normal' ] && continue;
            text="<${i}_bg>${loremipsum}</${i}_bg>"
            printf "%16s | %20s | %s\n" "${i}_bg" "$(parse_color_tags "$text")" "$text"
        done

        printf "%*.*s | %*.*s\n" 0 16 "$padder" 0 80 "$padder"

        echo "## raw examples:"
        parse_color_tags "$(cat <<MSG
<bold>mlkj</bold>
<magenta>qsdfqsf qsdfqsdfc </magenta>
<magenta_bg>qsdfqsf qsdfqsdfc </magenta_bg>
Lorem ipsum <bold>dolor</bold> sit amet <cyan>Lorem ipsum dolor sit amet</cyan> Lorem <underline>ipsum</underline> <red_bg>dolor</red_bg> sit amet .
Lorem ipsum <bold>dolor</bold> sit amet <cyan>Lorem ipsum <bold>dolor</bold> sit amet</cyan> Lorem ipsum <red_bg>dolor</red_bg> sit amet .
a string with <bold>tags</bold> to <red>set</red> <red_bg>styles</red_bg>
<unknown>mlkj</unknown>
MSG
)";

        ;;

    # test colored-output
    colored-output)
        echo "## run colored-output ...:"
        run colored-output "$(cat <<MSG
<bold>mlkj</bold>
<magenta>qsdfqsf qsdfqsdfc </magenta>
<magenta_bg>qsdfqsf qsdfqsdfc </magenta_bg>
Lorem ipsum <bold>dolor</bold> sit amet <cyan>Lorem ipsum dolor sit amet</cyan> Lorem <underline>ipsum</underline> <red_bg>dolor</red_bg> sit amet .
Lorem ipsum <bold>dolor</bold> sit amet <cyan>Lorem ipsum <bold>dolor</bold> sit amet</cyan> Lorem ipsum <red_bg>dolor</red_bg> sit amet .
a string with <bold>tags</bold> to <red>set</red> <red_bg>styles</red_bg>
<unknown>mlkj</unknown>
MSG
)";
        ;;

    arrays)
        use print-table
        use print-list

        echo
        echo '###########################'
        echo 'print_table'
        echo

        # declare the table array
        declare -a TABLE_ITEMS=()

        # declare the table padders (characters used to fill balcnk spaces)
        # item [0] is padder for separation lines cells
        # item [1] is padder for contents lines cells
        declare -a TABLE_PADDERS=()
        TABLE_PADDERS[0]="$(printf '%0.1s' "-"{1..120})"
        TABLE_PADDERS[1]="$(printf '%0.1s' " "{1..120})"

        # declare the table paddings (number of space(s) from line to cell's contents)
        # item [0] is padding for separation lines cells
        # item [1] is padding for contents lines cells
        declare -a TABLE_PADDINGS=()
        TABLE_PADDINGS[0]=0
        TABLE_PADDINGS[1]=1

        # declare the table separators (characters used to separate cells)
        # item [0] is the separator for separation lines
        # item [1] is the separator for contents lines
        declare -a TABLE_SEPARATORS=()
        TABLE_SEPARATORS[0]='+'
        TABLE_SEPARATORS[1]='|'

        # first item are headers
        declare -a TABLE_HEADERS=( "name" "value" "comment" )
        #TABLE_ITEMS[0]=TABLE_HEADERS[@]

        # add one line as array, declared itself as another array
        declare -a SUB_0=("my name1" "my value1" "my comment1")
        TABLE_ITEMS[${#TABLE_ITEMS[@]}]=SUB_0[@]

        # add one line as array, declared itself as another array
        declare -a SUB_1=("my name2" "lorem ipsum dolor sit amet")
        TABLE_ITEMS[${#TABLE_ITEMS[@]}]=SUB_1[@]

        print_table TABLE_ITEMS[@] TABLE_HEADERS[@] TABLE_PADDINGS[@] TABLE_PADDERS[@] TABLE_SEPARATORS[@]

        echo
        echo '###########################'
        echo 'print_list'
        echo

        # declare the list arrays
        declare -a LIST_HEADERS=('name' 'value')
        declare -a LIST_NAMES=()
        declare -a LIST_VALUES=()

        # add name/value items
        LIST_NAMES[${#LIST_NAMES[@]}]='my name 1'
        LIST_VALUES[${#LIST_VALUES[@]}]='my value 1'

        LIST_NAMES[${#LIST_NAMES[@]}]='my longer name 2'
        LIST_VALUES[${#LIST_VALUES[@]}]='my value 2: lorem ipsum dolor site amet'

        # declare the table padders (characters used to fill balcnk spaces)
        # item [0] is padder for separation lines cells
        # item [1] is padder for contents lines cells
        declare -a LIST_PADDERS=()
        LIST_PADDERS[0]="$(printf '%0.1s' "-"{1..120})"
        LIST_PADDERS[1]="$(printf '%0.1s' " "{1..120})"

        # declare the table paddings (number of space(s) from line to cell's contents)
        # item [0] is padding for separation lines cells
        # item [1] is padding for contents lines cells
        declare -a LIST_PADDINGS=()
        LIST_PADDINGS[0]=0
        LIST_PADDINGS[1]=1

        # declare the table separators (characters used to separate cells)
        # item [0] is the separator for separation lines
        # item [1] is the separator for contents lines
        declare -a LIST_SEPARATORS=()
        LIST_SEPARATORS[0]='+'
        LIST_SEPARATORS[1]='|'

        print_list LIST_NAMES[@] LIST_VALUES[@] LIST_HEADERS[@] LIST_PADDINGS[@] LIST_PADDERS[@] LIST_SEPARATORS[@]
        ;;

    test)

        echo "is known option a?"
        is_known_option a && echo '> known' || echo '> unknown';

        echo "is known option test1:?"
        is_known_option 'test1:' && echo '> known' || echo '> unknown';

        echo "is known option test2::?"
        is_known_option 'test2::' && echo '> known' || echo '> unknown';

        echo "is known option test3::?"
        is_known_option 'test3::' && echo '> known' || echo '> unknown';

        echo "is known option v?"
        is_known_option v && echo '> known' || echo '> unknown';

        echo "is known option verbose?"
        is_known_option verbose && echo '> known' || echo '> unknown';

        echo "is known option z?"
        is_known_option z && echo '> known' || echo '> unknown';

        ;;

    *) error "unknown action '${1:-}'";
esac

exit 0

#!/usr/bin/env bash
#
# Sample usage of the 'bash-utils' library
#
set -eETu
set -o pipefail

source bash-utils || { echo "> ${BASH_SOURCE[0]}:${LINENO}: bash-utils not found!" >&2; exit 1; };

CMD_NAME='script-model-sample'
CMD_VERSION='0.0.0'
CMD_COPYRIGHT='(CC-BY) 2015 Pierre Cassat & contributors'
CMD_LICENSE='Creative Commons 4.0 BY license <http://creativecommons.org/licenses/by/4.0/legalcode>'
CMD_SOURCES='Sources & updates: <http://gitlab.com/piwi/bash-utils.git>'
CMD_DESCRIPTION="A sample script from *bash* scripts' model."
CMD_HELP="Example of usage:
    ./sample.sh usage
    ./sample.sh help
    ./sample.sh version
    ./sample.sh version --quiet
    ./sample.sh about
    ./sample.sh -v -a arg1 -b=arg2 args --force argument2
    ./sample.sh --test1=...* globb # argument must be a globbing pattern
    ./sample.sh --test1 ...* globb # this one will fail as globbing pattern is substituted from terminal
    ./sample.sh error
    ./sample.sh try
    ./sample.sh -v warning
    ./sample.sh -v warning 2>/dev/null

Available options:
    -a|--test1=ARG      option with required argument
    -b|--test2[=ARG]    option with optional argument
    -v|--verbose        increase script's verbosity
    -q|--quiet          decrease script's verbosity
    -f|--force          do not prompt for choices if a default choice exists
    -x|--debug          see some debugging information
    --dry-run           process a dry-run

Use arguments 'usage', 'about' or 'version' for application information.";
CMD_OPTS_SHORT=(':' f q v x V h 'a:' 'b::')
CMD_OPTS_LONG=(debug dry-run force quiet verbose version help 'test1:' 'test2::')
TO_DEBUG=(
    CMD_PROG CMD_ROOT CMD_HOST CMD_USER CMD_CWD CMD_PID CMD_OS
    CMD_CALL VERBOSE QUIET DEBUG FORCE DRY_RUN TEST1 TEST2
)
declare -x TEST1=''
declare -x TEST2=''

# write colorized texts
# inspired by <http://natelandau.com/bash-scripting-utilities/>
# usage: `e_*** <strings>`
e_header()
{
    parse_color_tags "\n<bold><lightmagenta>==========  $@  ==========</bold></lightmagenta>"
}
e_arrow()
{
    parse_color_tags "➜ $@"
}
e_success()
{
    parse_color_tags "<lightgreen>✔ $@</lightgreen>"
}
e_error()
{
    parse_color_tags "<red>✖ $@</red>"
}
e_warning()
{
    parse_color_tags "<yellow>➜ $@</yellow>"
}
e_underline()
{
    parse_color_tags "<underline><bold>$@</bold></underline>"
}
e_bold()
{
    parse_color_tags "<bold>$@</bold>"
}
e_note()
{
    parse_color_tags "<underline><bold><cyan>Note:</underline></bold></cyan>  <cyan>$@</cyan>"
}

[ $# -eq 0 ] && usage_info && exit 1;
rearrange_options "$@"
[ -n "$CMD_REQ" ] && eval set -- "$CMD_REQ";
common_options "$@"
while [ $# -gt 0 ]; do
    case "$1" in
        -f | -q | -v | -x | -h | -V | --version | --help | --force | --quiet | --verbose | --debug | --dry-run ) true;;
        -a | --test1 ) OPTARG="$(echo "$2" | cut -d'=' -f2)"; TEST1="${OPTARG}"; shift;;
        -b | --test2 ) OPTARG="$(echo "$2" | cut -d'=' -f2)"; TEST2="${OPTARG:-default}"; shift;;
        -- ) shift; break;;
        * )  error "unknown option '$1'";;
    esac
    shift
done
$DEBUG && debug;

comment "original request was rebuilt as: $CMD_CALL"
$VERBOSE && comment "verbose mode is enabled";
$QUIET && comment "quiet mode is enabled";
$DEBUG && comment "debug mode is enabled";
$FORCE && comment "force mode is enabled";
$DRY_RUN && comment "dry-run mode is enabled";

# test cases
case "${1:-}" in

    about)    about_info   && exit 0;;
    debug)    debug        && exit 0;;
    help)     help_info    && exit 0;;
    usage)    usage_info   && exit 0;;
    version)  version_info && exit 0;;

    # debug arguments
    args)
        debug
        ;;

    # test an error
    error )
        f() { abqsdffhjfqskdlfjqfhs; }
        f 1 2
        ;;

    # test a try/catch statement
    try)
        echo 'test'
        try "ls bin/*.bash"
        try "echo test"
        try "grep some-string /non/existent/file | sort"
        ;;

    # test a globbing pattern as argument (for option a)
    globb)
        for f in $TEST1; do
            echo "f: $f"
        done
        ;;

    # test warning
    warning)
        warning 'my warning message'
        echo 'classic message'
        ;;

    # test colors
    colors)
        use colored-output

        e_header "I am a sample script"
        e_success "I am a success message"
        e_error "I am an error message"
        e_warning "I am a warning message"
        e_underline "I am underlined text"
        e_bold "I am bold text"
        e_note "I am a note"

        padder="$(printf '%0.1s' "-"{1..120})"
        loremipsum='lorem ipsum sit amet'

        [ -z "$TEXTOPTIONS" ] && declare -a TEXTOPTIONS=("$(get_env_array_TEXTOPTIONS)")
        title="TEXTOPTIONS"
        printf "%*.*s | %s %*.*s\n" 0 16 "$padder" "$title" 0 $((80 - ${#title})) "$padder"
        for i in "${TEXTOPTIONS[@]}"; do
            [ "$i" = 'normal' ] && continue;
            text="<${i}>${loremipsum}</${i}>"
            printf "%16s | %20s | %s\n" "$i" "$(parse_color_tags "$text")" "$text"
        done

        title="TEXTCOLORS (foregrounds)"
        [ -z "$TEXTCOLORS" ] && declare -a TEXTCOLORS=("$(get_env_array_TEXTCOLORS)")
        printf "%*.*s | %s %*.*s\n" 0 16 "$padder" "$title" 0 $((80 - ${#title})) "$padder"
        for i in "${TEXTCOLORS[@]}"; do
            [ "$i" = 'normal' ] && continue;
            text="<${i}>${loremipsum}</${i}>"
            printf "%16s | %20s | %s\n" "$i" "$(parse_color_tags "$text")" "$text"
        done

        title="TEXTCOLORS (backgrounds)"
        printf "%*.*s | %s %*.*s\n" 0 16 "$padder" "$title" 0 $((80 - ${#title})) "$padder"
        for i in "${TEXTCOLORS[@]}"; do
            [ "$i" = 'normal' ] && continue;
            text="<${i}_bg>${loremipsum}</${i}_bg>"
            printf "%16s | %20s | %s\n" "${i}_bg" "$(parse_color_tags "$text")" "$text"
        done

        printf "%*.*s | %*.*s\n" 0 16 "$padder" 0 80 "$padder"

        echo "## raw examples:"
        parse_color_tags "$(cat <<MSG
<bold>mlkj</bold>
<magenta>qsdfqsf qsdfqsdfc </magenta>
<magenta_bg>qsdfqsf qsdfqsdfc </magenta_bg>
Lorem ipsum <bold>dolor</bold> sit amet <cyan>Lorem ipsum dolor sit amet</cyan> Lorem <underline>ipsum</underline> <red_bg>dolor</red_bg> sit amet .
Lorem ipsum <bold>dolor</bold> sit amet <cyan>Lorem ipsum <bold>dolor</bold> sit amet</cyan> Lorem ipsum <red_bg>dolor</red_bg> sit amet .
a string with <bold>tags</bold> to <red>set</red> <red_bg>styles</red_bg>
<unknown>mlkj</unknown>
MSG
)";

        ;;

    # test colored-output
    colored-output)
        echo "## run colored-output ...:"
        run colored-output "$(cat <<MSG
<bold>mlkj</bold>
<magenta>qsdfqsf qsdfqsdfc </magenta>
<magenta_bg>qsdfqsf qsdfqsdfc </magenta_bg>
Lorem ipsum <bold>dolor</bold> sit amet <cyan>Lorem ipsum dolor sit amet</cyan> Lorem <underline>ipsum</underline> <red_bg>dolor</red_bg> sit amet .
Lorem ipsum <bold>dolor</bold> sit amet <cyan>Lorem ipsum <bold>dolor</bold> sit amet</cyan> Lorem ipsum <red_bg>dolor</red_bg> sit amet .
a string with <bold>tags</bold> to <red>set</red> <red_bg>styles</red_bg>
<unknown>mlkj</unknown>
MSG
)";
        ;;

    arrays)
        use print-table
        use print-list

        echo
        echo '###########################'
        echo 'print_table'
        echo

        # declare the table array
        declare -a TABLE_ITEMS=()

        # declare the table padders (characters used to fill balcnk spaces)
        # item [0] is padder for separation lines cells
        # item [1] is padder for contents lines cells
        declare -a TABLE_PADDERS=()
        TABLE_PADDERS[0]="$(printf '%0.1s' "-"{1..120})"
        TABLE_PADDERS[1]="$(printf '%0.1s' " "{1..120})"

        # declare the table paddings (number of space(s) from line to cell's contents)
        # item [0] is padding for separation lines cells
        # item [1] is padding for contents lines cells
        declare -a TABLE_PADDINGS=()
        TABLE_PADDINGS[0]=0
        TABLE_PADDINGS[1]=1

        # declare the table separators (characters used to separate cells)
        # item [0] is the separator for separation lines
        # item [1] is the separator for contents lines
        declare -a TABLE_SEPARATORS=()
        TABLE_SEPARATORS[0]='+'
        TABLE_SEPARATORS[1]='|'

        # first item are headers
        declare -a TABLE_HEADERS=( "name" "value" "comment" )
        #TABLE_ITEMS[0]=TABLE_HEADERS[@]

        # add one line as array, declared itself as another array
        declare -a SUB_0=("my name1" "my value1" "my comment1")
        TABLE_ITEMS[${#TABLE_ITEMS[@]}]=SUB_0[@]

        # add one line as array, declared itself as another array
        declare -a SUB_1=("my name2" "lorem ipsum dolor sit amet")
        TABLE_ITEMS[${#TABLE_ITEMS[@]}]=SUB_1[@]

        print_table TABLE_ITEMS[@] TABLE_HEADERS[@] TABLE_PADDINGS[@] TABLE_PADDERS[@] TABLE_SEPARATORS[@]

        echo
        echo '###########################'
        echo 'print_list'
        echo

        # declare the list arrays
        declare -a LIST_HEADERS=('name' 'value')
        declare -a LIST_NAMES=()
        declare -a LIST_VALUES=()

        # add name/value items
        LIST_NAMES[${#LIST_NAMES[@]}]='my name 1'
        LIST_VALUES[${#LIST_VALUES[@]}]='my value 1'

        LIST_NAMES[${#LIST_NAMES[@]}]='my longer name 2'
        LIST_VALUES[${#LIST_VALUES[@]}]='my value 2: lorem ipsum dolor site amet'

        # declare the table padders (characters used to fill balcnk spaces)
        # item [0] is padder for separation lines cells
        # item [1] is padder for contents lines cells
        declare -a LIST_PADDERS=()
        LIST_PADDERS[0]="$(printf '%0.1s' "-"{1..120})"
        LIST_PADDERS[1]="$(printf '%0.1s' " "{1..120})"

        # declare the table paddings (number of space(s) from line to cell's contents)
        # item [0] is padding for separation lines cells
        # item [1] is padding for contents lines cells
        declare -a LIST_PADDINGS=()
        LIST_PADDINGS[0]=0
        LIST_PADDINGS[1]=1

        # declare the table separators (characters used to separate cells)
        # item [0] is the separator for separation lines
        # item [1] is the separator for contents lines
        declare -a LIST_SEPARATORS=()
        LIST_SEPARATORS[0]='+'
        LIST_SEPARATORS[1]='|'

        print_list LIST_NAMES[@] LIST_VALUES[@] LIST_HEADERS[@] LIST_PADDINGS[@] LIST_PADDERS[@] LIST_SEPARATORS[@]
        ;;

    test)

        echo "is known option a?"
        is_known_option a && echo '> known' || echo '> unknown';

        echo "is known option test1:?"
        is_known_option 'test1:' && echo '> known' || echo '> unknown';

        echo "is known option test2::?"
        is_known_option 'test2::' && echo '> known' || echo '> unknown';

        echo "is known option test3::?"
        is_known_option 'test3::' && echo '> known' || echo '> unknown';

        echo "is known option v?"
        is_known_option v && echo '> known' || echo '> unknown';

        echo "is known option verbose?"
        is_known_option verbose && echo '> known' || echo '> unknown';

        echo "is known option z?"
        is_known_option z && echo '> known' || echo '> unknown';

        ;;

    *) error "unknown action '${1:-}'";
esac

exit 0


White-space formatting.

White-space formatting.

remote: Support for password authentication was removed on August 13, 2021.
remote: Please see https://docs.github.com/en/get-started/getting-started-with-git/about-remote-repositories#cloning-with-https-urls for information on currently recommended modes of authentication.
fatal: Authentication failed for 'https://github.com/xcjs/workstation-provision.git/'


Update and rename 30-Software_Design/10-Vision/send_stream to 30-Software_Design/10-Vision/send_stream/installer.sh

sudo apt-get install build-essential -y
sudo apt-get install pkg-config -y
sudo apt-get install linux-libc-dev -y
sudo apt-get install libv4l-dev -y

mkdir ~/bin
mkdir /tmp

cp send_stream/build_send_stream.sh /tmp
cp send_stream/send_stream.c /tmp

# You may need to adjust
/tmp/send_stream -c0 -s -f -d /dev/video0
cp tmp/send_stream ~/bin

error: pathspec '30-Software_Design/10-Vision/send_stream/installer.sh' did not match any file(s) known to git