2016-04-11 04:33:44 +02:00
|
|
|
#!/bin/bash
|
|
|
|
|
|
|
|
set -euo pipefail
|
|
|
|
|
2016-05-07 21:15:42 +02:00
|
|
|
function HELP {
|
|
|
|
echo "Build a debian package for lbry"
|
|
|
|
echo "-----"
|
|
|
|
echo "When run without any arguments, this script expects the current directory"
|
|
|
|
echo "to be the main lbry repo and it builds what is in that directory"
|
|
|
|
echo
|
|
|
|
echo "Optional arguments:"
|
|
|
|
echo
|
|
|
|
echo "-c: clone a fresh copy of the repo"
|
|
|
|
echo "-b <branch>: use the specified branch of the lbry repo"
|
|
|
|
echo "-w <web-ui-branch>: set the webui branch"
|
|
|
|
echo "-d <build-dir>: specifiy the build directory"
|
|
|
|
echo "-h: show help"
|
|
|
|
echo "-t: turn trace on"
|
|
|
|
exit 1
|
|
|
|
}
|
2016-04-11 04:33:44 +02:00
|
|
|
|
2016-05-07 21:15:42 +02:00
|
|
|
CLONE=false
|
|
|
|
BUILD_DIR=""
|
|
|
|
BRANCH=""
|
|
|
|
WEB_UI_BRANCH="master"
|
|
|
|
|
|
|
|
while getopts :hctb:w:d: FLAG; do
|
|
|
|
case $FLAG in
|
2016-05-23 04:36:56 +02:00
|
|
|
c)
|
2016-05-07 21:15:42 +02:00
|
|
|
CLONE=true
|
|
|
|
;;
|
2016-05-23 04:36:56 +02:00
|
|
|
b)
|
2016-05-07 21:15:42 +02:00
|
|
|
BRANCH=${OPTARG}
|
|
|
|
;;
|
2016-05-23 04:36:56 +02:00
|
|
|
w)
|
2016-05-07 21:15:42 +02:00
|
|
|
WEB_UI_BRANCH=${OPTARG}
|
|
|
|
;;
|
|
|
|
d)
|
|
|
|
BUILD_DIR=${OPTARG}
|
|
|
|
;;
|
|
|
|
t)
|
|
|
|
set -o xtrace
|
|
|
|
;;
|
2016-05-23 04:36:56 +02:00
|
|
|
h)
|
2016-05-07 21:15:42 +02:00
|
|
|
HELP
|
|
|
|
;;
|
|
|
|
\?) #unrecognized option - show help
|
|
|
|
echo "Option -$OPTARG not allowed."
|
|
|
|
HELP
|
|
|
|
;;
|
|
|
|
:)
|
|
|
|
echo "Option -$OPTARG requires an argument."
|
|
|
|
HELP
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
done
|
|
|
|
|
|
|
|
shift $((OPTIND-1))
|
|
|
|
|
|
|
|
|
|
|
|
SUDO=''
|
|
|
|
if (( $EUID != 0 )); then
|
|
|
|
SUDO='sudo'
|
|
|
|
fi
|
|
|
|
|
|
|
|
if [ "$CLONE" = false ]; then
|
|
|
|
if [ `basename $PWD` != "lbry" ]; then
|
|
|
|
echo "Not currently in the lbry directory. Cowardly refusing to go forward"
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
SOURCE_DIR=$PWD
|
|
|
|
fi
|
|
|
|
|
|
|
|
if [ -z "${BUILD_DIR}" ]; then
|
|
|
|
if [ "$CLONE" = true ]; then
|
|
|
|
# build in the current directory
|
|
|
|
BUILD_DIR="lbry-build-$(date +%Y%m%d-%H%M%S)"
|
|
|
|
else
|
|
|
|
BUILD_DIR="../lbry-build-$(date +%Y%m%d-%H%M%S)"
|
|
|
|
fi
|
|
|
|
fi
|
|
|
|
|
|
|
|
mkdir -p "$BUILD_DIR"
|
2016-04-13 00:50:47 +02:00
|
|
|
cd "$BUILD_DIR"
|
|
|
|
|
2016-05-07 21:15:42 +02:00
|
|
|
if [ -z ${TRAVIS+x} ]; then
|
|
|
|
# if not on travis, its nice to see progress
|
|
|
|
QUIET=""
|
|
|
|
else
|
|
|
|
QUIET="-qq"
|
|
|
|
fi
|
|
|
|
|
2016-04-11 04:33:44 +02:00
|
|
|
# get the required OS packages
|
2016-05-07 21:15:42 +02:00
|
|
|
$SUDO apt-get ${QUIET} update
|
|
|
|
$SUDO apt-get ${QUIET} install -y --no-install-recommends software-properties-common
|
|
|
|
$SUDO add-apt-repository -y ppa:spotify-jyrki/dh-virtualenv
|
|
|
|
$SUDO apt-get ${QUIET} update
|
|
|
|
$SUDO apt-get ${QUIET} install -y --no-install-recommends \
|
|
|
|
build-essential git python-dev libffi-dev libssl-dev \
|
2016-05-23 04:36:56 +02:00
|
|
|
libgmp3-dev dh-virtualenv debhelper wget python-pip fakeroot
|
2016-04-11 04:33:44 +02:00
|
|
|
|
|
|
|
# need a modern version of pip (more modern than ubuntu default)
|
2016-05-07 21:15:42 +02:00
|
|
|
$SUDO pip install --upgrade pip
|
|
|
|
$SUDO pip install make-deb
|
2016-04-11 04:33:44 +02:00
|
|
|
|
|
|
|
# build packages
|
2016-05-07 21:15:42 +02:00
|
|
|
#
|
|
|
|
# dpkg-buildpackage outputs its results into '..' so
|
|
|
|
# we need to move/clone lbry into the build directory
|
|
|
|
if [ "$CLONE" == true]; then
|
|
|
|
cp -a $SOURCE_DIR lbry
|
|
|
|
else
|
|
|
|
git clone https://github.com/lbryio/lbry.git
|
|
|
|
fi
|
2016-04-11 04:33:44 +02:00
|
|
|
(
|
2016-05-07 21:15:42 +02:00
|
|
|
cd lbry
|
|
|
|
if [ -n "${BRANCH}" ]; then
|
|
|
|
git checkout "${BRANCH}"
|
|
|
|
fi
|
|
|
|
make-deb
|
|
|
|
dpkg-buildpackage -us -uc
|
2016-04-11 04:33:44 +02:00
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
### insert our extra files
|
|
|
|
|
|
|
|
# extract .deb
|
|
|
|
PACKAGE="$(ls | grep '.deb')"
|
|
|
|
ar vx "$PACKAGE"
|
|
|
|
mkdir control data
|
2016-05-07 21:15:42 +02:00
|
|
|
tar -xzf control.tar.gz --directory control
|
|
|
|
|
|
|
|
# The output of the travis build is a
|
|
|
|
# tar.gz and the output locally is tar.xz.
|
|
|
|
# Instead of having tar detect the compression used, we
|
|
|
|
# could update the config to output the same in either spot.
|
|
|
|
# Unfortunately, doing so requires editting some auto-generated
|
|
|
|
# files: http://linux.spiney.org/forcing_gzip_compression_when_building_debian_packages
|
|
|
|
tar -xf data.tar.?z --directory data
|
2016-04-11 04:33:44 +02:00
|
|
|
|
2016-05-06 20:30:00 +02:00
|
|
|
PACKAGING_DIR='lbry/packaging/ubuntu'
|
|
|
|
|
|
|
|
# set web ui branch
|
2016-05-20 18:13:58 +02:00
|
|
|
sed -i "s/^WEB_UI_BRANCH='[^']\+'/WEB_UI_BRANCH='$WEB_UI_BRANCH'/" "$PACKAGING_DIR/lbry"
|
2016-05-06 20:30:00 +02:00
|
|
|
|
2016-04-11 04:33:44 +02:00
|
|
|
# add files
|
|
|
|
function addfile() {
|
|
|
|
FILE="$1"
|
|
|
|
TARGET="$2"
|
|
|
|
mkdir -p "$(dirname "data/$TARGET")"
|
|
|
|
cp "$FILE" "data/$TARGET"
|
|
|
|
echo "$(md5sum "data/$TARGET" | cut -d' ' -f1) $TARGET" >> control/md5sums
|
|
|
|
}
|
2016-04-13 00:50:47 +02:00
|
|
|
addfile "$PACKAGING_DIR/lbry" usr/share/python/lbrynet/bin/lbry
|
2016-04-11 04:33:44 +02:00
|
|
|
addfile "$PACKAGING_DIR/lbry.desktop" usr/share/applications/lbry.desktop
|
|
|
|
|
2016-05-23 06:19:55 +02:00
|
|
|
cat "$PACKAGING_DIR/postinst_append" >> control/postinst
|
|
|
|
|
2016-04-11 04:33:44 +02:00
|
|
|
# repackage .deb
|
2016-05-07 21:15:42 +02:00
|
|
|
$SUDO chown -R root:root control data
|
|
|
|
tar -czf control.tar.gz -C control .
|
|
|
|
tar -cJf data.tar.xz -C data .
|
|
|
|
$SUDO chown root:root debian-binary control.tar.gz data.tar.xz
|
2016-04-11 04:33:44 +02:00
|
|
|
ar r "$PACKAGE" debian-binary control.tar.gz data.tar.xz
|
|
|
|
|
|
|
|
# TODO: we can append to data.tar instead of extracting it all and recompressing
|