Hash :
4c48bec9
Author :
Thomas de Grivel
Date :
2023-01-11T10:05:17
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 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141
#!/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
SHPKG_REPO_INDEX="${SHPKG_DIR}/repo_index"
if ! [ -f "$SHPKG_REPO_INDEX" ]; then
echo "$SHPKG_REPO_INDEX: not found" >&2
exit 1
fi
shpkg_src_dir () {
shpkg_get "$@" | cut -d ' ' -f 2
}
shpkg_get () {
[ "x$#" = "x1" ] || return 1
grep "^$1 " "${SHPKG_REPO_INDEX}"
}
shpkg_git_url () {
shpkg_get "$@" | cut -d ' ' -f 3
}
shpkg_clone () {
for REPO; do
SHPKG_REPO_SRC_DIR="$(shpkg_src_dir "$REPO")"
SHPKG_REPO_PARENT_DIR="$(shpkg_src_parent_dir "$REPO")"
SHPKG_REPO_GIT_URL="$(shpkg_git_url "$REPO")"
SHPKG_REPO_BASENAME="$(basename "$SHPKG_REPO_SRC_DIR")"
if ! [ -d "${SHPKG_SRC_DIR}/$SHPKG_REPO_SRC_DIR" ]; then
verbose mkdir -p "${SHPKG_SRC_DIR}/$SHPKG_REPO_PARENT_DIR"
( verbose cd "${SHPKG_SRC_DIR}/$SHPKG_REPO_PARENT_DIR" &&
verbose git clone "$SHPKG_REPO_GIT_URL" \
"$SHPKG_REPO_BASENAME" &&
cd "$SHPKG_REPO_BASENAME" &&
verbose git submodule init &&
verbose git submodule update
)
fi
done
}
shpkg_fetch () {
for REPO; do
SHPKG_REPO_SRC_DIR="$(shpkg_src_dir "$REPO")"
( verbose cd "${SHPKG_SRC_DIR}/$SHPKG_REPO_SRC_DIR" &&
verbose git fetch
)
done
}
shpkg_pull () {
for REPO; do
SHPKG_REPO_SRC_DIR="$(shpkg_src_dir "$REPO")"
( verbose cd "${SHPKG_SRC_DIR}/$SHPKG_REPO_SRC_DIR" &&
verbose git pull
)
done
}
shpkg_src_parent_dir () {
dirname "$(shpkg_src_dir "$REPO")"
}
shpkg_remove () {
for REPO; do
SHPKG_REPO_SRC_DIR="$(shpkg_src_dir "$REPO")"
SHPKG_REPO_PARENT_DIR="$(shpkg_src_parent_dir "$REPO")"
verbose rm -rf "${SHPKG_SRC_DIR}/$SHPKG_REPO_SRC_DIR"
rmdir "${SHPKG_SRC_DIR}/$SHPKG_REPO_PARENT_DIR" 2>/dev/null || true
done
}
# Building from sources
shpkg_build () {
shpkg_configure "$@"
for REPO; do
SHPKG_REPO_SRC_DIR="$(shpkg_src_dir "$REPO")"
if [ -f "${SHPKG_SRC_DIR}/${SHPKG_REPO_SRC_DIR}/Makefile" ]; then
( verbose cd "${SHPKG_SRC_DIR}/$SHPKG_REPO_SRC_DIR" &&
verbose make; )
fi
done
}
shpkg_configure () {
shpkg_clone "$@"
for REPO; do
SHPKG_REPO_SRC_DIR="$(shpkg_src_dir "$REPO")"
if [ -x "${SHPKG_SRC_DIR}/${SHPKG_REPO_SRC_DIR}/configure" ]; then
( verbose cd "${SHPKG_SRC_DIR}/$SHPKG_REPO_SRC_DIR" &&
verbose ./configure --prefix "$SHPKG_DIR"; )
elif [ -x "${SHPKG_SRC_DIR}/${SHPKG_REPO_SRC_DIR}/configure.sh" ]; then
( verbose cd "${SHPKG_SRC_DIR}/$SHPKG_REPO_SRC_DIR" &&
verbose ./configure.sh --prefix "$SHPKG_DIR"; )
fi
done
}
# misc
shpkg_install () {
shpkg_build "$@"
for REPO; do
SHPKG_REPO_SRC_DIR="$(shpkg_src_dir "$REPO")"
if [ -f "${SHPKG_SRC_DIR}/${SHPKG_REPO_SRC_DIR}/Makefile" ]; then
( verbose cd "${SHPKG_SRC_DIR}/$SHPKG_REPO_SRC_DIR" &&
verbose make install; )
fi
done
}
shpkg_uninstall () {
for REPO; do
SHPKG_REPO_SRC_DIR="$(shpkg_src_dir "$REPO")"
if [ -f "${SHPKG_SRC_DIR}/${SHPKG_REPO_SRC_DIR}/Makefile" ]; then
( verbose cd "${SHPKG_SRC_DIR}/$SHPKG_REPO_SRC_DIR" &&
verbose make uninstall; )
fi
done
}
shpkg_upgrade () {
verbose shpkg_pull "$@"
verbose shpkg_build "$@"
verbose shpkg_install "$@"
}
verbose () {
echo "$@"
"$@"
}