2022-11-07 23:12:43 +00:00
|
|
|
#!/usr/bin/env bash
|
2023-11-04 02:11:57 +00:00
|
|
|
# This script was generated by bashly 1.1.1 (https://bashly.dannyb.co)
|
2022-11-07 23:12:43 +00:00
|
|
|
# Modifying it manually is not recommended
|
|
|
|
|
|
|
|
if [[ "${BASH_VERSINFO:-0}" -lt 4 ]]; then
|
|
|
|
printf "bash version 4 or higher is required\n" >&2
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
|
|
|
root_command() {
|
|
|
|
# Settings
|
|
|
|
source_url=${args[source]}
|
|
|
|
publisher=${args[publisher]}
|
|
|
|
# Flags
|
|
|
|
no_call=${args[--no-call]}
|
|
|
|
dry_run=${args[--dry-run]}
|
|
|
|
|
|
|
|
REQS="wget apt-transport-https"
|
|
|
|
|
|
|
|
function do_call() {
|
|
|
|
if [[ $dry_run ]]; then
|
|
|
|
echo -e "### DRY RUN: \n$1"
|
|
|
|
else
|
|
|
|
$1
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
|
|
|
function get_distribution {
|
|
|
|
if [ -f /etc/os-release ]; then
|
|
|
|
. /etc/os-release
|
|
|
|
OS=$NAME
|
|
|
|
VER=$VERSION_ID
|
|
|
|
elif type lsb_release >/dev/null 2>&1; then
|
|
|
|
OS=$(lsb_release -si)
|
|
|
|
VER=$(lsb_release -sr)
|
|
|
|
elif [ -f /etc/lsb-release ]; then
|
|
|
|
. /etc/lsb-release
|
|
|
|
OS=$DISTRIB_ID
|
|
|
|
VER=$DISTRIB_RELEASE
|
|
|
|
elif [ -f /etc/debian_version ]; then
|
|
|
|
OS=Debian
|
|
|
|
VER=$(cat /etc/debian_version)
|
|
|
|
elif [ -f /etc/SuSe-release ]; then
|
|
|
|
OS=SEL
|
|
|
|
elif [ -f /etc/redhat-release ]; then
|
|
|
|
OS=RedHat
|
|
|
|
else
|
|
|
|
OS=$(uname -s)
|
|
|
|
VER=$(uname -r)
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
|
|
|
echo "### Installer for InvenTree - source: $publisher/$source_url"
|
|
|
|
|
|
|
|
# Check if os and version is supported
|
|
|
|
get_distribution
|
|
|
|
echo "### Detected distribution: $OS $VER"
|
2023-06-03 14:04:52 +00:00
|
|
|
SUPPORTED=true # is this OS supported?
|
2022-11-21 11:03:32 +00:00
|
|
|
NEEDS_LIBSSL1_1=false # does this OS need libssl1.1?
|
|
|
|
|
|
|
|
DIST_OS=${OS,,}
|
|
|
|
DIST_VER=$VER
|
|
|
|
|
2022-11-07 23:12:43 +00:00
|
|
|
case "$OS" in
|
|
|
|
Ubuntu)
|
2022-11-21 11:03:32 +00:00
|
|
|
if [[ $VER == "22.04" ]]; then
|
|
|
|
SUPPORTED=true
|
|
|
|
NEEDS_LIBSSL1_1=true
|
|
|
|
DIST_VER="20.04"
|
|
|
|
elif [[ $VER == "20.04" ]]; then
|
|
|
|
SUPPORTED=true
|
|
|
|
else
|
2022-11-20 08:29:12 +00:00
|
|
|
SUPPORTED=false
|
2022-11-07 23:12:43 +00:00
|
|
|
fi
|
|
|
|
;;
|
2023-01-24 22:30:14 +00:00
|
|
|
"Debian GNU/Linux" | "debian gnu/linux" | Raspbian)
|
2023-07-08 22:40:53 +00:00
|
|
|
if [[ $VER == "12" ]]; then
|
|
|
|
SUPPORTED=true
|
|
|
|
elif [[ $VER == "11" ]]; then
|
|
|
|
SUPPORTED=true
|
|
|
|
elif [[ $VER == "10" ]]; then
|
|
|
|
SUPPORTED=true
|
|
|
|
else
|
2022-11-20 08:29:12 +00:00
|
|
|
SUPPORTED=false
|
2022-11-07 23:12:43 +00:00
|
|
|
fi
|
2023-01-24 22:30:14 +00:00
|
|
|
DIST_OS=debian
|
2022-11-07 23:12:43 +00:00
|
|
|
;;
|
|
|
|
*)
|
|
|
|
echo "### Distribution not supported"
|
2022-11-20 08:29:12 +00:00
|
|
|
SUPPORTED=false
|
2022-11-07 23:12:43 +00:00
|
|
|
;;
|
|
|
|
esac
|
|
|
|
|
2022-11-20 08:29:12 +00:00
|
|
|
if [[ $SUPPORTED != "true" ]]; then
|
2023-04-01 21:34:53 +00:00
|
|
|
echo "This OS is currently not supported."
|
|
|
|
echo "Please install manually using https://docs.inventree.org/en/stable/start/install/"
|
2022-11-07 23:12:43 +00:00
|
|
|
echo "or check https://github.com/inventree/InvenTree/issues/3836 for packaging for your OS."
|
|
|
|
echo "If you think this is a bug please file an issue at"
|
|
|
|
echo "https://github.com/inventree/InvenTree/issues/new?template=install.yaml"
|
|
|
|
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
|
|
|
echo "### Installing required packages for download"
|
|
|
|
for pkg in $REQS; do
|
|
|
|
if dpkg-query -W -f'${Status}' "$pkg" 2>/dev/null | grep -q "ok installed"; then
|
|
|
|
true
|
|
|
|
else
|
|
|
|
do_call "sudo apt-get -yqq install $pkg"
|
|
|
|
fi
|
|
|
|
done
|
|
|
|
|
2022-11-21 11:03:32 +00:00
|
|
|
if [[ $NEEDS_LIBSSL1_1 == "true" ]]; then
|
2023-12-08 02:10:44 +00:00
|
|
|
echo "### Installing libssl1.1"
|
2022-11-21 11:03:32 +00:00
|
|
|
|
|
|
|
echo "deb http://security.ubuntu.com/ubuntu focal-security main" | sudo tee /etc/apt/sources.list.d/focal-security.list
|
|
|
|
do_call "sudo apt-get update"
|
|
|
|
do_call "sudo apt-get install libssl1.1"
|
|
|
|
sudo rm /etc/apt/sources.list.d/focal-security.list
|
|
|
|
fi
|
|
|
|
|
2022-11-20 08:29:12 +00:00
|
|
|
echo "### Getting and adding key"
|
2023-12-08 02:10:44 +00:00
|
|
|
curl -fsSL https://dl.packager.io/srv/$publisher/InvenTree/key | gpg --dearmor | tee /etc/apt/trusted.gpg.d/pkgr-inventree.gpg > /dev/null
|
2022-11-20 08:29:12 +00:00
|
|
|
echo "### Adding package source"
|
2023-11-04 02:11:57 +00:00
|
|
|
SOURCE_URL="deb [signed-by=/etc/apt/trusted.gpg.d/pkgr-inventree.gpg] https://dl.packager.io/srv/deb/$publisher/InvenTree/$source_url/$DIST_OS $DIST_VER main"
|
|
|
|
echo "$SOURCE_URL" | tee /etc/apt/sources.list.d/inventree.list > /dev/null
|
2023-06-03 14:04:52 +00:00
|
|
|
echo "### Updating package lists"
|
2022-11-07 23:12:43 +00:00
|
|
|
do_call "sudo apt-get update"
|
|
|
|
|
|
|
|
# Set up environment for install
|
|
|
|
echo "### Setting installer args"
|
|
|
|
if [[ $no_call ]]; then
|
|
|
|
do_call "export NO_CALL=true"
|
|
|
|
fi
|
|
|
|
|
|
|
|
echo "### Installing InvenTree"
|
|
|
|
do_call "sudo apt-get install inventree -y"
|
|
|
|
|
|
|
|
echo "### Install done!"
|
|
|
|
|
2022-10-15 23:14:18 +00:00
|
|
|
}
|
|
|
|
|
2022-11-07 23:12:43 +00:00
|
|
|
version_command() {
|
|
|
|
echo "$version"
|
|
|
|
}
|
|
|
|
|
2022-11-20 08:29:12 +00:00
|
|
|
install.sh_usage() {
|
2022-11-07 23:12:43 +00:00
|
|
|
if [[ -n $long_usage ]]; then
|
2022-11-20 08:29:12 +00:00
|
|
|
printf "install.sh - Interactive installer for InvenTree\n"
|
2022-11-07 23:12:43 +00:00
|
|
|
echo
|
|
|
|
|
|
|
|
else
|
2022-11-20 08:29:12 +00:00
|
|
|
printf "install.sh - Interactive installer for InvenTree\n"
|
2022-11-07 23:12:43 +00:00
|
|
|
echo
|
|
|
|
|
|
|
|
fi
|
|
|
|
|
2023-04-02 10:21:51 +00:00
|
|
|
printf "%s\n" "Usage:"
|
2022-11-20 08:29:12 +00:00
|
|
|
printf " install.sh [SOURCE] [PUBLISHER] [OPTIONS]\n"
|
|
|
|
printf " install.sh --help | -h\n"
|
|
|
|
printf " install.sh --version | -v\n"
|
2022-11-07 23:12:43 +00:00
|
|
|
echo
|
|
|
|
|
|
|
|
if [[ -n $long_usage ]]; then
|
2023-04-02 10:21:51 +00:00
|
|
|
printf "%s\n" "Options:"
|
2022-11-07 23:12:43 +00:00
|
|
|
|
2023-04-02 10:21:51 +00:00
|
|
|
printf " %s\n" "--no-call, -n"
|
2022-11-07 23:12:43 +00:00
|
|
|
printf " Do not call outside APIs (only functionally needed)\n"
|
|
|
|
echo
|
|
|
|
|
2023-04-02 10:21:51 +00:00
|
|
|
printf " %s\n" "--dry-run, -d"
|
2022-11-07 23:12:43 +00:00
|
|
|
printf " Dry run (do not install anything)\n"
|
|
|
|
echo
|
|
|
|
|
2023-11-04 02:11:57 +00:00
|
|
|
printf " %s\n" "--help, -h"
|
|
|
|
printf " Show this help\n"
|
|
|
|
echo
|
|
|
|
printf " %s\n" "--version, -v"
|
|
|
|
printf " Show version number\n"
|
|
|
|
echo
|
|
|
|
|
2023-04-02 10:21:51 +00:00
|
|
|
printf "%s\n" "Arguments:"
|
2022-11-07 23:12:43 +00:00
|
|
|
|
2023-04-02 10:21:51 +00:00
|
|
|
printf " %s\n" "SOURCE"
|
2022-11-07 23:12:43 +00:00
|
|
|
printf " Package source that should be used\n"
|
|
|
|
printf " Allowed: stable, master, main\n"
|
|
|
|
printf " Default: stable\n"
|
|
|
|
echo
|
|
|
|
|
2023-04-02 10:21:51 +00:00
|
|
|
printf " %s\n" "PUBLISHER"
|
2022-11-07 23:12:43 +00:00
|
|
|
printf " Publisher that should be used\n"
|
|
|
|
printf " Default: inventree\n"
|
|
|
|
echo
|
|
|
|
|
2023-04-02 10:21:51 +00:00
|
|
|
printf "%s\n" "Examples:"
|
2022-11-07 23:12:43 +00:00
|
|
|
printf " install\n"
|
|
|
|
printf " install master --no-call\n"
|
|
|
|
printf " install master matmair --dry-run\n"
|
|
|
|
echo
|
|
|
|
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
|
|
|
normalize_input() {
|
|
|
|
local arg flags
|
|
|
|
|
|
|
|
while [[ $# -gt 0 ]]; do
|
|
|
|
arg="$1"
|
|
|
|
if [[ $arg =~ ^(--[a-zA-Z0-9_\-]+)=(.+)$ ]]; then
|
|
|
|
input+=("${BASH_REMATCH[1]}")
|
|
|
|
input+=("${BASH_REMATCH[2]}")
|
|
|
|
elif [[ $arg =~ ^(-[a-zA-Z0-9])=(.+)$ ]]; then
|
|
|
|
input+=("${BASH_REMATCH[1]}")
|
|
|
|
input+=("${BASH_REMATCH[2]}")
|
|
|
|
elif [[ $arg =~ ^-([a-zA-Z0-9][a-zA-Z0-9]+)$ ]]; then
|
|
|
|
flags="${BASH_REMATCH[1]}"
|
2023-04-02 10:21:51 +00:00
|
|
|
for ((i = 0; i < ${#flags}; i++)); do
|
2022-11-07 23:12:43 +00:00
|
|
|
input+=("-${flags:i:1}")
|
|
|
|
done
|
|
|
|
else
|
|
|
|
input+=("$arg")
|
2022-10-15 23:14:18 +00:00
|
|
|
fi
|
2022-11-07 23:12:43 +00:00
|
|
|
|
|
|
|
shift
|
|
|
|
done
|
|
|
|
}
|
2022-11-20 08:29:12 +00:00
|
|
|
|
2022-11-07 23:12:43 +00:00
|
|
|
inspect_args() {
|
2023-04-02 10:21:51 +00:00
|
|
|
if ((${#args[@]})); then
|
2023-11-04 02:11:57 +00:00
|
|
|
readarray -t sorted_keys < <(printf '%s\n' "${!args[@]}" | sort)
|
2022-11-07 23:12:43 +00:00
|
|
|
echo args:
|
|
|
|
for k in "${sorted_keys[@]}"; do echo "- \${args[$k]} = ${args[$k]}"; done
|
|
|
|
else
|
|
|
|
echo args: none
|
|
|
|
fi
|
|
|
|
|
2023-04-02 10:21:51 +00:00
|
|
|
if ((${#other_args[@]})); then
|
2022-11-07 23:12:43 +00:00
|
|
|
echo
|
|
|
|
echo other_args:
|
|
|
|
echo "- \${other_args[*]} = ${other_args[*]}"
|
|
|
|
for i in "${!other_args[@]}"; do
|
|
|
|
echo "- \${other_args[$i]} = ${other_args[$i]}"
|
|
|
|
done
|
|
|
|
fi
|
2023-11-04 02:11:57 +00:00
|
|
|
|
|
|
|
if ((${#deps[@]})); then
|
|
|
|
readarray -t sorted_keys < <(printf '%s\n' "${!deps[@]}" | sort)
|
|
|
|
echo
|
|
|
|
echo deps:
|
|
|
|
for k in "${sorted_keys[@]}"; do echo "- \${deps[$k]} = ${deps[$k]}"; done
|
|
|
|
fi
|
|
|
|
|
2022-11-07 23:12:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
parse_requirements() {
|
2022-11-20 08:29:12 +00:00
|
|
|
|
2023-04-02 10:21:51 +00:00
|
|
|
while [[ $# -gt 0 ]]; do
|
|
|
|
case "${1:-}" in
|
|
|
|
--version | -v)
|
|
|
|
version_command
|
|
|
|
exit
|
|
|
|
;;
|
|
|
|
|
|
|
|
--help | -h)
|
|
|
|
long_usage=yes
|
|
|
|
install.sh_usage
|
|
|
|
exit
|
|
|
|
;;
|
2022-11-07 23:12:43 +00:00
|
|
|
|
2023-04-02 10:21:51 +00:00
|
|
|
*)
|
|
|
|
break
|
|
|
|
;;
|
2022-11-07 23:12:43 +00:00
|
|
|
|
2023-04-02 10:21:51 +00:00
|
|
|
esac
|
|
|
|
done
|
2022-11-07 23:12:43 +00:00
|
|
|
|
|
|
|
action="root"
|
|
|
|
|
|
|
|
while [[ $# -gt 0 ]]; do
|
|
|
|
key="$1"
|
|
|
|
case "$key" in
|
2022-11-20 08:29:12 +00:00
|
|
|
|
2023-04-02 10:21:51 +00:00
|
|
|
--no-call | -n)
|
2022-11-07 23:12:43 +00:00
|
|
|
|
2023-04-02 10:21:51 +00:00
|
|
|
args['--no-call']=1
|
|
|
|
shift
|
|
|
|
;;
|
2022-11-07 23:12:43 +00:00
|
|
|
|
2023-04-02 10:21:51 +00:00
|
|
|
--dry-run | -d)
|
2022-11-07 23:12:43 +00:00
|
|
|
|
2023-04-02 10:21:51 +00:00
|
|
|
args['--dry-run']=1
|
|
|
|
shift
|
|
|
|
;;
|
2022-11-07 23:12:43 +00:00
|
|
|
|
2023-04-02 10:21:51 +00:00
|
|
|
-?*)
|
|
|
|
printf "invalid option: %s\n" "$key" >&2
|
|
|
|
exit 1
|
|
|
|
;;
|
2022-11-07 23:12:43 +00:00
|
|
|
|
2023-04-02 10:21:51 +00:00
|
|
|
*)
|
2022-11-20 08:29:12 +00:00
|
|
|
|
2023-04-02 10:21:51 +00:00
|
|
|
if [[ -z ${args['source']+x} ]]; then
|
2022-11-07 23:12:43 +00:00
|
|
|
|
2023-04-02 10:21:51 +00:00
|
|
|
args['source']=$1
|
|
|
|
shift
|
|
|
|
elif [[ -z ${args['publisher']+x} ]]; then
|
2022-11-07 23:12:43 +00:00
|
|
|
|
2023-04-02 10:21:51 +00:00
|
|
|
args['publisher']=$1
|
|
|
|
shift
|
|
|
|
else
|
|
|
|
printf "invalid argument: %s\n" "$key" >&2
|
|
|
|
exit 1
|
|
|
|
fi
|
2022-11-07 23:12:43 +00:00
|
|
|
|
2023-04-02 10:21:51 +00:00
|
|
|
;;
|
2022-11-07 23:12:43 +00:00
|
|
|
|
|
|
|
esac
|
|
|
|
done
|
|
|
|
|
2023-04-02 10:21:51 +00:00
|
|
|
[[ -n ${args['source']:-} ]] || args['source']="stable"
|
|
|
|
[[ -n ${args['publisher']:-} ]] || args['publisher']="inventree"
|
2022-11-07 23:12:43 +00:00
|
|
|
|
2023-11-04 02:11:57 +00:00
|
|
|
if [[ -n ${args['source']} ]] && [[ ! ${args['source']} =~ ^(stable|master|main)$ ]]; then
|
2022-11-07 23:12:43 +00:00
|
|
|
printf "%s\n" "source must be one of: stable, master, main" >&2
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
initialize() {
|
|
|
|
version="2.0"
|
|
|
|
long_usage=''
|
|
|
|
set -e
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
run() {
|
|
|
|
declare -A args=()
|
2023-11-04 02:11:57 +00:00
|
|
|
declare -A deps=()
|
2022-11-07 23:12:43 +00:00
|
|
|
declare -a other_args=()
|
|
|
|
declare -a input=()
|
|
|
|
normalize_input "$@"
|
|
|
|
parse_requirements "${input[@]}"
|
|
|
|
|
2023-04-02 10:21:51 +00:00
|
|
|
case "$action" in
|
2023-11-04 02:11:57 +00:00
|
|
|
"root") root_command ;;
|
2023-04-02 10:21:51 +00:00
|
|
|
esac
|
2022-11-07 23:12:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
initialize
|
|
|
|
run "$@"
|