Skip to content

Instantly share code, notes, and snippets.

@hdoverobinson
Last active February 5, 2018 02:52
Show Gist options
  • Save hdoverobinson/91bfda10ad4398b79e8dc813041c5d33 to your computer and use it in GitHub Desktop.
Save hdoverobinson/91bfda10ad4398b79e8dc813041c5d33 to your computer and use it in GitHub Desktop.
#!/bin/bash
###AUTHOR###
#Harry Dove-Robinson 2018-02-04
#harry@doverobinson.me
#https://gist.github.com/hdoverobinson
#https://github.com/hdoverobinson
###CONTENTS OF TARGET_DIR WILL BE CLEARED AT EACH RUN###
DOCKER="$1"
TARGET_DIR="/root/osp-build"
BUILD_DIR="$TARGET_DIR/build"
RUN_DIR="$TARGET_DIR/bin"
MONO_BRANCH="Release"
GOESDUMP_BRANCH="TestingFeatures"
GOESDUMP_WEB_URL="https://github.com/opensatelliteproject/goesdump/releases/download/1.3.6489/goesdump-web.zip"
BUILD_PACKAGES1="apt-utils build-essential ca-certificates ca-certificates-mono cmake git nuget software-properties-common unzip wget"
BUILD_PACKAGES2="nuget msbuild"
RUN_PACKAGES="libaec0 libaec-dev libairspy-dev libhackrf0 libhackrf-dev libusb-1.0-0-dev mono-complete monodevelop screen tzdata"
if [ "$EUID" -ne 0 ]
then echo "This script must be run as root!"
exit 1
fi &&
DOCKER=${DOCKER,,} &&
if ! [[ "$DOCKER" =~ "docker" ]]
then
echo "$(tput setaf 1 2> /dev/null)ANY FILES WITHIN $TARGET_DIR WILL BE DESTROYED. CONTINUE? (yes/no)$(tput sgr0 2> /dev/null)" &&
read -r REPLY &&
REPLY=${REPLY,,} &&
if ! [[ $REPLY =~ ^(yes|y) ]]
then
echo "$(tput setaf 1 2> /dev/null)Aborting!$(tput sgr0 2> /dev/null)" &&
exit 1
else
sleep 2s
fi
fi &&
if [[ "$DOCKER" =~ "docker" ]]
then
set -x &&
TARGET_DIR="/root/osp-build/"
BUILD_DIR="$TARGET_DIR/build"
RUN_DIR="$TARGET_DIR/bin"
fi &&
#create target dir, clear it out if it already exists
echo "$(tput setaf 2 2> /dev/null)Preparing target directory...$(tput sgr0 2> /dev/null)" &&
mkdir -p "$TARGET_DIR" &&
cd "$TARGET_DIR" &&
rm -rf * &&
mkdir -p "$BUILD_DIR" &&
mkdir -p "$RUN_DIR" &&
cd "$BUILD_DIR" &&
echo "$(tput setaf 2 2> /dev/null)Getting dependencies...$(tput sgr0 2> /dev/null)" &&
apt-get update &&
apt-get --no-install-recommends -y install $BUILD_PACKAGES1 &&
add-apt-repository ppa:myriadrf/drivers -y &&
add-apt-repository ppa:myriadrf/gnuradio -y &&
apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv-keys 3FA7E0328081BFF6A14DA29AA6A19B38D3D831EF &&
echo "deb http://download.mono-project.com/repo/ubuntu xenial main" | tee /etc/apt/sources.list.d/mono-official.list &&
apt-get update &&
apt-get --no-install-recommends -y install $BUILD_PACKAGES2 &&
apt-get --no-install-recommends -y install $RUN_PACKAGES &&
echo "$(tput setaf 2 2> /dev/null)Building xritdemod...$(tput sgr0 2> /dev/null)" &&
git clone https://github.com/opensatelliteproject/xritdemod.git &&
cd xritdemod/ &&
make libcorrect &&
make libcorrect-install &&
git clone https://github.com/opensatelliteproject/libsathelper.git &&
cd libsathelper &&
#comment out below line if you have Haswell or newer
sed -i '/ADD_CXX_COMPILER_FLAG_IF_AVAILABLE(-mfma HAVE_FMA)/s/^/#/' CMakeLists.txt &&
mkdir build &&
cd build &&
cmake .. &&
make &&
make install &&
cd ../../ &&
make librtlsdr &&
make librtlsdr-install &&
make &&
make test &&
echo "$(tput setaf 2 2> /dev/null)Build complete for xritdemod!$(tput sgr0 2> /dev/null)" &&
cd "$BUILD_DIR" &&
echo "$(tput setaf 2 2> /dev/null)Building goesdump...$(tput sgr0 2> /dev/null)" &&
git clone -b "$GOESDUMP_BRANCH" https://github.com/opensatelliteproject/goesdump.git &&
cd goesdump &&
git clone https://github.com/opensatelliteproject/decompressor.git &&
cd decompressor &&
mkdir build &&
cd build &&
cmake .. &&
make &&
make install &&
ldconfig &&
cd "$BUILD_DIR/goesdump" &&
nuget restore goesdump.sln &&
msbuild /p:Configuration="$MONO_BRANCH" goesdump.sln &&
cd "goesdump/bin/$MONO_BRANCH" &&
mkbundle --simple *.exe XRIT.dll -o goesdump &&
echo "$(tput setaf 2 2> /dev/null)Build complete for goesdump!$(tput sgr0 2> /dev/null)" &&
echo "$(tput setaf 2 2> /dev/null)Setting up run environment...$(tput sgr0 2> /dev/null)" &&
mkdir -p "$RUN_DIR/xritdemod" &&
mkdir -p "$RUN_DIR/goesdump" &&
cd "$RUN_DIR/goesdump" &&
cp -r "$BUILD_DIR/goesdump/goesdump/bin/$MONO_BRANCH"/* . &&
chmod +x goesdump &&
cd "$RUN_DIR/xritdemod" &&
cp "$BUILD_DIR/xritdemod/decoder/build/xritDecoder" . &&
cp "$BUILD_DIR/xritdemod/demodulator/build/xritDemodulator" . &&
chmod +x * &&
echo "$(tput setaf 2 2> /dev/null)Getting goesdump web components...$(tput sgr0 2> /dev/null)" &&
cd "$RUN_DIR/goesdump" &&
wget "$GOESDUMP_WEB_URL" &&
unzip goesdump-web.zip &&
mv build web &&
rm goesdump-web.zip &&
#docker cleanup
if [[ "$DOCKER" =~ "docker" ]]
then
rm -r /var/lib/apt/lists/* &&
rm -r /root/osp-build/build/ &&
apt-get purge -y --auto-remove $BUILD_PACKAGES1 $BUILD_PACKAGES2
fi &&
echo "$(tput setaf 2 2> /dev/null)Finished! You can now run the binaries from $RUN_DIR.$(tput sgr0 2> /dev/null)" &&
exit 0 ||
echo "$(tput setaf 2 2> /dev/null)Something went wrong!$(tput sgr0 2> /dev/null)" &&
exit 1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment