cdist/cdist/conf/type/__interface/manifest

95 lines
2.3 KiB
Bash
Executable File

#!/bin/sh -e
# -*- mode: sh; indent-tabs-mode: t -*-
#
# 2020 Dennis Camera (dennis.camera at ssrq-sds-fds.ch)
#
# This file is part of cdist.
#
# cdist is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# cdist is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with cdist. If not, see <http://www.gnu.org/licenses/>.
#
die() { echo "$*" >&2; exit 1; }
dief() {
#shellcheck disable=SC2059
die "$(printf "$@")"
}
invalid_param() { die "$@"; }
invalid_paramf() { dief "$@"; }
os=$(cat "${__global:?}/explorer/os")
# Check parameters
bootproto=$(cat "${__object:?}/parameter/bootproto")
case $bootproto
in
(dhcp)
# Check parameters
! test -f "${__object:?}/parameter/address" \
|| invalid_param '--address is invalid for --bootproto dhcp'
! test -f "${__object:?}/parameter/gateway" \
|| invalid_param '--gateway is invalid for --bootproto dhcp'
;;
(static)
# TODO
;;
(manual)
# TODO
;;
(*)
invalid_paramf 'Unknown --bootproto: %s\n' "${bootproto}"
;;
esac
if test -f "${__object:?}/parameter/type"
then
impl_type=$(cat "${__object:?}/parameter/type")
else
# Guess the type based on the operating system
case $os
in
(debian)
os_major=$(grep -o '^[0-9][0-9]*' "${__global:?}/explorer/os_version")
test "${os_major}" -ge 7 \
|| die 'Debian versions older than 7 (wheezy) are not supported'
impl_type=ifupdown.d
;;
(devuan)
impl_type=ifupdown.d
;;
(centos|redhat|scientific|suse)
impl_type=ifcfg
;;
(openwrt)
impl_type=uci
;;
(*)
if test -s "${__object:?}/explorer/has_networkctl"
then
impl_type=systemd
else
dief "Don't know how to manage interfaces on: %s\n" "${os}"
fi
;;
esac
fi
# Hand over to backend-specific implementation
manifest_file="${__type:?}/files/backends/${impl_type}/manifest"
test -x "${manifest_file}" || dief 'Unknown type: %s\n' "${impl_type}"
# Run backend-specific script
exec "${manifest_file}"