From f952988fb34a266b64953b23db6c76ad2777dc4a Mon Sep 17 00:00:00 2001 From: Joshua Boniface Date: Sat, 19 Jan 2019 01:22:41 -0500 Subject: Add new centralized build script and README --- build | 199 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 199 insertions(+) create mode 100755 build (limited to 'build') diff --git a/build b/build new file mode 100755 index 0000000000..e9c288ff53 --- /dev/null +++ b/build @@ -0,0 +1,199 @@ +#!/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 " + echo -e " $ build [-b/--web-branch ] " + 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/'." +} + +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 ' 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 -- cgit v1.2.3 From 85966b54fb6305402deef05fde2289a3e2568a6a Mon Sep 17 00:00:00 2001 From: Joshua Boniface Date: Sat, 19 Jan 2019 21:19:42 -0500 Subject: Small formatting consistency tweak --- build | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'build') diff --git a/build b/build index e9c288ff53..98f2e622a4 100755 --- a/build +++ b/build @@ -167,7 +167,7 @@ fi git fetch --all git checkout origin/${web_branch} || { - echo "Error: 'jellyfin-web' branch ${web_branch} is invalid." + echo "ERROR: 'jellyfin-web' branch ${web_branch} is invalid." exit 1 } popd -- cgit v1.2.3 From 4f14b479bb04cb73b6adc3b186b07650a1a34db3 Mon Sep 17 00:00:00 2001 From: Joshua Boniface Date: Sat, 19 Jan 2019 21:56:00 -0500 Subject: Bashify all variable references --- build | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) (limited to 'build') diff --git a/build b/build index 98f2e622a4..fc021397cc 100755 --- a/build +++ b/build @@ -50,7 +50,7 @@ fi if [[ $1 == '--list-actions' ]]; then platform="$2" if [[ ! " ${platforms[@]} " =~ " ${platform} " ]]; then - echo "ERROR: Platform $platform does not exist." + echo "ERROR: Platform ${platform} does not exist." exit 1 fi echo -e "Available actions for platform ${platform}:" @@ -78,11 +78,11 @@ else echo "ERROR: A platform must be specified. Use 'all' to specify all platforms." exit 1 fi -if [[ $cli_platform == 'all' ]]; then +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." + echo "ERROR: Platform ${cli_platform} is invalid. Use the '--list-platforms' option to list available platforms." exit 1 else declare -a platform=( "${cli_platform}" ) @@ -97,11 +97,11 @@ else echo "ERROR: An action must be specified. Use 'all' to specify all actions." exit 1 fi -if [[ $cli_action == 'all' ]]; then +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 ' option to list available actions." + echo "ERROR: Action ${cli_action} is invalid. Use the '--list-actions ' option to list available actions." exit 1 else declare -a action=( "${cli_action}" ) -- cgit v1.2.3 From 99dfb8549f3c2a633e15efc64c51cb8a7b78bd86 Mon Sep 17 00:00:00 2001 From: Joshua Boniface Date: Sat, 19 Jan 2019 21:57:29 -0500 Subject: Use the same branch for web by default --- build | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'build') diff --git a/build b/build index fc021397cc..f50311d0a2 100755 --- a/build +++ b/build @@ -26,7 +26,7 @@ usage() { echo -e " $ build --list-actions " echo -e " $ build [-b/--web-branch ] " echo -e "" - echo -e "The web_branch defaults to 'master'." + echo -e "The web_branch defaults to the same branch name as the current main branch." 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/'." @@ -67,7 +67,7 @@ if [[ $1 == '-b' || $1 == '--web-branch' ]]; then web_branch="$2" shift 2 else - web_branch="master" + web_branch="$( git branch 2>/dev/null | sed -e '/^[^*]/d' -e 's/* \(.*\)/\1/' )" fi # Parse platform option -- cgit v1.2.3 From bc18d5341c09bb3e5c122b0e447bb134ce62d81e Mon Sep 17 00:00:00 2001 From: Joshua Boniface Date: Sat, 19 Jan 2019 22:02:19 -0500 Subject: Make help and usage setup standards-compliant --- build | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 'build') diff --git a/build b/build index f50311d0a2..9047dd816b 100755 --- a/build +++ b/build @@ -32,7 +32,13 @@ usage() { echo -e "Build output files are collected at '../jellyfin-build/'." } +# Show usage on stderr with exit 1 on argless if [[ -z $1 ]]; then + usage >&2 + exit 1 +fi +# Show usage if -h or --help are specified in the args +if [[ $@ =~ '-h' || $@ =~ '--help' ]]; then usage exit 0 fi -- cgit v1.2.3 From 3320d4feeb22b2015c26a17309818465cf7272b0 Mon Sep 17 00:00:00 2001 From: Joshua Boniface Date: Sun, 20 Jan 2019 12:33:15 -0500 Subject: Move dotnet to a per-platform dependency --- build | 3 +-- deployment/debian-x64/dependencies.txt | 1 + deployment/linux-x64/dependencies.txt | 1 + deployment/osx-x64/dependencies.txt | 1 + deployment/ubuntu-x64/dependencies.txt | 1 + deployment/win-generic/dependencies.txt | 1 + deployment/win-x64/dependencies.txt | 1 + deployment/win-x86/dependencies.txt | 1 + 8 files changed, 8 insertions(+), 2 deletions(-) create mode 100644 deployment/debian-x64/dependencies.txt create mode 100644 deployment/linux-x64/dependencies.txt create mode 100644 deployment/osx-x64/dependencies.txt create mode 100644 deployment/ubuntu-x64/dependencies.txt create mode 100644 deployment/win-generic/dependencies.txt create mode 100644 deployment/win-x64/dependencies.txt create mode 100644 deployment/win-x86/dependencies.txt (limited to 'build') diff --git a/build b/build index 9047dd816b..c2daddd84a 100755 --- a/build +++ b/build @@ -15,8 +15,7 @@ declare -a platforms=( $( # 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' ) +declare -a dependencies=( 'tar' 'zip' ) usage() { echo -e "build - build Jellyfin binaries or packages" diff --git a/deployment/debian-x64/dependencies.txt b/deployment/debian-x64/dependencies.txt new file mode 100644 index 0000000000..3d25d1bdf4 --- /dev/null +++ b/deployment/debian-x64/dependencies.txt @@ -0,0 +1 @@ +dotnet diff --git a/deployment/linux-x64/dependencies.txt b/deployment/linux-x64/dependencies.txt new file mode 100644 index 0000000000..3d25d1bdf4 --- /dev/null +++ b/deployment/linux-x64/dependencies.txt @@ -0,0 +1 @@ +dotnet diff --git a/deployment/osx-x64/dependencies.txt b/deployment/osx-x64/dependencies.txt new file mode 100644 index 0000000000..3d25d1bdf4 --- /dev/null +++ b/deployment/osx-x64/dependencies.txt @@ -0,0 +1 @@ +dotnet diff --git a/deployment/ubuntu-x64/dependencies.txt b/deployment/ubuntu-x64/dependencies.txt new file mode 100644 index 0000000000..3d25d1bdf4 --- /dev/null +++ b/deployment/ubuntu-x64/dependencies.txt @@ -0,0 +1 @@ +dotnet diff --git a/deployment/win-generic/dependencies.txt b/deployment/win-generic/dependencies.txt new file mode 100644 index 0000000000..3d25d1bdf4 --- /dev/null +++ b/deployment/win-generic/dependencies.txt @@ -0,0 +1 @@ +dotnet diff --git a/deployment/win-x64/dependencies.txt b/deployment/win-x64/dependencies.txt new file mode 100644 index 0000000000..3d25d1bdf4 --- /dev/null +++ b/deployment/win-x64/dependencies.txt @@ -0,0 +1 @@ +dotnet diff --git a/deployment/win-x86/dependencies.txt b/deployment/win-x86/dependencies.txt new file mode 100644 index 0000000000..3d25d1bdf4 --- /dev/null +++ b/deployment/win-x86/dependencies.txt @@ -0,0 +1 @@ +dotnet -- cgit v1.2.3 From 0dab69b5519499f7bee7d85188ebe5628957a507 Mon Sep 17 00:00:00 2001 From: Joshua Boniface Date: Mon, 21 Jan 2019 01:42:25 -0500 Subject: Use basename for cross-platform operation Trying to sed out the deployment/ failed on MacOS, so use the basename command instead for the same effect. --- build | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'build') diff --git a/build b/build index c2daddd84a..b922cf72a9 100755 --- a/build +++ b/build @@ -10,7 +10,7 @@ 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 + find deployment/ -maxdepth 1 -mindepth 1 -type d -exec basename {} \; | sort ) ) # The list of standard dependencies required by all build scripts; individual -- cgit v1.2.3 From cf85e2327ed8fc0c3bdb54b08b5708b31bb0262d Mon Sep 17 00:00:00 2001 From: Joshua Boniface Date: Mon, 21 Jan 2019 12:10:48 -0500 Subject: Support trying local branches in submodule --- build | 18 ++++++++++++++---- bump_version | 18 ++++++++++++++---- 2 files changed, 28 insertions(+), 8 deletions(-) (limited to 'build') diff --git a/build b/build index b922cf72a9..5c081af6e5 100755 --- a/build +++ b/build @@ -171,10 +171,20 @@ if ! git diff-index --quiet HEAD --; then fi git fetch --all -git checkout origin/${web_branch} || { - echo "ERROR: 'jellyfin-web' branch ${web_branch} is invalid." - exit 1 -} +# If this is an official branch name, fetch it from origin +official_branches_regex="^master$|^dev$|^release-.*$|^hotfix-.*$" +if [[ ${web_branch} =~ ${official_branches_regex} ]]; then + git checkout origin/${web_branch} || { + echo "ERROR: 'jellyfin-web' branch 'origin/${web_branch}' is invalid." + exit 1 + } +# Otherwise, just check out the local branch (for testing, etc.) +else + git checkout ${web_branch} || { + echo "ERROR: 'jellyfin-web' branch '${web_branch}' is invalid." + exit 1 + } +fi popd # Execute each platform and action in order, if said action is enabled diff --git a/bump_version b/bump_version index 0db6c18ad6..c3f1a78d50 100755 --- a/bump_version +++ b/bump_version @@ -47,10 +47,20 @@ if ! git diff-index --quiet HEAD --; then fi git fetch --all -git checkout origin/${web_branch} || { - echo "ERROR: 'jellyfin-web' branch ${web_branch} is invalid." - exit 1 -} +# If this is an official branch name, fetch it from origin +official_branches_regex="^master$|^dev$|^release-.*$|^hotfix-.*$" +if [[ ${web_branch} =~ ${official_branches_regex} ]]; then + git checkout origin/${web_branch} || { + echo "ERROR: 'jellyfin-web' branch 'origin/${web_branch}' is invalid." + exit 1 + } +# Otherwise, just check out the local branch (for testing, etc.) +else + git checkout ${web_branch} || { + echo "ERROR: 'jellyfin-web' branch '${web_branch}' is invalid." + exit 1 + } +fi popd new_version="$1" -- cgit v1.2.3 From e30cf63aefbb293f742cfe4b9949f72241ca98af Mon Sep 17 00:00:00 2001 From: Joshua Boniface Date: Mon, 21 Jan 2019 16:31:42 -0500 Subject: Add helpful time text around platform builds --- build | 3 +++ 1 file changed, 3 insertions(+) (limited to 'build') diff --git a/build b/build index 5c081af6e5..7d49db72ab 100755 --- a/build +++ b/build @@ -191,6 +191,7 @@ popd pushd deployment/ for target_platform in ${platform[@]}; do echo -e "> Processing platform ${target_platform}" + date_start=$( date +%s ) pushd ${target_platform} for target_action in ${action[@]}; do echo -e ">> Processing action ${target_action}" @@ -209,6 +210,8 @@ for target_platform in ${platform[@]}; do ./clean.sh fi fi + date_end=$( date +%s ) + echo -e "> Completed platform ${target_platform} in $( expr ${date_end} - ${date_start} ) seconds." popd done popd -- cgit v1.2.3