|
|
|
#!/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
|
|
|
|
declare -a dependencies
|
|
|
|
dependencies=( 'tar' 'zip' 'dotnet' )
|
|
|
|
|
|
|
|
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 ""
|
|
|
|
echo -e "The web_branch defaults to 'master'."
|
|
|
|
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>'."
|
|
|
|
}
|
|
|
|
|
|
|
|
if [[ -z $1 ]]; then
|
|
|
|
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
|
|
|
|
echo "ERROR: Platform $platform does not exist."
|
|
|
|
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
|
|
|
|
web_branch="master"
|
|
|
|
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
|
|
|
|
if [[ $cli_platform == 'all' ]]; then
|
|
|
|
declare -a platform=( ${platforms[@]} )
|
|
|
|
else
|
|
|
|
if [[ ! " ${platforms[@]} " =~ " ${cli_platform} " ]]; then
|
|
|
|
echo "ERROR: Platform $cli_platform is invalid. Use the '--list-platforms' option to list available platforms."
|
|
|
|
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
|
|
|
|
if [[ $cli_action == 'all' ]]; then
|
|
|
|
declare -a action=( ${actions[@]} )
|
|
|
|
else
|
|
|
|
if [[ ! " ${actions[@]} " =~ " ${cli_action} " ]]; then
|
|
|
|
echo "ERROR: Action $cli_action is invalid. Use the '--list-actions <platform>' option to list available actions."
|
|
|
|
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} || {
|
|
|
|
echo "ERROR: 'jellyfin-web' branch ${web_branch} is invalid."
|
|
|
|
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
|