Skip to content

Instantly share code, notes, and snippets.

@alejandroandreu
Created May 29, 2018 16:01
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save alejandroandreu/5a39069199717c531112eb94b7e63832 to your computer and use it in GitHub Desktop.
Save alejandroandreu/5a39069199717c531112eb94b7e63832 to your computer and use it in GitHub Desktop.
#!/bin/bash -e
echo
echo "| |_|_| |___ ___ ___| |_ | _ | __ | |"
echo "| | | | | . | . | | -_| _| | | -| | | |"
echo "|_|_|_|_|___|___|_|_|___|_| |__|__|__|__|_|_|_|"
echo
set -x
#
# V A R I A B L E S
#
YELLOW='\033[1;33m'
GREEN='\033[0;32m'
NC='\033[0m'
MIDONET_GIT_URL="https://review.gerrithub.io/midonet/midonet"
MIDONET_GIT_BRANCH= # TODO: Wait for ---- to commit changes in a hotfix branch
WORKING_DIR=$(mktemp --directory)
NEW_HOSTNAME="$1"
RUNUSER=$(whoami)
#
# F U N C T I O N S
#
function info() {
echo -e "${GREEN}[*] ${@}${NC}"
}
function alert () {
echo -e "${YELLOW}[!] ${@}${NC}"
}
#
# M A I N
#
if [ "$#" -ne 1 ]; then
alert "Missing argument. Usage: $0 NEW_HOSTNAME"
exit 1
fi
if ! [ "$(id -u)" == "0" ]; then
info "Adding user ${USER} to sudoers... (will ask for password)"
echo "${USER} ALL=(root) NOPASSWD:ALL" | sudo tee -a "/etc/sudoers.d/${USER}"
sudo chmod 0440 "/etc/sudoers.d/${USER}"
fi
info "Updating certificates..."
sudo apt update
sudo apt install --yes ca-certificates
info "Setting hostname..."
sudo hostnamectl set-hostname "$NEW_HOSTNAME"
alert "Remember to set up hostname ${NEW_HOSTNAME} in /etc/hosts"
info "Recompiling kernel with necessary modules..."
# TODO: Remove hardcoding of cloning sources in nvidia's home folder
wget https://raw.githubusercontent.com/midokura/buildJetsonTX2Kernel/master/scripts/deployKernel.sh -qO- | sudo sh -
info "Installing repositories..."
sudo apt-add-repository ppa:brightbox/ruby-ng
sudo add-apt-repository ppa:webupd8team/java
sudo apt update
info "Installing packages..."
sudo apt install --yes wget git g++ make debsigs expect rpm maven ruby ruby-dev oracle-java8-installer oracle-java8-set-default git-review protobuf-compiler python3-setuptools python-setuptools
sudo gem install fpm ronn
info "Cloning sources..."
cd "${WORKING_DIR}"
git config --global user.email "you@example.com"
git config --global user.name "Your Name"
git clone https://github.com/midonet/midonet
cd "midonet"
git fetch https://review.gerrithub.io/midonet/midonet refs/changes/84/400984/9 && git checkout FETCH_HEAD
git fetch https://review.gerrithub.io/midonet/midonet refs/changes/88/400788/2 && git cherry-pick FETCH_HEAD
# TODO: Uncomment this when change is fully merged
#git clone $MIDONET_GIT_URL -b $MIDONET_GIT_BRANCH
#cd "midonet"
info "Building .deb packages..."
./gradlew clean debian -x test -x integration
info "Installing Midolman package..."
midotools_deb=$(find . -name "*.deb" | grep tools)
midolman_deb=$(find . -name "*.deb" | grep midolman)
sudo dpkg -i --ignore-depends=libreswan,vpp "$midotools_deb" || true
sudo dpkg -i --ignore-depends=libreswan,vpp "$midolman_deb" || true
sudo apt-get -f install || true
sudo dpkg -i --ignore-depends=libreswan,vpp "$midotools_deb" || true
sudo dpkg -i --ignore-depends=libreswan,vpp "$midolman_deb" || true
find . -name "*.deb" -exec cp {} /tmp/ \;
info "All .deb files have been placed in /tmp"
info "Cleaning up... Thanks for flying MidoNet!"
cd
rm -rf "$WORKING_DIR"
exit 0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment