2019-01-19 06:22:41 +00:00
|
|
|
#!/usr/bin/env bash
|
|
|
|
|
|
|
|
# build - build Jellyfin binaries or packages
|
|
|
|
|
|
|
|
set -o errexit
|
|
|
|
set -o pipefail
|
|
|
|
|
|
|
|
# The list of possible package actions (except 'clean')
|
|
|
|
declare -a actions=( 'build' 'package' 'sign' 'publish' )
|
|
|
|
|
|
|
|
# The list of possible platforms, based on directories under 'deployment/'
|
|
|
|
declare -a platforms=( $(
|
|
|
|
find deployment/ -maxdepth 1 -mindepth 1 -type d | sed 's/deployment\///' | sort
|
|
|
|
) )
|
|
|
|
|
|
|
|
# The list of standard dependencies required by all build scripts; individual
|
|
|
|
# action scripts may specify their own dependencies
|
2019-01-20 17:33:15 +00:00
|
|
|
declare -a dependencies=( 'tar' 'zip' )
|
2019-01-19 06:22:41 +00:00
|
|
|
|
|
|
|
usage() {
|
|
|
|
echo -e "build - build Jellyfin binaries or packages"
|
|
|
|
echo -e ""
|
|
|
|
echo -e "Usage:"
|
|
|
|
echo -e " $ build --list-platforms"
|
|
|
|
echo -e " $ build --list-actions <platform>"
|
|
|
|
echo -e " $ build [-b/--web-branch <web_branch>] <platform> <action>"
|
|
|
|
echo -e ""
|
2019-01-20 02:57:29 +00:00
|
|
|
echo -e "The web_branch defaults to the same branch name as the current main branch."
|
2019-01-19 06:22:41 +00:00
|
|
|
echo -e "To build all platforms, use 'all'."
|
|
|
|
echo -e "To perform all build actions, use 'all'."
|
|
|
|
echo -e "Build output files are collected at '../jellyfin-build/<platform>'."
|
|
|
|
}
|
|
|
|
|
2019-01-20 03:02:19 +00:00
|
|
|
# Show usage on stderr with exit 1 on argless
|
2019-01-19 06:22:41 +00:00
|
|
|
if [[ -z $1 ]]; then
|
2019-01-20 03:02:19 +00:00
|
|
|
usage >&2
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
# Show usage if -h or --help are specified in the args
|
|
|
|
if [[ $@ =~ '-h' || $@ =~ '--help' ]]; then
|
2019-01-19 06:22:41 +00:00
|
|
|
usage
|
|
|
|
exit 0
|
|
|
|
fi
|
|
|
|
|
|
|
|
# List all available platforms then exit
|
|
|
|
if [[ $1 == '--list-platforms' ]]; then
|
|
|
|
echo -e "Available platforms:"
|
|
|
|
for platform in ${platforms[@]}; do
|
|
|
|
echo -e " ${platform}"
|
|
|
|
done
|
|
|
|
exit 0
|
|
|
|
fi
|
|
|
|
|
|
|
|
# List all available actions for a given platform then exit
|
|
|
|
if [[ $1 == '--list-actions' ]]; then
|
|
|
|
platform="$2"
|
|
|
|
if [[ ! " ${platforms[@]} " =~ " ${platform} " ]]; then
|
2019-01-20 02:56:00 +00:00
|
|
|
echo "ERROR: Platform ${platform} does not exist."
|
2019-01-19 06:22:41 +00:00
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
echo -e "Available actions for platform ${platform}:"
|
|
|
|
for action in ${actions[@]}; do
|
|
|
|
if [[ -f deployment/${platform}/${action}.sh ]]; then
|
|
|
|
echo -e " ${action}"
|
|
|
|
fi
|
|
|
|
done
|
|
|
|
exit 0
|
|
|
|
fi
|
|
|
|
|
|
|
|
# Parse branch option
|
|
|
|
if [[ $1 == '-b' || $1 == '--web-branch' ]]; then
|
|
|
|
web_branch="$2"
|
|
|
|
shift 2
|
|
|
|
else
|
2019-01-20 02:57:29 +00:00
|
|
|
web_branch="$( git branch 2>/dev/null | sed -e '/^[^*]/d' -e 's/* \(.*\)/\1/' )"
|
2019-01-19 06:22:41 +00:00
|
|
|
fi
|
|
|
|
|
|
|
|
# Parse platform option
|
|
|
|
if [[ -n $1 ]]; then
|
|
|
|
cli_platform="$1"
|
|
|
|
shift
|
|
|
|
else
|
|
|
|
echo "ERROR: A platform must be specified. Use 'all' to specify all platforms."
|
|
|
|
exit 1
|
|
|
|
fi
|
2019-01-20 02:56:00 +00:00
|
|
|
if [[ ${cli_platform} == 'all' ]]; then
|
2019-01-19 06:22:41 +00:00
|
|
|
declare -a platform=( ${platforms[@]} )
|
|
|
|
else
|
|
|
|
if [[ ! " ${platforms[@]} " =~ " ${cli_platform} " ]]; then
|
2019-01-20 02:56:00 +00:00
|
|
|
echo "ERROR: Platform ${cli_platform} is invalid. Use the '--list-platforms' option to list available platforms."
|
2019-01-19 06:22:41 +00:00
|
|
|
exit 1
|
|
|
|
else
|
|
|
|
declare -a platform=( "${cli_platform}" )
|
|
|
|
fi
|
|
|
|
fi
|
|
|
|
|
|
|
|
# Parse action option
|
|
|
|
if [[ -n $1 ]]; then
|
|
|
|
cli_action="$1"
|
|
|
|
shift
|
|
|
|
else
|
|
|
|
echo "ERROR: An action must be specified. Use 'all' to specify all actions."
|
|
|
|
exit 1
|
|
|
|
fi
|
2019-01-20 02:56:00 +00:00
|
|
|
if [[ ${cli_action} == 'all' ]]; then
|
2019-01-19 06:22:41 +00:00
|
|
|
declare -a action=( ${actions[@]} )
|
|
|
|
else
|
|
|
|
if [[ ! " ${actions[@]} " =~ " ${cli_action} " ]]; then
|
2019-01-20 02:56:00 +00:00
|
|
|
echo "ERROR: Action ${cli_action} is invalid. Use the '--list-actions <platform>' option to list available actions."
|
2019-01-19 06:22:41 +00:00
|
|
|
exit 1
|
|
|
|
else
|
|
|
|
declare -a action=( "${cli_action}" )
|
|
|
|
fi
|
|
|
|
fi
|
|
|
|
|
|
|
|
# Verify required utilities are installed
|
|
|
|
missing_deps=()
|
|
|
|
for utility in ${dependencies[@]}; do
|
|
|
|
if ! which ${utility} &>/dev/null; then
|
|
|
|
missing_deps+=( ${utility} )
|
|
|
|
fi
|
|
|
|
done
|
|
|
|
|
|
|
|
# Error if we're missing anything
|
|
|
|
if [[ ${#missing_deps[@]} -gt 0 ]]; then
|
|
|
|
echo -e "ERROR: This script requires the following missing utilities:"
|
|
|
|
for utility in ${missing_deps[@]}; do
|
|
|
|
echo -e " ${utility}"
|
|
|
|
done
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
|
|
|
# Parse platform-specific dependencies
|
|
|
|
for target_platform in ${platform[@]}; do
|
|
|
|
# Read platform-specific dependencies
|
|
|
|
if [[ -f deployment/${target_platform}/dependencies.txt ]]; then
|
|
|
|
platform_dependencies="$( grep -v '^#' deployment/${target_platform}/dependencies.txt )"
|
|
|
|
|
|
|
|
# Verify required utilities are installed
|
|
|
|
missing_deps=()
|
|
|
|
for utility in ${platform_dependencies[@]}; do
|
|
|
|
if ! which ${utility} &>/dev/null; then
|
|
|
|
missing_deps+=( ${utility} )
|
|
|
|
fi
|
|
|
|
done
|
|
|
|
|
|
|
|
# Error if we're missing anything
|
|
|
|
if [[ ${#missing_deps[@]} -gt 0 ]]; then
|
|
|
|
echo -e "ERROR: The ${target_platform} platform requires the following utilities:"
|
|
|
|
for utility in ${missing_deps[@]}; do
|
|
|
|
echo -e " ${utility}"
|
|
|
|
done
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
fi
|
|
|
|
done
|
|
|
|
|
|
|
|
# Initialize submodules
|
|
|
|
git submodule update --init --recursive
|
|
|
|
|
|
|
|
# configure branch
|
|
|
|
pushd MediaBrowser.WebDashboard/jellyfin-web
|
|
|
|
|
|
|
|
if ! git diff-index --quiet HEAD --; then
|
|
|
|
popd
|
|
|
|
echo
|
|
|
|
echo "ERROR: Your 'jellyfin-web' submodule working directory is not clean!"
|
|
|
|
echo "This script will overwrite your unstaged and unpushed changes."
|
|
|
|
echo "Please do development on 'jellyfin-web' outside of the submodule."
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
|
|
|
git fetch --all
|
|
|
|
git checkout origin/${web_branch} || {
|
2019-01-20 02:19:42 +00:00
|
|
|
echo "ERROR: 'jellyfin-web' branch ${web_branch} is invalid."
|
2019-01-19 06:22:41 +00:00
|
|
|
exit 1
|
|
|
|
}
|
|
|
|
popd
|
|
|
|
|
|
|
|
# Execute each platform and action in order, if said action is enabled
|
|
|
|
pushd deployment/
|
|
|
|
for target_platform in ${platform[@]}; do
|
|
|
|
echo -e "> Processing platform ${target_platform}"
|
|
|
|
pushd ${target_platform}
|
|
|
|
for target_action in ${action[@]}; do
|
|
|
|
echo -e ">> Processing action ${target_action}"
|
|
|
|
if [[ -f ${target_action}.sh && -x ${target_action}.sh ]]; then
|
|
|
|
./${target_action}.sh
|
|
|
|
fi
|
|
|
|
done
|
|
|
|
if [[ -d pkg-dist/ ]]; then
|
|
|
|
echo -e ">> Collecting build artifacts"
|
|
|
|
target_dir="../../../jellyfin-build/${target_platform}"
|
|
|
|
mkdir -p ${target_dir}
|
|
|
|
mv pkg-dist/* ${target_dir}/
|
|
|
|
|
|
|
|
echo -e ">> Processing action clean"
|
|
|
|
if [[ -f clean.sh && -x clean.sh ]]; then
|
|
|
|
./clean.sh
|
|
|
|
fi
|
|
|
|
fi
|
|
|
|
popd
|
|
|
|
done
|
|
|
|
popd
|