Last active
October 29, 2017 08:14
-
-
Save fno2010/6c77070b22d705fb41c813f55a31a641 to your computer and use it in GitHub Desktop.
Quickly setup an ODL controller with alto-unicorn
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
WORKDIR=$1 | |
UNICORN_URL=https://github.com/openalto/alto-experimental | |
UNICORN_DIR=$WORKDIR/alto-experimental | |
UNICORN_FEATURE=$UNICORN_DIR/features/target/alto-experimental-features-0.1.0-SNAPSHOT.kar | |
yum install -y wget git zip unzip | |
curl -s "https://get.sdkman.io" | bash | |
source "$HOME/.sdkman/bin/sdkman-init.sh" | |
sdk i java 8u151-oracle | |
sdk i maven 3.5.0 | |
mkdir -p ~/.m2 | |
touch ~/.m2/settings.xml | |
cp -n ~/.m2/settings.xml{,.orig} ; \ | |
wget -q -O - https://raw.githubusercontent.com/opendaylight/odlparent/master/settings.xml > ~/.m2/settings.xml | |
git clone $UNICORN_URL -b single-feature-repo $UNICORN_DIR | |
pushd $UNICORN_DIR | |
mvn clean install -DskipTests | |
popd | |
LOGIN_KARAF=$2 | |
KARAF_BASE=$3 | |
$LOGIN_KARAF config:edit org.ops4j.pax.url.mvn; \ | |
config:property-set org.ops4j.pax.url.mvn.defaultRepositories \ | |
'"file:${karaf.home}/${karaf.default.repository}@id=system.repository@snapshots, | |
file:${karaf.data}/kar@id=kar.repository@multi@snapshots, | |
file:${karaf.base}/${karaf.default.repository}@id=child.system.repository@snapshots"'; \ | |
config:update | |
if [ -n $KARAF_BASE ] ; then | |
cp $UNICORN_FEATURE $KARAF_BASE/deploy/ | |
$LOGIN_KARAF feature:install odl-alto-unicorn-ui | |
else | |
$LOGIN_KARAF kar:install file://$UNICORN_FEATURE; \ | |
feature:install odl-alto-unicorn-ui | |
fi |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
WORKDIR="$(pwd)" | |
CACHE="$WORKDIR/.cache" | |
mkdir -p "$CACHE" | |
BASE_URL="https://nexus.opendaylight.org/content/repositories/opendaylight.release/org/opendaylight/integration/distribution-karaf" | |
DEFAULT_DISTRIBUTION="0.6.1-Carbon" | |
URL="$BASE_URL/$DEFAULT_DISTRIBUTION/distribution-karaf-$DEFAULT_DISTRIBUTION.zip" | |
UNICORN_URL=https://github.com/openalto/alto-experimental | |
work_in() { | |
local DIR="$1" | |
shift | |
local CMD="$*" | |
pushd "$DIR" &>/dev/null && \ | |
$CMD 1>/dev/null && \ | |
echo "Done." || \ | |
echo "Failed." && \ | |
popd | |
} | |
find_local_file() { | |
local FILENAME=distribution-karaf-$1 | |
local TARGET=$2 | |
if [ -f "$CACHE/$FILENAME.tar.gz" ]; then | |
eval $TARGET="$FILENAME.tar.gz" | |
elif [ -f "$CACHE/$FILENAME.tar" ]; then | |
eval $TARGET="$FILENAME.tar" | |
elif [ -f "$CACHE/$FILENAME.zip" ]; then | |
eval $TARGET="$FILENAME.zip" | |
else | |
eval $TARGET="" | |
fi | |
} | |
download() { | |
local DISTRIBUTION=$1 | |
local TARGET=$2 | |
local TARGET_FILE=$(eval "echo \$$TARGET") | |
echo $TARGET_FILE | |
if [ -z "$TARGET_FILE" ] || [ ! -f "$CACHE/$TARGET_FILE" ]; then | |
if [ -n "$DISTRIBUTION" ]; then | |
URL="$BASE_URL/$DISTRIBUTION/distribution-karaf-$DISTRIBUTION.zip" | |
fi | |
wget $URL -P "$CACHE" | |
find_local_file $DISTRIBUTION $TARGET | |
fi | |
} | |
install() { | |
local FILENAME=distribution-karaf-$1 | |
local TARGET=$2 | |
local INSTALL="echo" | |
local TARGET_FILE="Failed to install target: $FILENAME" | |
local INSTALL_PATH=${3:-$TARGET} | |
rm -rf "$TARGET" | |
if [ -f "$CACHE/$FILENAME.tar.gz" ]; then | |
INSTALL="$(which tar) xvfz" | |
TARGET_FILE="$CACHE/$FILENAME.tar.gz" | |
elif [ -f "$CACHE/$FILENAME.tar" ]; then | |
INSTALL="$(which tar) xvf" | |
TARGET_FILE="$CACHE/$FILENAME.tar" | |
elif [ -f "$CACHE/$FILENAME.zip" ]; then | |
INSTALL="$(which unzip)" | |
TARGET_FILE="$CACHE/$FILENAME.zip" | |
fi | |
mkdir -p "$INSTALL_PATH" | |
echo "Installing $FILENAME" | |
work_in "$INSTALL_PATH" "$INSTALL $TARGET_FILE" | |
} | |
merge_log_file() { | |
local ORIGIN=$1 | |
local TMP="$1_tmp" | |
rm -f $TMP | |
cat "$ORIGIN" | sed "s/^.*2016/2016/g" | sort | uniq > "$TMP" | |
mv "$TMP" "$ORIGIN" | |
} | |
set_distribution() { | |
if [ -z "$1" ]; then | |
DISTRIBUTION="$DEFAULT_DISTRIBUTION" | |
else | |
DISTRIBUTION="$1" | |
fi | |
DISTRIBUTION_DIR="$WORKDIR/$DISTRIBUTION" | |
ODL_SYSPATH="$DISTRIBUTION_DIR/system/org/opendaylight" | |
} | |
setup_distribution() { | |
set_distribution $1 | |
find_local_file $DISTRIBUTION DISTRIBUTION_FILE | |
download $DISTRIBUTION DISTRIBUTION_FILE | |
install $DISTRIBUTION "$DISTRIBUTION_DIR" "$WORKDIR" | |
} | |
setup_git() { | |
echo "Setting up git for $DISTRIBUTION" | |
work_in $DISTRIBUTION_DIR git init | |
} | |
start_controller() { | |
echo "Starting ODL controller (distribution: $DISTRIBUTION)" | |
work_in $DISTRIBUTION_DIR bin/start | |
} | |
install_dependency() { | |
yum install -y wget git zip unzip # Only work on redhat/centos/fedora | |
curl -s "https://get.sdkman.io" | bash | |
source "$HOME/.sdkman/bin/sdkman-init.sh" | |
sdk i java 8u151-oracle | |
sdk i maven 3.5.0 | |
mkdir -p ~/.m2 | |
touch ~/.m2/settings.xml | |
cp -n ~/.m2/settings.xml{,.orig} ; \ | |
wget -q -O - https://raw.githubusercontent.com/opendaylight/odlparent/master/settings.xml > ~/.m2/settings.xml | |
} | |
install_unicorn() { | |
local UNICORN_DIR=$WORKDIR/alto-experimental | |
local UNICORN_FEATURE=$UNICORN_DIR/features/target/alto-experimental-features-0.1.0-SNAPSHOT.kar | |
git clone $UNICORN_URL -b single-feature-repo $UNICORN_DIR | |
work_in $UNICORN_DIR mvn clean install -DskipTests | |
work_in $DISTRIBUTION_DIR bin/client config:edit org.ops4j.pax.url.mvn; \ | |
config:property-set org.ops4j.pax.url.mvn.defaultRepositories \ | |
'"file:${karaf.home}/${karaf.default.repository}@id=system.repository@snapshots, | |
file:${karaf.data}/kar@id=kar.repository@multi@snapshots, | |
file:${karaf.base}/${karaf.default.repository}@id=child.system.repository@snapshots"'; \ | |
bin/client config:update | |
work_in $DISTRIBUTION_DIR bin/client kar:install file://$UNICORN_FEATURE | |
work_in $DISTRIBUTION_DIR bin/client feature:install odl-alto-unicorn-ui | |
} | |
install_dependency | |
setup_distribution $1 | |
start_controller | |
install_unicorn |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Just run
./setup-unicorn.sh
.If you have set up the ODL controller by yourself, you can run
./setup-unicorn-without-odl.sh <base_dir> <karaf_login_cmd>
.For example,