Hash :
28ad6fa5
Author :
Thomas de Grivel
Date :
2023-01-10T20:36:45
shpkg clone c3
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51
#!/bin/sh
# Copyright 2023 Thomas de Grivel <thodg@kmx.io>
set -e
# Config
SHPKG_DIR="${SHPKG_DIR:-~/shpkg}"
SHPKG_SRC_DIR="${SHPKG_SRC_DIR:-${SHPKG_DIR}/src}"
if ! [ -d "$SHPKG_SRC_DIR" ]; then
mkdir -p "$SHPKG_SRC_DIR"
fi
# Repo
REPO_INDEX="${SHPKG_DIR}/repo_index"
if ! [ -f "$REPO_INDEX" ]; then
echo "$REPO_INDEX: not found" >&2
exit 1
fi
# Repo routines
repo_dir () {
repo_find "$@" | cut -d ' ' -f 2
}
repo_find () {
[ "x$#" = "x1" ] || return 1
grep "^$1 " "${REPO_INDEX}"
}
repo_git_url () {
repo_find "$@" | cut -d ' ' -f 3
}
repo_install () {
for REPO; do
REPO_DIR="$(repo_dir "$REPO")"
REPO_PARENT_DIR="$(repo_parent_dir "$REPO")"
REPO_GIT_URL="$(repo_git_url "$REPO")"
REPO_BASENAME="$(basename "$REPO_DIR")"
if ! [ -d "$REPO_DIR" ]; then
mkdir -p "${SHPKG_SRC_DIR}/$REPO_PARENT_DIR"
( cd "${SHPKG_SRC_DIR}/$REPO_PARENT_DIR" &&
git clone "$REPO_GIT_URL" "$REPO_BASENAME"
)
fi
done
}
repo_parent_dir () {
dirname "$(repo_dir "$REPO")"
}