cdist/cdist/conf/type/__interface/manifest

97 lines
2.4 KiB
Plaintext
Raw Normal View History

2020-01-19 17:06:03 +00:00
#!/bin/sh -e
# -*- mode: sh; indent-tabs-mode: t -*-
2020-01-19 17:06:03 +00:00
#
# 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() { die "$(printf "$@")"; }
invalid_param() { die "$@"; }
invalid_paramf() { dief "$@"; }
2020-01-19 17:06:03 +00:00
os=$(cat "${__global}/explorer/os")
# Parameters
state=$(cat "${__object}/parameter/state")
comment=$(cat "${__object}/parameter/comment")
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'
! test -f "${__object}/parameter/netmask" \
|| invalid_param '--netmask is invalid for --bootproto dhcp'
;;
(static)
# TODO
;;
(manual)
# TODO
;;
(*)
invalid_paramf 'Unknown --bootproto: %s\n' "${bootproto}"
;;
esac
2020-01-19 17:06:03 +00:00
if test -f "${__object}/parameter/type"
then
impl_type=$(cat "${__object}/parameter/type")
2020-01-19 17:06:03 +00:00
else
# Guess the type based on the operating system
case $os
in
(debian)
2020-01-19 17:06:03 +00:00
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
2020-01-19 17:06:03 +00:00
;;
(devuan)
impl_type=ifupdown.d
2020-01-19 17:06:03 +00:00
;;
(centos|redhat)
impl_type=redhat
;;
(openwrt)
impl_type=uci
;;
(*)
if test -s "${__object}/explorer/has_networkctl"
then
impl_type=systemd
else
die "Don't know how to manage interfaces on: ${os}"
fi
2020-01-19 17:06:03 +00:00
;;
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}"
2020-01-19 17:06:03 +00:00
# Run backend-specific script
"${manifest_file}" "$@"