#!/bin/sh -e

os="$(cat "$__global/explorer/os")"
default_package_name="socat sipcalc sudo"

if [ -f "$__object/parameter/with-x" ]; then
    with_x="$(cat "$__object/parameter/with-x")"
fi

case "$os" in
     alpine)
        name_netcat="netcat-openbsd"
        name_wireshark="tshark"
     ;;
     debian|devuan)
        name_netcat="netcat"
        name_wireshark="tshark"
     ;;
     fedora)
        name_netcat="nmap-ncat"
        name_wireshark="wireshark-cli"
     ;;
     *)
        echo "Don't know how to manage packages on: $os" >&2
        exit 1
         :
     ;;
esac

all_package_name="$default_package_name $name_netcat $name_wireshark"

__package_update_index

for package in $all_package_name; do
    require="__package_update_index" __package $package --state=present
done

if [ -f "$__object/parameter/extra-packages" ]; then
    for package in $(cat "$__object/parameter/extra-packages"); do
        require="__package_update_index" __package $package --state=present
    done
fi
