feat: add system packaging (.rpm, .deb, .tar.gz) and Gitea Actions CI/CD release workflow
This commit is contained in:
1 parent
e5784db650
commit
a03d9a85e6
10 files changed
+834
No files matched your search
Executable
+125
@@ -0,0 +1,125 @@
|
||||
#!/usr/bin/env bash
|
||||
#
|
||||
# inventory-collector installation script
|
||||
# Installs inventory-collector to standard system directories.
|
||||
#
|
||||
set -euo pipefail
|
||||
|
||||
PREFIX="${PREFIX:-/usr}"
|
||||
DESTDIR="${DESTDIR:-}"
|
||||
|
||||
BIN_DIR="${DESTDIR}${PREFIX}/bin"
|
||||
LIB_DIR="${DESTDIR}${PREFIX}/lib/inventory-collector"
|
||||
ETC_DIR="${DESTDIR}/etc/inventory-collector"
|
||||
MAN_DIR="${DESTDIR}${PREFIX}/share/man/man1"
|
||||
BASH_COMP_DIR="${DESTDIR}${PREFIX}/share/bash-completion/completions"
|
||||
ZSH_COMP_DIR="${DESTDIR}${PREFIX}/share/zsh/site-functions"
|
||||
DOC_DIR="${DESTDIR}${PREFIX}/share/doc/inventory-collector"
|
||||
|
||||
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
||||
ROOT_DIR="$(cd "${SCRIPT_DIR}/.." && pwd)"
|
||||
|
||||
usage() {
|
||||
cat <<EOF
|
||||
Usage: $(basename "$0") [OPTIONS]
|
||||
|
||||
Options:
|
||||
--prefix <path> Installation prefix (default: /usr)
|
||||
--destdir <path> Staging root for packaging (default: empty)
|
||||
--uninstall Remove installed files
|
||||
-h, --help Show this help message
|
||||
EOF
|
||||
exit 0
|
||||
}
|
||||
|
||||
uninstall() {
|
||||
echo "==> Uninstalling inventory-collector from ${PREFIX}..."
|
||||
rm -f "${BIN_DIR}/inventory-collector"
|
||||
rm -rf "${LIB_DIR}"
|
||||
rm -f "${ETC_DIR}/config.yaml.example"
|
||||
rmdir "${ETC_DIR}" 2>/dev/null || true
|
||||
rm -f "${MAN_DIR}/inventory-collector.1"
|
||||
rm -f "${BASH_COMP_DIR}/inventory-collector"
|
||||
rm -f "${ZSH_COMP_DIR}/_inventory-collector"
|
||||
rm -rf "${DOC_DIR}"
|
||||
echo "==> Uninstallation complete."
|
||||
exit 0
|
||||
}
|
||||
|
||||
while [[ $# -gt 0 ]]; do
|
||||
case "$1" in
|
||||
--prefix)
|
||||
PREFIX="$2"
|
||||
shift 2
|
||||
;;
|
||||
--destdir)
|
||||
DESTDIR="$2"
|
||||
shift 2
|
||||
;;
|
||||
--uninstall)
|
||||
uninstall
|
||||
;;
|
||||
-h|--help)
|
||||
usage
|
||||
;;
|
||||
*)
|
||||
echo "Unknown option: $1" >&2
|
||||
usage
|
||||
;;
|
||||
esac
|
||||
done
|
||||
|
||||
# Recalculate target paths after arg parsing
|
||||
BIN_DIR="${DESTDIR}${PREFIX}/bin"
|
||||
LIB_DIR="${DESTDIR}${PREFIX}/lib/inventory-collector"
|
||||
ETC_DIR="${DESTDIR}/etc/inventory-collector"
|
||||
MAN_DIR="${DESTDIR}${PREFIX}/share/man/man1"
|
||||
BASH_COMP_DIR="${DESTDIR}${PREFIX}/share/bash-completion/completions"
|
||||
ZSH_COMP_DIR="${DESTDIR}${PREFIX}/share/zsh/site-functions"
|
||||
DOC_DIR="${DESTDIR}${PREFIX}/share/doc/inventory-collector"
|
||||
|
||||
echo "==> Installing inventory-collector to ${PREFIX} (DESTDIR='${DESTDIR}')..."
|
||||
|
||||
# 1. Directories
|
||||
mkdir -p "${BIN_DIR}" "${LIB_DIR}" "${ETC_DIR}" "${MAN_DIR}" "${BASH_COMP_DIR}" "${ZSH_COMP_DIR}" "${DOC_DIR}"
|
||||
|
||||
# 2. Binary
|
||||
install -m 0755 "${ROOT_DIR}/bin/inventory-collector" "${BIN_DIR}/inventory-collector"
|
||||
|
||||
# 3. Python package
|
||||
cp -r "${ROOT_DIR}/inventory_collector" "${LIB_DIR}/"
|
||||
find "${LIB_DIR}" -type d -exec chmod 0755 {} +
|
||||
find "${LIB_DIR}" -type f -exec chmod 0644 {} +
|
||||
|
||||
# 4. Example configuration
|
||||
if [[ -f "${ROOT_DIR}/config.yaml.example" ]]; then
|
||||
install -m 0644 "${ROOT_DIR}/config.yaml.example" "${ETC_DIR}/config.yaml.example"
|
||||
fi
|
||||
|
||||
# 5. Man page
|
||||
if [[ -f "${ROOT_DIR}/man/inventory-collector.1" ]]; then
|
||||
install -m 0644 "${ROOT_DIR}/man/inventory-collector.1" "${MAN_DIR}/inventory-collector.1"
|
||||
fi
|
||||
|
||||
# 6. Shell completions
|
||||
if [[ -f "${ROOT_DIR}/completions/bash/inventory-collector" ]]; then
|
||||
install -m 0644 "${ROOT_DIR}/completions/bash/inventory-collector" "${BASH_COMP_DIR}/inventory-collector"
|
||||
fi
|
||||
if [[ -f "${ROOT_DIR}/completions/zsh/_inventory-collector" ]]; then
|
||||
install -m 0644 "${ROOT_DIR}/completions/zsh/_inventory-collector" "${ZSH_COMP_DIR}/_inventory-collector"
|
||||
fi
|
||||
|
||||
# 7. Documentation
|
||||
if [[ -f "${ROOT_DIR}/README.md" ]]; then
|
||||
install -m 0644 "${ROOT_DIR}/README.md" "${DOC_DIR}/README.md"
|
||||
fi
|
||||
if [[ -f "${ROOT_DIR}/docs/user-guide.md" ]]; then
|
||||
install -m 0644 "${ROOT_DIR}/docs/user-guide.md" "${DOC_DIR}/user-guide.md"
|
||||
fi
|
||||
|
||||
echo "==> Successfully installed inventory-collector."
|
||||
echo " Binary: ${BIN_DIR}/inventory-collector"
|
||||
echo " Library: ${LIB_DIR}"
|
||||
echo " Config Ex.: ${ETC_DIR}/config.yaml.example"
|
||||
echo " Man Page: ${MAN_DIR}/inventory-collector.1"
|
||||
echo " Completions: ${BASH_COMP_DIR}, ${ZSH_COMP_DIR}"
|
||||
Reference in new issue
Block a user