2015-10-21 19:46:24 +00:00
#!/usr/bin/env bash
2015-11-16 19:21:57 +00:00
#
# Copyright (c) .NET Foundation and contributors. All rights reserved.
# Licensed under the MIT license. See LICENSE file in the project root for full license information.
2015-10-22 22:12:49 +00:00
# Debian Packaging Script
2015-10-21 19:46:24 +00:00
# Currently Intended to build on ubuntu14.04
2015-12-02 19:52:19 +00:00
set -e
2015-10-21 19:46:24 +00:00
SOURCE = " ${ BASH_SOURCE [0] } "
while [ -h " $SOURCE " ] ; do # resolve $SOURCE until the file is no longer a symlink
DIR = " $( cd -P " $( dirname " $SOURCE " ) " && pwd ) "
SOURCE = " $( readlink " $SOURCE " ) "
2015-12-28 19:47:21 +00:00
[ [ " $SOURCE " != /* ] ] && SOURCE = " $DIR / $SOURCE " # if $SOURCE was a relative symlink, we need to resolve it relative to the path where the symlink file was located
2015-10-21 19:46:24 +00:00
done
DIR = " $( cd -P " $( dirname " $SOURCE " ) " && pwd ) "
2015-12-29 10:34:10 +00:00
source " $DIR /../common/_common.sh "
2016-03-08 23:33:18 +00:00
REPOROOT = " $DIR /../.. "
help( ) {
echo " Usage: $0 "
echo ""
echo "Options:"
echo " --version <version> Specify a version for the package."
echo " --input <input directory> Package the entire contents of the directory tree."
2016-03-09 20:15:06 +00:00
echo " --manpages <man pages directory> Directory containing man pages for the package (Optional)."
2016-03-08 23:33:18 +00:00
echo " --output <output debfile> The full path to which the package will be written."
echo " --package-name <package name> Package to identify during installation. Example - 'dotnet-nightly', 'dotnet'"
2016-03-18 08:54:40 +00:00
echo " --framework-nuget-name <name> The name of the nuget package that produced this shared framework."
echo " --framework-nuget-version <ver> The versionf of the nuget package that produced this shared framework."
2016-03-09 20:15:06 +00:00
echo " --previous-version-url <url> Url to the previous version of the debian packge against which to run the upgrade tests."
2016-03-10 08:21:09 +00:00
echo " --obj-root <object root> Root folder for intermediate objects."
2015-10-21 19:46:24 +00:00
exit 1
2016-03-08 23:33:18 +00:00
}
2016-03-09 20:15:06 +00:00
parseargs( ) {
while [ [ $# > 0 ] ] ; do
lowerI = " $( echo $1 | awk '{print tolower($0)}' ) "
case $lowerI in
2016-03-08 23:33:18 +00:00
-m| --manpages)
MANPAGE_DIR = $2
shift
; ;
-o| --output)
OUTPUT_DEBIAN_FILE = $2
shift
; ;
-i| --input)
REPO_BINARIES_DIR = $2
shift
; ;
-p| --package-name)
DOTNET_DEB_PACKAGE_NAME = $2
shift
; ;
-v| --version)
DOTNET_CLI_VERSION = $2
shift
; ;
2016-03-09 20:15:06 +00:00
--previous-version-url)
PREVIOUS_VERSION_URL = $2
2016-03-08 23:33:18 +00:00
shift
; ;
2016-03-22 18:40:57 +00:00
--framework-debian-package-name)
SHARED_FRAMEWORK_DEBIAN_PACKAGE_NAME = $2
shift
; ;
2016-03-15 23:41:18 +00:00
--framework-nuget-name)
SHARED_FRAMEWORK_NUGET_NAME = $2
shift
; ;
--framework-nuget-version)
SHARED_FRAMEWORK_NUGET_VERSION = $2
shift
; ;
2016-03-10 08:21:09 +00:00
--obj-root)
OBJECT_DIR = $2
shift
; ;
2016-03-08 23:33:18 +00:00
--help)
help
; ;
*)
break
; ;
2016-03-09 20:15:06 +00:00
esac
shift
done
if [ -z " $DOTNET_CLI_VERSION " ] ; then
echo "Provide a version number. Missing option '--version'" && help
fi
if [ -z " $OUTPUT_DEBIAN_FILE " ] ; then
echo "Provide an output deb. Missing option '--output'" && help
fi
if [ -z " $REPO_BINARIES_DIR " ] ; then
echo "Provide an input directory. Missing option '--input'" && help
fi
if [ -z " $DOTNET_DEB_PACKAGE_NAME " ] ; then
echo "Provide an the name for the debian package. Missing option '--package-name'" && help
fi
2016-03-22 16:01:36 +00:00
2016-03-18 08:54:40 +00:00
if [ -z " $SHARED_FRAMEWORK_NUGET_NAME " ] ; then
echo "Provide the NuGet name of the targetted Shared Framework. Missing option '--framework-nuget-name'" && help
fi
2016-03-22 18:14:29 +00:00
if [ -z " $PREVIOUS_VERSION_URL " ] ; then
echo "Provide a URL to the previous debian pacakge (Required for running upgrade tests). Missing option '--previous-version-url'" && help
fi
2016-03-18 08:54:40 +00:00
if [ -z " $SHARED_FRAMEWORK_NUGET_VERSION " ] ; then
echo "Provide the NuGet version of the targetted Shared Framework. Missing option '--framework-nuget-version'" && help
fi
2016-03-09 20:15:06 +00:00
if [ ! -d " $REPO_BINARIES_DIR " ] ; then
echo " ' $REPO_BINARIES_DIR ' - is either missing or not a directory " 1>& 2
exit 1
fi
}
2016-03-22 18:40:57 +00:00
parseargs " $@ "
2015-10-21 19:46:24 +00:00
2016-01-07 00:46:25 +00:00
PACKAGING_ROOT = " $REPOROOT /packaging/debian "
2016-02-09 19:57:43 +00:00
PACKAGING_TOOL_DIR = " $REPOROOT /tools/DebianPackageTool "
2015-10-21 19:46:24 +00:00
2016-03-10 08:21:09 +00:00
PACKAGE_OUTPUT_DIR = " $OBJECT_DIR /deb_output "
PACKAGE_LAYOUT_DIR = " $OBJECT_DIR /deb_intermediate "
TEST_STAGE_DIR = " $OBJECT_DIR /debian_tests "
2016-01-13 08:08:19 +00:00
2016-03-09 02:51:58 +00:00
# remove any residual deb files from earlier builds
rm -f " $PACKAGE_OUTPUT_DIR /*.deb "
2015-12-02 19:52:19 +00:00
execute_build( ) {
2015-10-21 19:46:24 +00:00
create_empty_debian_layout
copy_files_to_debian_layout
2016-03-15 23:41:18 +00:00
update_debian_json
2015-10-21 19:46:24 +00:00
create_debian_package
}
2015-12-02 19:52:19 +00:00
execute_test( ) {
test_debian_package
}
2015-10-21 19:46:24 +00:00
create_empty_debian_layout( ) {
2015-11-11 01:30:01 +00:00
header "Creating empty debian package layout"
2015-10-29 17:33:39 +00:00
2016-01-07 00:46:25 +00:00
rm -rf " $PACKAGE_LAYOUT_DIR "
mkdir -p " $PACKAGE_LAYOUT_DIR "
2015-10-21 19:46:24 +00:00
mkdir " $PACKAGE_LAYOUT_DIR /\$ "
mkdir " $PACKAGE_LAYOUT_DIR /package_root "
mkdir " $PACKAGE_LAYOUT_DIR /samples "
mkdir " $PACKAGE_LAYOUT_DIR /docs "
}
copy_files_to_debian_layout( ) {
2015-11-11 01:30:01 +00:00
header "Copying files to debian layout"
2015-10-29 17:33:39 +00:00
2015-10-21 19:46:24 +00:00
# Copy Built Binaries
cp -a " $REPO_BINARIES_DIR /. " " $PACKAGE_LAYOUT_DIR /package_root "
# Copy config file
2016-03-22 21:14:54 +00:00
cp " $PACKAGING_ROOT /dotnet-debian_config.json " " $PACKAGE_LAYOUT_DIR /debian_config.json "
2015-12-30 00:42:24 +00:00
# Copy Manpages
2016-03-22 22:14:00 +00:00
cp -a " $MANPAGE_DIR /sdk/. " " $PACKAGE_LAYOUT_DIR /docs "
2016-04-01 20:41:31 +00:00
# Append Version to all manpage files
for manpage in " $PACKAGE_LAYOUT_DIR /docs/ " *.1; do mv " $manpage " " ${ manpage %.1 } " ; done
for manpage in " $PACKAGE_LAYOUT_DIR /docs/ " *; do mv " $manpage " " ${ manpage } - ${ DOTNET_CLI_VERSION } .1 " ; done
2016-04-02 02:07:16 +00:00
# Copy postinstall
cp " $PACKAGING_ROOT /postinst " " $PACKAGE_LAYOUT_DIR / $"
2015-10-21 19:46:24 +00:00
}
create_debian_package( ) {
2015-11-11 01:30:01 +00:00
header "Packing .deb"
2015-10-29 17:33:39 +00:00
2016-01-07 00:46:25 +00:00
mkdir -p " $PACKAGE_OUTPUT_DIR "
2016-01-12 23:27:02 +00:00
2016-03-22 22:36:17 +00:00
" $PACKAGING_TOOL_DIR /package_tool " -i " $PACKAGE_LAYOUT_DIR " -o " $PACKAGE_OUTPUT_DIR " -v $DOTNET_CLI_VERSION -n " $DOTNET_DEB_PACKAGE_NAME "
2015-10-21 19:46:24 +00:00
}
2016-03-15 23:41:18 +00:00
update_debian_json( )
{
header "Updating debian.json file"
2016-03-22 18:40:57 +00:00
sed -i " s/%SHARED_FRAMEWORK_DEBIAN_PACKAGE_NAME%/ $SHARED_FRAMEWORK_DEBIAN_PACKAGE_NAME /g " " $PACKAGE_LAYOUT_DIR " /debian_config.json
2016-03-15 23:41:18 +00:00
sed -i " s/%SHARED_FRAMEWORK_NUGET_NAME%/ $SHARED_FRAMEWORK_NUGET_NAME /g " " $PACKAGE_LAYOUT_DIR " /debian_config.json
sed -i " s/%SHARED_FRAMEWORK_NUGET_VERSION%/ $SHARED_FRAMEWORK_NUGET_VERSION /g " " $PACKAGE_LAYOUT_DIR " /debian_config.json
2016-03-18 08:54:40 +00:00
sed -i " s/%SDK_NUGET_VERSION%/ $DOTNET_CLI_VERSION /g " " $PACKAGE_LAYOUT_DIR " /debian_config.json
2016-03-15 23:41:18 +00:00
}
2015-10-22 17:13:05 +00:00
test_debian_package( ) {
2015-11-11 01:30:01 +00:00
header "Testing debian package"
2016-01-13 08:08:19 +00:00
2016-02-18 23:47:26 +00:00
install_bats
run_package_integrity_tests
}
install_bats( ) {
2015-12-05 01:24:30 +00:00
rm -rf $TEST_STAGE_DIR
2015-12-02 19:52:19 +00:00
git clone https://github.com/sstephenson/bats.git $TEST_STAGE_DIR
2016-02-18 23:47:26 +00:00
}
run_package_integrity_tests( ) {
# Set LAST_VERSION_URL to enable upgrade tests
2016-03-22 18:40:57 +00:00
# Temporarily disable last version until we have one with shared fx
# export LAST_VERSION_URL="$PREVIOUS_VERSION_URL"
2016-02-18 23:47:26 +00:00
$TEST_STAGE_DIR /bin/bats $PACKAGE_OUTPUT_DIR /test_package.bats
2015-10-22 17:13:05 +00:00
}
2015-12-02 19:52:19 +00:00
execute_build
2015-10-27 21:19:04 +00:00
DEBIAN_FILE = $( find $PACKAGE_OUTPUT_DIR -iname "*.deb" )
2015-12-02 19:52:19 +00:00
execute_test
2016-03-09 02:51:58 +00:00
mv -f " $DEBIAN_FILE " " $OUTPUT_DEBIAN_FILE "