blob: 5bc2b6967bd052fd05e3bfb7e5f853ce0aafaf69 [file] [log] [blame]
#!/bin/bash
# Copyright 2017 The Fuchsia Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
### create and publish packages from a build directory
## usage: fx publish [--build-dir <DIR>] [--pkg-key <key file>]
## [--far-dir <DIR>] [--update-repo <DIR>] [pkg1 pkg2 ...]
##
## One or more package name arguments may be supplied as the last arguments.
## If no package name is supplied, all packages from the current build output
## will be published.
##
## optional arguments:
## --build-dir Directory containing the build output
## --pkg-key Key used to sign the package's meta FAR
## --fars-dir Directory to be used to build the meta FAR
## --update-repo Directory to be used to publish the meta FAR and
## associated content blobs
## --mono-versions Base the repository versioning on monotonically
## increasing values instead of time since epoch
source "$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"/lib/vars.sh
fx-config-read
function usage {
fx-command-help publish
}
# Create a package manager package and then create update files which are
# published to the local file system. If no package name is supplied, all
# built packages are processed.
function main {
fx-standard-switches "$@"
set -- "${FX_ARGV[@]}"
local build_dir=""
local fuchsia_dir="${FUCHSIA_DIR}"
local argz=()
local c=0
local has_dir=0
local mono_version=0
# first parse the non-pkg args which should be named
while (( "$#" )); do
case $1 in
# treat build-dir specially since we inject it if not supplied
--build-dir)
argz+=($1)
shift
build_dir=$1
argz+=($1)
shift
has_dir=1
;;
--mono-versions)
mono_version=1
shift
;;
--*)
argz+=($1)
shift
# seems like the current arg is a boolean, skip to the next
if [[ $1 == --* ]]; then
continue
else
argz+=($1)
shift
fi
;;
*)
break
;;
esac
done
# now process the trailing args which are all interpretted as packages
while (( "$#" )); do
case $1 in
--*)
echo "Non-package arg detected in packages section"
usage
exit 1
;;
*)
argz+=("--pkgs")
argz+=($1)
shift
;;
esac
done
if [[ mono_version -eq 1 ]]; then
argz+=("--ver-scheme" "mono")
else
argz+=("--ver-scheme" "time")
fi
# no build directory, use the default
if [[ has_dir -eq 0 ]]; then
build_dir="${FUCHSIA_BUILD_DIR}"
argz+=("--build-dir" "${build_dir}")
elif [[ -z "${build_dir}" ]]; then
# the arg was passed, but wasn't acutally set
echo >&2 "error: Build directory is not set!"
return 1
fi
(cd "${FUCHSIA_BUILD_DIR}" && ${fuchsia_dir}/scripts/publish-package.py "${argz[@]}")
local rc=$?
if [[ $rc -ne 0 ]]; then
usage
return $rc
fi
}
main "$@"