Skip to content

Commit

Permalink
Add things needed for packaging (#3972)
Browse files Browse the repository at this point in the history
Co-authored-by: Oliver <oliver.henry.walters@gmail.com>
  • Loading branch information
matmair and SchrodingersGat committed Nov 21, 2022
1 parent ca1fbf9 commit d041867
Show file tree
Hide file tree
Showing 11 changed files with 877 additions and 0 deletions.
34 changes: 34 additions & 0 deletions .pkgr.yml
@@ -0,0 +1,34 @@
name: inventree
description: Open Source Inventory Management System
homepage: https://inventree.org
notifications: false
buildpack: https://github.com/mjmair/heroku-buildpack-python#v216-mjmair
env:
- STACK=heroku-20
- DISABLE_COLLECTSTATIC=1
- INVENTREE_DB_ENGINE=sqlite3
- INVENTREE_DB_NAME=database.sqlite3
- INVENTREE_PLUGINS_ENABLED
- INVENTREE_MEDIA_ROOT=/opt/inventree/media
- INVENTREE_STATIC_ROOT=/opt/inventree/static
- INVENTREE_BACKUP_DIR=/opt/inventree/backup
- INVENTREE_PLUGIN_FILE=/opt/inventree/plugins.txt
- INVENTREE_CONFIG_FILE=/opt/inventree/config.yaml
after_install: contrib/packager.io/postinstall.sh
dependencies:
- curl
- python3
- python3-venv
- python3-pip
- python3-cffi
- python3-brotli
- python3-wheel
- libpango-1.0-0
- libharfbuzz0b
- libpangoft2-1.0-0
- gettext
- nginx
- jq
targets:
ubuntu-20.04: true
debian-11: true
2 changes: 2 additions & 0 deletions Procfile
@@ -0,0 +1,2 @@
web: env/bin/gunicorn --chdir $APP_HOME/InvenTree -c InvenTree/gunicorn.conf.py InvenTree.wsgi -b 0.0.0.0:$PORT
worker: env/bin/python InvenTree/manage.py qcluster
311 changes: 311 additions & 0 deletions contrib/install.sh
@@ -0,0 +1,311 @@
#!/usr/bin/env bash
# This script was generated by bashly 0.8.9 (https://bashly.dannyb.co)
# 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"
SUPPORTED=true
case "$OS" in
Ubuntu)
if [[ $VER != "20.04" ]]; then
SUPPORTED=false
fi
;;
"Debian GNU/Linux" | Raspbian)
if [[ $VER != "11" ]]; then
SUPPORTED=false
fi
OS=Debian
;;
*)
echo "### Distribution not supported"
SUPPORTED=false
;;
esac

if [[ $SUPPORTED != "true" ]]; then
echo "This OS is currently not supported"
echo "please install manually using https://inventree.readthedocs.io/en/stable/start/install/"
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

echo "### Getting and adding key"
wget -qO- https://dl.packager.io/srv/$publisher/InvenTree/key | sudo apt-key add -
echo "### Adding package source"
do_call "sudo wget -O /etc/apt/sources.list.d/inventree.list https://dl.packager.io/srv/$publisher/InvenTree/$source_url/installer/${OS,,}/${VER}.repo"

echo "### Updateing package lists"
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!"

}

version_command() {
echo "$version"
}

