Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 22 additions & 14 deletions dstack/scripts/install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -57,35 +57,43 @@ cleanup() {
}
trap cleanup EXIT INT TERM

info() {
echo "$*" >&2
}

error() {
echo "error: $*" >&2
}

while [ "$#" -gt 0 ]; do
case "$1" in
--repo)
if [ "$#" -lt 2 ]; then
echo "error: --repo requires a URL" >&2
error "--repo requires a URL"
exit 1
fi
repo=$2
shift 2
;;
--ref)
if [ "$#" -lt 2 ]; then
echo "error: --ref requires a ref" >&2
error "--ref requires a ref"
exit 1
fi
ref=$2
shift 2
;;
--src)
if [ "$#" -lt 2 ]; then
echo "error: --src requires a directory" >&2
error "--src requires a directory"
exit 1
fi
src=$2
shift 2
;;
--prefix|--root)
if [ "$#" -lt 2 ]; then
echo "error: --prefix requires a directory" >&2
error "--prefix requires a directory"
exit 1
fi
prefix=$2
Expand All @@ -101,7 +109,7 @@ while [ "$#" -gt 0 ]; do
exit 0
;;
*)
echo "error: unknown option: $1" >&2
error "unknown option: $1"
usage >&2
exit 1
;;
Expand All @@ -110,7 +118,7 @@ done

need_cmd() {
if ! command -v "$1" >/dev/null 2>&1; then
echo "error: required command not found: $1" >&2
error "required command not found: $1"
exit 1
fi
}
Expand Down Expand Up @@ -170,10 +178,10 @@ resolve_source() {

if [ -n "$src" ] && [ -e "$src" ]; then
if ! is_checkout "$src" || ! git -C "$src" rev-parse --git-dir >/dev/null 2>&1; then
echo "error: $src exists but is not a dstack git checkout" >&2
error "$src exists but is not a dstack git checkout"
exit 1
fi
echo "updating dstack source in $src"
info "updating dstack source in $src"
(
cd "$src"
git fetch --tags origin
Expand All @@ -183,7 +191,7 @@ resolve_source() {
fi
)
elif [ -n "$src" ]; then
echo "cloning dstack source into $src"
info "cloning dstack source into $src"
git clone "$repo" "$src"
(
cd "$src"
Expand All @@ -194,7 +202,7 @@ resolve_source() {
need_cmd mktemp
tmp_src=$(mktemp -d "${TMPDIR:-/tmp}/dstack-install.XXXXXX")
src="$tmp_src/source"
echo "cloning dstack source into a temporary checkout"
info "cloning dstack source into a temporary checkout"
git clone "$repo" "$src"
(
cd "$src"
Expand All @@ -210,17 +218,17 @@ validate_prefix() {
case "$prefix" in
/*) ;;
*)
echo "error: --prefix must be an absolute path" >&2
error "--prefix must be an absolute path"
exit 1
;;
esac
if [ "$prefix" = "/" ]; then
echo "error: --prefix must not be /" >&2
error "--prefix must not be /"
exit 1
fi
case "$prefix" in
*"/../"*|*"/.."|*"/./"*|*"/.")
echo "error: --prefix must not contain . or .. path components" >&2
error "--prefix must not contain . or .. path components"
exit 1
;;
esac
Expand Down Expand Up @@ -266,7 +274,7 @@ install_bin() {
src_bin="$core_checkout/target/release/$1"
dest_bin="$bin_dir/$2"
if [ ! -f "$src_bin" ]; then
echo "error: expected binary not found: $src_bin" >&2
error "expected binary not found: $src_bin"
exit 1
fi
if [ -n "$sudo_cmd" ]; then
Expand Down