install: add moonraker system deps json file
Signed-off-by: Eric Callahan <arksine.code@gmail.com>
This commit is contained in:
parent
b50057c3ba
commit
a5790d4b84
|
@ -15,6 +15,17 @@ INSTANCE_ALIAS="${MOONRAKER_ALIAS:-moonraker}"
|
||||||
SERVICE_VERSION="1"
|
SERVICE_VERSION="1"
|
||||||
MACHINE_PROVIDER="systemd_cli"
|
MACHINE_PROVIDER="systemd_cli"
|
||||||
|
|
||||||
|
package_decode_script=$( cat << EOF
|
||||||
|
import sys
|
||||||
|
import json
|
||||||
|
try:
|
||||||
|
ret = json.load(sys.stdin)
|
||||||
|
except Exception:
|
||||||
|
exit(0)
|
||||||
|
sys.stdout.write(' '.join(ret['debian']))
|
||||||
|
EOF
|
||||||
|
)
|
||||||
|
|
||||||
# Step 2: Clean up legacy installation
|
# Step 2: Clean up legacy installation
|
||||||
cleanup_legacy() {
|
cleanup_legacy() {
|
||||||
if [ -f "/etc/init.d/moonraker" ]; then
|
if [ -f "/etc/init.d/moonraker" ]; then
|
||||||
|
@ -30,18 +41,30 @@ cleanup_legacy() {
|
||||||
# Step 3: Install packages
|
# Step 3: Install packages
|
||||||
install_packages()
|
install_packages()
|
||||||
{
|
{
|
||||||
PKGLIST="python3-virtualenv python3-dev"
|
|
||||||
PKGLIST="${PKGLIST} libopenjp2-7 python3-libgpiod liblmdb-dev"
|
|
||||||
PKGLIST="${PKGLIST} libsodium-dev zlib1g-dev libjpeg-dev packagekit"
|
|
||||||
PKGLIST="${PKGLIST} wireless-tools curl"
|
|
||||||
|
|
||||||
# Update system package info
|
# Update system package info
|
||||||
report_status "Running apt-get update..."
|
report_status "Running apt-get update..."
|
||||||
sudo apt-get update --allow-releaseinfo-change
|
sudo apt-get update --allow-releaseinfo-change
|
||||||
|
|
||||||
|
system_deps="${SRCDIR}/scripts/system-dependencies.json"
|
||||||
|
if [ -f "${system_deps}" ]; then
|
||||||
|
if [ ! -x "$(command -v python3)" ]; then
|
||||||
|
report_status "Installing python3 base package..."
|
||||||
|
sudo apt-get install --yes python3
|
||||||
|
fi
|
||||||
|
PKGS="$( cat ${system_deps} | python3 -c "${package_decode_script}" )"
|
||||||
|
|
||||||
|
else
|
||||||
|
echo "Error: system-dependencies.json not found, falling back to legacy pacakge list"
|
||||||
|
PKGLIST="${PKGLIST} python3-virtualenv python3-dev python3-libgpiod liblmdb-dev"
|
||||||
|
PKGLIST="${PKGLIST} libopenjp2-7 libsodium-dev zlib1g-dev libjpeg-dev packagekit"
|
||||||
|
PKGLIST="${PKGLIST} wireless-tools curl"
|
||||||
|
PKGS=${PKGLIST}
|
||||||
|
fi
|
||||||
|
|
||||||
# Install desired packages
|
# Install desired packages
|
||||||
report_status "Installing packages..."
|
report_status "Installing Moonraker Dependencies:"
|
||||||
sudo apt-get install --yes ${PKGLIST}
|
report_status "${PKGS}"
|
||||||
|
sudo apt-get install --yes ${PKGS}
|
||||||
}
|
}
|
||||||
|
|
||||||
# Step 4: Create python virtual environment
|
# Step 4: Create python virtual environment
|
||||||
|
|
|
@ -0,0 +1,57 @@
|
||||||
|
#! /usr/bin/python3
|
||||||
|
# Create system dependencies json file from the install script
|
||||||
|
#
|
||||||
|
# Copyright (C) 2023 Eric Callahan <arksine.code@gmail.com>
|
||||||
|
#
|
||||||
|
# This file may be distributed under the terms of the GNU GPLv3 license
|
||||||
|
from __future__ import annotations
|
||||||
|
import argparse
|
||||||
|
import pathlib
|
||||||
|
import json
|
||||||
|
import re
|
||||||
|
from typing import List, Dict
|
||||||
|
|
||||||
|
def make_sysdeps(input: str, output: str, distro: str, truncate: bool) -> None:
|
||||||
|
sysdeps: Dict[str, List[str]] = {}
|
||||||
|
outpath = pathlib.Path(output).expanduser().resolve()
|
||||||
|
if outpath.is_file() and not truncate:
|
||||||
|
sysdeps = json.loads(outpath.read_bytes())
|
||||||
|
inst_path: pathlib.Path = pathlib.Path(input).expanduser().resolve()
|
||||||
|
if not inst_path.is_file():
|
||||||
|
raise Exception(f"Unable to locate install script: {inst_path}")
|
||||||
|
data = inst_path.read_text()
|
||||||
|
plines: List[str] = re.findall(r'PKGLIST="(.*)"', data)
|
||||||
|
plines = [p.lstrip("${PKGLIST}").strip() for p in plines]
|
||||||
|
packages: List[str] = []
|
||||||
|
for line in plines:
|
||||||
|
packages.extend(line.split())
|
||||||
|
sysdeps[distro] = packages
|
||||||
|
outpath.write_text(json.dumps(sysdeps, indent=4))
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
def_path = pathlib.Path(__file__).parent
|
||||||
|
desc = (
|
||||||
|
"make_sysdeps - generate system dependency json file from an install script"
|
||||||
|
)
|
||||||
|
parser = argparse.ArgumentParser(description=desc)
|
||||||
|
parser.add_argument(
|
||||||
|
"-i", "--input", metavar="<install script>",
|
||||||
|
help="path of the install script to read",
|
||||||
|
default=f"{def_path}/install-moonraker.sh"
|
||||||
|
)
|
||||||
|
parser.add_argument(
|
||||||
|
"-o", "--output", metavar="<output file>",
|
||||||
|
help="path of the system dependency file to write",
|
||||||
|
default=f"{def_path}/system-dependencies.json"
|
||||||
|
)
|
||||||
|
parser.add_argument(
|
||||||
|
"-d", "--distro", metavar="<linux distro>",
|
||||||
|
help="linux distro for dependencies", default="debian"
|
||||||
|
)
|
||||||
|
parser.add_argument(
|
||||||
|
"-t", "--truncate", action="store_true",
|
||||||
|
help="truncate output file"
|
||||||
|
)
|
||||||
|
args = parser.parse_args()
|
||||||
|
make_sysdeps(args.input, args.output, args.distro, args.truncate)
|
|
@ -0,0 +1,15 @@
|
||||||
|
{
|
||||||
|
"debian": [
|
||||||
|
"python3-virtualenv",
|
||||||
|
"python3-dev",
|
||||||
|
"python3-libgpiod",
|
||||||
|
"liblmdb-dev",
|
||||||
|
"libopenjp2-7",
|
||||||
|
"libsodium-dev",
|
||||||
|
"zlib1g-dev",
|
||||||
|
"libjpeg-dev",
|
||||||
|
"packagekit",
|
||||||
|
"wireless-tools",
|
||||||
|
"curl"
|
||||||
|
]
|
||||||
|
}
|
Loading…
Reference in New Issue