install.sh_usage() {
if [[ -n $long_usage ]]; then
printf "install.sh - Interactive installer for InvenTree\n"
echo

else
printf "install.sh - Interactive installer for InvenTree\n"
echo

fi

printf "Usage:\n"
printf " install.sh [SOURCE] [PUBLISHER] [OPTIONS]\n"
printf " install.sh --help | -h\n"
printf " install.sh --version | -v\n"
echo

if [[ -n $long_usage ]]; then
printf "Options:\n"

echo " --help, -h"
printf " Show this help\n"
echo
echo " --version, -v"
printf " Show version number\n"
echo

echo " --no-call, -n"
printf " Do not call outside APIs (only functionally needed)\n"
echo

echo " --dry-run, -d"
printf " Dry run (do not install anything)\n"
echo

printf "Arguments:\n"

echo " SOURCE"
printf " Package source that should be used\n"
printf " Allowed: stable, master, main\n"
printf " Default: stable\n"
echo

echo " PUBLISHER"
printf " Publisher that should be used\n"
printf " Default: inventree\n"
echo

printf "Examples:\n"
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]}"
for (( i=0 ; i < ${#flags} ; i++ )); do
input+=("-${flags:i:1}")
done
else
input+=("$arg")
fi

shift
done
}

inspect_args() {
readarray -t sorted_keys < <(printf '%s\n' "${!args[@]}" | sort)
if (( ${#args[@]} )); then
echo args:
for k in "${sorted_keys[@]}"; do echo "- \${args[$k]} = ${args[$k]}"; done
else
echo args: none
fi

if (( ${#other_args[@]} )); then
echo
echo other_args:
echo "- \${other_args[*]} = ${other_args[*]}"
for i in "${!other_args[@]}"; do
echo "- \${other_args[$i]} = ${other_args[$i]}"
done
fi
}

parse_requirements() {

case "${1:-}" in
--version | -v )
version_command
exit
;;

--help | -h )
long_usage=yes
install.sh_usage
exit
;;

esac

action="root"

while [[ $# -gt 0 ]]; do
key="$1"
case "$key" in

--no-call | -n )

args[--no-call]=1
shift
;;

--dry-run | -d )

args[--dry-run]=1
shift
;;

-?* )
printf "invalid option: %s\n" "$key" >&2
exit 1
;;

* )

if [[ -z ${args[source]+x} ]]; then

args[source]=$1
shift
elif [[ -z ${args[publisher]+x} ]]; then

args[publisher]=$1
shift
else
printf "invalid argument: %s\n" "$key" >&2
exit 1
fi

;;

esac
done

[[ -n ${args[source]:-} ]] || args[source]="stable"
[[ -n ${args[publisher]:-} ]] || args[publisher]="inventree"

if [[ ! ${args[source]} =~ ^(stable|master|main)$ ]]; then
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=()
declare -a other_args=()
declare -a input=()
normalize_input "$@"
parse_requirements "${input[@]}"

if [[ $action == "root" ]]; then
root_command
fi
}

initialize
run "$@"
14 changes: 14 additions & 0 deletions contrib/installer/README
@@ -0,0 +1,14 @@
The installer is generated using bashly.

## Installation
Check out the docs: https://bashly.dannyb.co/installation/

If you have ruby already installed run
```bash
gem install bashly
```

## Regenerate script
```bash
bashly generate
```
32 changes: 32 additions & 0 deletions contrib/installer/settings.yml
@@ -0,0 +1,32 @@
# All settings are optional (with their default values provided below), and
# can also be set with an environment variable with the same name, capitalized
# and prefixed by `BASHLY_` - for example: BASHLY_SOURCE_DIR
#
# When setting environment variables, you can use:
# - "0", "false" or "no" to represent false
# - "1", "true" or "yes" to represent true

# The path containing the bashly configuration and source files
source_dir: src

# The path to use for creating the bash script
target_dir: ..

# The path to use for upgrading library files, relative to the source dir
lib_dir: lib

# When true, enable bash strict mode (set -euo pipefail)
strict: false

# When true, the generated script will use tab indentation instead of spaces
# (every 2 leading spaces will be converted to a tab character)
tab_indent: false

# When true, the generated script will consider any argument in the form of
# `-abc` as if it is `-a -b -c`.
compact_short_flags: true

# Set to 'production' or 'development':
# - production generate a smaller script, without file markers
# - development generate with file markers
env: production

0 comments on commit d041867

Please sign in to comment.