#!/bin/bash

PROGNAME="${BASH_SOURCE[0]}"
HERE="$(cd "$(dirname "$PROGNAME")" &>/dev/null && pwd)"
READIES=$(cd $HERE/.. && pwd)
. $READIES/shibumi/defs

packs="ca-certificates wget curl unzip"

if [[ $FORCE != 1 ]]; then
	missing=0
	for cmd in ${packs/ca-certificates/}; do
		if ! is_command $cmd; then
			missing=1
			break
		fi
	done
	[[ $missing == 0 ]] && exit 0
fi

if is_command apt-get; then
	export DEBIAN_FRONTEND=noninteractive
	runn apt-get update -qq
	runn apt-get install --fix-missing -y $packs xz-utils
elif is_command dnf; then
	runn dnf install -y $packs xz
elif is_command yum; then
	# runn $READIES/bin/getepel
	runn yum install -y $packs xz
elif is_command zypper; then
	runn zypper install -y $packs xz
elif is_command apk; then
	runn apk update
	runn apk add $packs xz
elif is_command pacman; then
	pacman --noconfirm -S $packs xz
elif is_command brew; then
	packs=${packs/ca-certificates/}
	runn brew install $packs xz
elif is_command pkg; then
	runn pkg install -y $packs xz
fi
