Revize c95784dc
Přidáno uživatelem Ondřej Fibich před téměř 11 roky(ů)
LICENSE | ||
---|---|---|
state the exclusion of warranty; and each file should have at least
|
||
the "copyright" line and a pointer to where the full notice is found.
|
||
|
||
{one line to give the program's name and a brief idea of what it does.}
|
||
Copyright (C) {year} {name of author}
|
||
FreenetIS DHCP synchronization tool.
|
||
Copyright (C) 2013 FreenetIS
|
||
|
||
This program is free software: you can redistribute it and/or modify
|
||
it under the terms of the GNU General Public License as published by
|
||
... | ... | |
If the program does terminal interaction, make it output a short
|
||
notice like this when it starts in an interactive mode:
|
||
|
||
{project} Copyright (C) {year} {fullname}
|
||
freenetis-dhcp Copyright (C) 2013 FreenetIS
|
||
This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
|
||
This is free software, and you are welcome to redistribute it
|
||
under certain conditions; type `show c' for details.
|
README.md | ||
---|---|---|
==============
|
||
|
||
The tool is used to synchronize the DHCP server configuration with data obtained from FreenetIS. DHCP server is identified in FreenetIS by the device ID.
|
||
|
||
For more informations see <http://wiki.freenetis.org/index.php/Instalace#Bal.C3.ADk_freenetis-monitoring>.
|
||
|
||
Changelog
|
||
---------
|
||
|
||
Changelog in debian format is available [here](deb/changelog).
|
deb/changelog | ||
---|---|---|
freenetis-dhcp (0.1.2) stable; urgency=hight
|
||
* Adds dependency for killall
|
||
* Adds support for lenny
|
||
-- Ondrej Fibich <ondrej.fibich@gmail.com> Mon, 04 Mar 2013 19:15:04 +0100
|
||
|
||
freenetis-dhcp (0.1.1) stable; urgency=hight
|
||
* Fix release
|
||
-- Ondrej Fibich <ondrej.fibich@gmail.com> Wed, 19 Jan 2013 19:21:49 +0100
|
||
|
||
freenetis-dhcp (0.1.0) stable; urgency=low
|
||
* First release
|
||
-- Ondrej Fibich <ondrej.fibich@gmail.com> Wed, 16 Jan 2013 19:29:49 +0100
|
deb/conffiles | ||
---|---|---|
/etc/freenetis/freenetis-dhcp.conf
|
||
/etc/init.d/freenetis-dhcp
|
deb/config | ||
---|---|---|
#!/bin/sh
|
||
|
||
set -e
|
||
. /usr/share/debconf/confmodule
|
||
|
||
CONFIGFILE=/etc/freenetis/freenetis-dhcp.conf
|
||
|
||
# Load config file, if it exists.
|
||
if [ -e $CONFIGFILE ]; then
|
||
db_get freenetis-dhcp/hack_reload
|
||
if [ "$RET" = true ]; then
|
||
. $CONFIGFILE || true
|
||
db_set freenetis-dhcp/path_freenetis "$PATH_FN"
|
||
db_set freenetis-dhcp/device_id "$DEVICE_ID"
|
||
db_set freenetis-dhcp/timeout "$TIMEOUT"
|
||
fi
|
||
fi
|
||
|
||
# h@ck for not reloading variables from config file (enabled again by postinst)
|
||
db_set freenetis-dhcp/hack_reload false
|
||
|
||
# Ask questions.
|
||
db_input critical freenetis-dhcp/path_freenetis || true
|
||
db_input critical freenetis-dhcp/device_id || true
|
||
db_input critical freenetis-dhcp/timeout || true
|
||
db_go || true
|
deb/control | ||
---|---|---|
Priority: optional
|
||
Section: web
|
||
Pre-Depends: debconf (>= 0.5) | debconf-2.0
|
||
Suggests: freenetis
|
||
Architecture: all
|
||
Maintainer: Ondrej Fibich <ondrej.fibich@gmail.com>
|
||
Homepage: http://www.freenetis.org
|
||
Description: DHCP server synchronization from FreenetIS
|
||
The tool is used to synchronize the DHCP server configuration with data
|
||
obtained from FreenetIS. DHCP server is identified in FreenetIS by
|
||
the device ID.
|
||
Description-cs.UTF-8: Synchronizace DHCP serveru z FreenetISu:
|
||
Nástroj se používá k synchronizaci konfigurace DHCP serveru daty získanými
|
||
z FreenetISu. DHCP server je ve FreenetISu identifikován pomocí ID zařízení.
|
deb/debianization.sh | ||
---|---|---|
#!/bin/sh
|
||
################################################################################
|
||
# Script for debianization of FreenetIS DHCP package
|
||
# (c) Ondrej Fibich, 2013
|
||
#
|
||
# Takes two arguments (version of package - FreenetIS DHCP and debian version).
|
||
#
|
||
################################################################################
|
||
|
||
if [ $# -ne 2 ]; then
|
||
echo "Wrong arg count.. Terminating"
|
||
exit 1
|
||
fi
|
||
|
||
NAME=freenetis-dhcp
|
||
VERSION=$1
|
||
DEBIAN=$2
|
||
|
||
# create dirs ##################################################################
|
||
mkdir -p deb_packages/tmp
|
||
cd deb_packages/tmp
|
||
|
||
mkdir -m 755 DEBIAN
|
||
mkdir -m 755 etc
|
||
mkdir -m 755 etc/freenetis
|
||
mkdir -m 755 etc/init.d
|
||
mkdir -m 755 usr
|
||
mkdir -m 755 usr/sbin
|
||
mkdir -m 755 usr/share
|
||
mkdir -m 755 usr/share/doc
|
||
mkdir -m 755 usr/share/doc/${NAME}
|
||
|
||
# copy content of package ######################################################
|
||
cp ../../../freenetis-dhcp.init.sh etc/init.d/${NAME}
|
||
cp ../../../freenetis-dhcp-sync.sh usr/sbin/freenetis-dhcp-sync
|
||
|
||
|
||
if [ "$DEBIAN" = lenny ]; then
|
||
cp ../../../freenetis-dhcp.lenny.conf etc/freenetis/freenetis-dhcp.conf
|
||
else
|
||
cp ../../../freenetis-dhcp.conf etc/freenetis/freenetis-dhcp.conf
|
||
fi
|
||
|
||
# doc ##########################################################################
|
||
|
||
# change log
|
||
cat ../../changelog >> usr/share/doc/${NAME}/changelog
|
||
|
||
# debian change log is same
|
||
cp usr/share/doc/${NAME}/changelog usr/share/doc/${NAME}/changelog.Debian
|
||
|
||
# copywriting
|
||
|
||
echo "This package was debianized by Ondrej Fibich <ondrej.fibich@gmail.com> on `date -R`" >> usr/share/doc/${NAME}/copyright
|
||
echo "It was downloaded from <http://freenetis.org/>\n" >> usr/share/doc/${NAME}/copyright
|
||
echo "Copyright:\n" >> usr/share/doc/${NAME}/copyright
|
||
echo " Copyright 2010-2013 Ondřej Fibich <ondrej.fibich@gmail.com>" >> usr/share/doc/${NAME}/copyright
|
||
echo " Copyright 2018-2013 Michal Kliment <kliment@freenetis.org>" >> usr/share/doc/${NAME}/copyright
|
||
echo "\nLicense:\n" >> usr/share/doc/${NAME}/copyright
|
||
echo " This program is free software: you can redistribute it and/or modify" >> usr/share/doc/${NAME}/copyright
|
||
echo " it under the terms of the GNU General Public License as published by" >> usr/share/doc/${NAME}/copyright
|
||
echo " the Free Software Foundation, either version 3 of the License, or" >> usr/share/doc/${NAME}/copyright
|
||
echo " (at your option) any later version." >> usr/share/doc/${NAME}/copyright
|
||
echo "" >> usr/share/doc/${NAME}/copyright
|
||
echo " This program is distributed in the hope that it will be useful," >> usr/share/doc/${NAME}/copyright
|
||
echo " but WITHOUT ANY WARRANTY; without even the implied warranty of" >> usr/share/doc/${NAME}/copyright
|
||
echo " MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the" >> usr/share/doc/${NAME}/copyright
|
||
echo " GNU General Public License for more details." >> usr/share/doc/${NAME}/copyright
|
||
echo "" >> usr/share/doc/${NAME}/copyright
|
||
echo "On Debian systems, the complete text of the GNU General" >> usr/share/doc/${NAME}/copyright
|
||
echo "Public License can be found in \`/usr/share/common-licenses/GPL-3'.\n" >> usr/share/doc/${NAME}/copyright
|
||
echo -n "The Debian packaging is (C) `date +%Y`, Ondrej Fibich <ondrej.fibich@gmail.com> and" >> usr/share/doc/${NAME}/copyright
|
||
echo " it is licensed under the GPL, see above.\n" >> usr/share/doc/${NAME}/copyright
|
||
|
||
# man pages
|
||
|
||
# rights
|
||
chmod 644 usr/share/doc/${NAME}/changelog usr/share/doc/${NAME}/changelog.Debian \
|
||
usr/share/doc/${NAME}/copyright
|
||
|
||
# compress doc
|
||
gzip --best usr/share/doc/${NAME}/changelog
|
||
gzip --best usr/share/doc/${NAME}/changelog.Debian
|
||
|
||
# count size
|
||
SIZE=`du -s etc usr | cut -f1 | paste -sd+ | bc`
|
||
|
||
# calculate checksum ###########################################################
|
||
|
||
find * -type f ! -regex '^DEBIAN/.*' -exec md5sum {} \; >> DEBIAN/md5sums
|
||
|
||
# create info files ############################################################
|
||
|
||
# create package info
|
||
|
||
echo "Package: ${NAME}" >> DEBIAN/control
|
||
echo "Version: ${VERSION}-${DEBIAN}" >> DEBIAN/control
|
||
echo "Installed-Size: ${SIZE}" >> DEBIAN/control
|
||
|
||
if [ "$DEBIAN" = lenny ]; then
|
||
echo "Depends: coreutils (>= 6.10-6), wget (>= 1.11-4.1), dhcp3-server, diff, procps, psmisc" >> DEBIAN/control
|
||
else
|
||
echo "Depends: coreutils (>= 6.10-6), wget (>= 1.11-4.1), isc-dhcp-server, diffutils, procps, psmisc" >> DEBIAN/control
|
||
fi
|
||
|
||
cat ../../control >> DEBIAN/control
|
||
|
||
# scripts ######################################################################
|
||
|
||
cat ../../postinst >> DEBIAN/postinst
|
||
cat ../../postrm >> DEBIAN/postrm
|
||
cat ../../prerm >> DEBIAN/prerm
|
||
cat ../../templates >> DEBIAN/templates
|
||
cat ../../config >> DEBIAN/config
|
||
cp -a -f ../../conffiles DEBIAN/conffiles
|
||
|
||
chmod 644 DEBIAN/control DEBIAN/md5sums DEBIAN/templates DEBIAN/conffiles \
|
||
etc/freenetis/freenetis-dhcp.conf
|
||
|
||
chmod 755 DEBIAN/postinst DEBIAN/postrm DEBIAN/prerm DEBIAN/config \
|
||
etc/init.d/${NAME} usr/sbin/freenetis-dhcp-sync
|
||
|
||
# create deb ###################################################################
|
||
|
||
# change owner of files to root (security)
|
||
cd ..
|
||
fakeroot chown -hR root:root *
|
||
|
||
# make package
|
||
fakeroot dpkg-deb -b tmp ${NAME}_${VERSION}+${DEBIAN}.deb
|
||
|
||
# clean-up mess ################################################################
|
||
|
||
# clean
|
||
rm -rf tmp
|
||
|
deb/postinst | ||
---|---|---|
#!/bin/bash
|
||
# FreenetIS-dhcp DEB: actions after installing of package
|
||
|
||
set -e
|
||
. /usr/share/debconf/confmodule
|
||
|
||
NAME=freenetis-dhcp
|
||
CONFIGFILE=/etc/freenetis/freenetis-dhcp.conf
|
||
|
||
# Quit if config file is missing.
|
||
if [ ! -e $CONFIGFILE ]; then
|
||
echo "$CONFIGFILE not founded!"
|
||
exit 1
|
||
fi
|
||
|
||
. $CONFIGFILE
|
||
|
||
url_regex='(https?|ftp|file)://[-A-Za-z0-9\+&@#/%?=~_|!:,.;]*[-A-Za-z0-9\+&@#/%=~_|]'
|
||
|
||
# Substitute in the values from the debconf db.
|
||
# There are obvious optimizations possible here.
|
||
# The cp before the sed ensures we do not mess up
|
||
# the config file’s ownership and permissions.
|
||
|
||
db_get freenetis-dhcp/path_freenetis
|
||
PATH_FN="$RET"
|
||
|
||
db_get freenetis-dhcp/device_id
|
||
DEVICE_ID="$RET"
|
||
|
||
db_get freenetis-dhcp/timeout
|
||
TIMEOUT="$RET"
|
||
|
||
# check path
|
||
if [ -z "$PATH_FN" ]; then
|
||
echo "Empty path to FreenetIS instance, configuration failed!"
|
||
exit 3
|
||
fi
|
||
|
||
# check path format
|
||
if [[ ! "$PATH_FN" =~ $url_regex ]]; then
|
||
echo "Wrong format of the path to FreenetIS instance, configuration failed!"
|
||
exit 3
|
||
fi
|
||
|
||
# check device ID
|
||
if [[ ! "$DEVICE_ID" =~ ^[0-9]+$ ]] || [ $DEVICE_ID -lt 1 ]; then
|
||
echo "Wrong configuration (ID not set properly), configuration failed!" 1>&2
|
||
exit 1
|
||
fi
|
||
|
||
# check timeout ID
|
||
if [[ ! "$TIMEOUT" =~ ^[0-9]+$ ]] || [ $TIMEOUT -lt 1 ]; then
|
||
echo "Wrong configuration (TIMEOUT not set properly), configuration failed!" 1>&2
|
||
exit 1
|
||
fi
|
||
|
||
cp -a -f $CONFIGFILE $CONFIGFILE.tmp
|
||
|
||
# If the admin deleted or commented some variables but then set
|
||
# them via debconf, (re-)add them to the conffile.
|
||
|
||
test -z "$PATH_FN" || grep -Eq '^ *PATH_FN=' $CONFIGFILE || echo "PATH_FN=" >> $CONFIGFILE
|
||
test -z "$DEVICE_ID" || grep -Eq '^ *DEVICE_ID=' $CONFIGFILE || echo "DEVICE_ID=" >> $CONFIGFILE
|
||
test -z "$TIMEOUT" || grep -Eq '^ *TIMEOUT=' $CONFIGFILE || echo "TIMEOUT=" >> $CONFIGFILE
|
||
|
||
PATH_FN_ESCAPED="${PATH_FN//\//\\/}"
|
||
DEVICE_ID_ESCAPED="${DEVICE_ID//\//\\/}"
|
||
TIMEOUT_ESCAPED="${TIMEOUT//\//\\/}"
|
||
|
||
sed -e "s/^ *PATH_FN=.*/PATH_FN=\"$PATH_FN_ESCAPED\"/" \
|
||
-e "s/^ *DEVICE_ID=.*/DEVICE_ID=\"$DEVICE_ID_ESCAPED\"/" \
|
||
-e "s/^ *TIMEOUT=.*/TIMEOUT=\"$TIMEOUT_ESCAPED\"/" < $CONFIGFILE > $CONFIGFILE.tmp
|
||
|
||
mv -f $CONFIGFILE.tmp $CONFIGFILE
|
||
|
||
# Make post install things
|
||
|
||
# 1) Startup at boot
|
||
|
||
# set on fire after boot
|
||
update-rc.d freenetis-dhcp defaults
|
||
|
||
exit 0
|
deb/postrm | ||
---|---|---|
#!/bin/sh
|
||
# FreenetIS-dhcp DEB: actions before uninstalling of package
|
||
|
||
set -e
|
||
. /usr/share/debconf/confmodule
|
||
|
||
NAME=freenetis-dhcp
|
||
CONFIGFILE=/etc/freenetis/freenetis-dhcp.conf
|
||
|
||
# disable startup from update-rc.d
|
||
set +e
|
||
update-rc.d -f freenetis-dhcp remove
|
||
set -e
|
||
|
||
# remove all configuration if purge
|
||
if [ "$1" = purge ]; then
|
||
# remove defconf values
|
||
if [ -e /usr/share/debconf/confmodule ]; then
|
||
db_purge
|
||
fi
|
||
# remove config files
|
||
rm -rf $CONFIGFILE
|
||
# remove dir if empty
|
||
[ "$(ls -A /etc/freenetis)" ] || rm -rf /etc/freenetis
|
||
fi
|
||
|
||
exit 0
|
deb/prerm | ||
---|---|---|
#!/bin/sh
|
||
# FreenetIS-dhcp DEB: actions before uninstalling of package
|
||
|
||
set -e
|
||
|
||
NAME=freenetis-dhcp
|
||
|
||
# stop daemon
|
||
if [ -x /usr/sbin/invoke-rc.d ]; then
|
||
invoke-rc.d $NAME stop 3>/dev/null || true
|
||
else
|
||
/etc/init.d/$NAME stop 3>/dev/null || true
|
||
fi
|
||
|
||
exit 0
|
deb/templates | ||
---|---|---|
Template: freenetis-dhcp/path_freenetis
|
||
Type: string
|
||
Default: http://localhost/freenetis
|
||
Description: FreenetIS URL:
|
||
Base path to running FreenetIS instance (e.g. http://freenet.org/is)
|
||
Description-cs.UTF-8: FreenetIS URL:
|
||
Cesta ke kořenu běžící instalace FreenetISu (např. http://freenet.org/is)
|
||
|
||
Template: freenetis-dhcp/device_id
|
||
Type: string
|
||
Default:
|
||
Description: Device ID:
|
||
ID of device from FreenetIS.
|
||
Description-cs.UTF-8: ID zařízení:
|
||
ID zařízení z FreenetISu.
|
||
|
||
Template: freenetis-dhcp/timeout
|
||
Type: string
|
||
Default: 300
|
||
Description: Timeout:
|
||
Timeout in seconds after that the synchronization is made (default 5 minutes).
|
||
Description-cs.UTF-8: Timeout:
|
||
Timeout v sekundách, po kterém je provedena synchronizace (defaultně 5 minut).
|
||
|
||
Template: freenetis-dhcp/hack_reload
|
||
Type: boolean
|
||
Default: true
|
||
Description: Hack for propper working of loading package?
|
freenetis-dhcp-sync.rsc | ||
---|---|---|
#######################################################################################################
|
||
# #
|
||
# Author: Michal Kliment #
|
||
# Description: This script regenerate DHCP server from FreenetIS #
|
||
# #
|
||
# Version: 0.1.1 #
|
||
# #
|
||
#######################################################################################################
|
||
|
||
########################################## CONFIG VALUES ##############################################
|
||
|
||
# Base PATH_FN to running FreenetIS instance
|
||
:global PATHFN "http://localhost/freenetis"
|
||
|
||
# ID of device from FreenetIS
|
||
:global DEVICEID 0
|
||
|
||
# Forced download
|
||
:global FORCED 0
|
||
|
||
######################################## SCRIPT - DO NOT CHANGE! ######################################
|
||
|
||
# First run with forced download
|
||
:if ([:len [/file find name="dhcp.rsc"]] = 0) do={
|
||
:set FORCED 1
|
||
}
|
||
|
||
# Download script from FreenetIS
|
||
/tool fetch url="$PATHFN/en/devices/export/$DEVICEID/mikrotik-ip-dhcp-server/text/$FORCED" dst-path="dhcp.rsc"
|
||
|
||
# Waiting to end of downloading
|
||
:delay 3
|
||
|
||
# Run script
|
||
import dhcp.rsc
|
freenetis-dhcp-sync.sh | ||
---|---|---|
#!/bin/bash
|
||
################################################################################
|
||
# #
|
||
# Author: Michal Kliment #
|
||
# Description: This script generates config file of ISC DHCP server #
|
||
# from FreenetIS #
|
||
# #
|
||
# Version: 0.1.1 #
|
||
# #
|
||
################################################################################
|
||
|
||
CONFIG=/etc/freenetis/freenetis-dhcp.conf
|
||
CUSTOM_DHCP_CONF=/etc/dhcp/dhcp.conf.custom
|
||
FORCED=1
|
||
|
||
# Load variables
|
||
if [ -e $CONFIG ]; then
|
||
. $CONFIG || true
|
||
else
|
||
echo "`date -R` Config file is missing at path $CONFIG. Terminating..."
|
||
exit 0
|
||
fi
|
||
|
||
# check config
|
||
if [[ ! "$DEVICE_ID" =~ ^[0-9]+$ ]] || [ $DEVICE_ID -lt 1 ]; then
|
||
echo "[ERROR] `date -R` Wrong configuration (ID not set properly)"
|
||
exit 1
|
||
fi
|
||
|
||
if [[ ! "$TIMEOUT" =~ ^[0-9]+$ ]] || [ $TIMEOUT -lt 1 ]; then
|
||
echo "[ERROR] `date -R` Wrong configuration (TIMEOUT not set properly)"
|
||
exit 1
|
||
fi
|
||
|
||
# endless loop
|
||
while true;
|
||
do
|
||
#path
|
||
if [ "$FORCED" = 1 ]; then # forced download (#474)
|
||
DOWN_PATH="$FULL_PATH/1"
|
||
FORCED=0
|
||
else
|
||
DOWN_PATH="$FULL_PATH"
|
||
fi
|
||
# download
|
||
TMPFILE=`mktemp`
|
||
echo "[INFO] `date -R` Downloading ISC DHCP SERVER config from (${PATH_FN})"
|
||
|
||
if [ "$DEBIAN_VERSION" = lenny ]; then # lenny wget -q DO NOT WORK :-(
|
||
status=`wget --no-check-certificate --server-response "$DOWN_PATH" -O "$TMPFILE" 2>&1 | awk '/^ HTTP/{print $2}'`
|
||
else
|
||
status=`wget --no-check-certificate --server-response -q "$DOWN_PATH" -O "$TMPFILE" 2>&1 | awk '/^ HTTP/{print $2}'`
|
||
fi
|
||
|
||
# make sure that config exist
|
||
touch "$DHCP_CONF"
|
||
|
||
# check download
|
||
if [ "$status" = "200" ]; then
|
||
# attach custom conf if exists
|
||
if [ -r "$CUSTOM_DHCP_CONF" ]; then
|
||
cat "$CUSTOM_DHCP_CONF" >> "$TMPFILE"
|
||
fi
|
||
# config has been change
|
||
if [ `diff "$TMPFILE" "$DHCP_CONF" | wc -l` -gt 0 ]; then
|
||
echo "[INFO] `date -R` Downloaded (code: $status)"
|
||
echo "[INFO] `date -R` Backuping old config to $DHCP_CONF.save"
|
||
mv -f "$DHCP_CONF" "$DHCP_CONF".save
|
||
echo "[INFO] `date -R` Loading new config to $DHCP_CONF.save..."
|
||
# copy config
|
||
mv -f "$TMPFILE" "$DHCP_CONF"
|
||
#restart DHCP server
|
||
echo "[INFO] `date -R` Restarting ISC DHCP server"
|
||
|
||
if [ "$DEBIAN_VERSION" = lenny ]; then # lenny do not have ISC
|
||
/etc/init.d/dhcp3-server restart 2>&1 >/dev/null
|
||
else # squeeze, wheezy, ...
|
||
service isc-dhcp-server restart 2>&1 >/dev/null
|
||
fi
|
||
else
|
||
echo "[INFO] `date -R` No change -> keeping old configuration"
|
||
fi
|
||
elif [[ "$status" =~ ^30[0-9] ]]; then
|
||
echo "[INFO] `date -R` DHCP configuration not changed"
|
||
elif [ "$status" = "404" ]; then
|
||
echo "[ERROR] `date -R` Download failed (code: $status). Wrong path to FreenetIS or device $DEVICE_ID not exists."
|
||
elif [ "$status" = "403" ]; then
|
||
echo "[ERROR] `date -R` Download failed (code: $status). Device $DEVICE_ID not configured properly."
|
||
else
|
||
echo "[ERROR] `date -R` Download failed (code: $status)"
|
||
fi
|
||
|
||
rm -f "$TMPFILE"
|
||
sleep $TIMEOUT
|
||
done
|
freenetis-dhcp.conf | ||
---|---|---|
################################################################################
|
||
# #
|
||
# Author: Michal Kliment, Ondrej Fibich #
|
||
# Description: This script generates config file of ISC DHCP server #
|
||
# from FreenetIS. #
|
||
# #
|
||
################################################################################
|
||
|
||
# Base PATH_FN to running FreenetIS instance
|
||
PATH_FN=http://localhost/freenetis
|
||
|
||
# ID of device from FreenetIS
|
||
DEVICE_ID=0
|
||
|
||
# Timeout in seconds after that the synchronization is made
|
||
TIMEOUT=300
|
||
|
||
# Log file, change to /dev/null to disable logging
|
||
LOG_FILE=/var/log/freenetis-dhcp.log
|
||
|
||
# Filename with ISC DHCP server config
|
||
DHCP_CONF="/etc/dhcp/dhcpd.conf"
|
||
|
||
# This file (if exists) is attached to generated DHCP conf file
|
||
CUSTOM_DHCP_CONF="/etc/dhcp/dhcpd.conf.custom"
|
||
|
||
# Full path [DO NOT CHANGE THIS VARIABLE!!!]
|
||
FULL_PATH=$PATH_FN"/index.php/en/devices/export/"$DEVICE_ID"/debian-etc-dhcp-dhcpd/text"
|
freenetis-dhcp.init.sh | ||
---|---|---|
#! /bin/bash
|
||
|
||
### BEGIN INIT INFO
|
||
# Provides: freenetis-dhcp
|
||
# Required-Start: $remote_fs
|
||
# Required-Stop: $remote_fs
|
||
# Should-Start: $network $syslog
|
||
# Should-Stop: $network $syslog
|
||
# Default-Start: 2 3 4 5
|
||
# Default-Stop: 0 1 6
|
||
# Short-Description: Start and stop freenetis DHCP sync daemon
|
||
# Description: FreenetIS initialization DHCP synchronization script.
|
||
### END INIT INFO
|
||
|
||
################################################################################
|
||
# #
|
||
# This script serves for initialization of DHCP of IS FreenetIS #
|
||
# #
|
||
# Author Ondrej Fibich 2013 #
|
||
# Email ondrej.fibic@gmail.com #
|
||
# #
|
||
# Name freenetis-dhcp.init.sh #
|
||
# Version 0.1.1 #
|
||
# #
|
||
################################################################################
|
||
|
||
#Load variables from config file
|
||
CONFIG=/etc/freenetis/freenetis-dhcp.conf
|
||
|
||
# Path to DHCP synchronization file
|
||
DHCP_SYNCFILE=/usr/sbin/freenetis-dhcp-sync
|
||
|
||
#Load variables
|
||
if [ -f ${CONFIG} ]; then
|
||
. $CONFIG;
|
||
else
|
||
echo "Config file is missing at path $CONFIG."
|
||
echo "Terminating..."
|
||
exit 0
|
||
fi
|
||
|
||
start_dhcp ()
|
||
{
|
||
if [ `ps aux | grep "$DHCP_SYNCFILE" | grep -v grep | wc -l` -gt 0 ]; then
|
||
echo "Already started"
|
||
return 0
|
||
fi
|
||
|
||
cat /dev/null > "$LOG_FILE"
|
||
|
||
echo -n "Starting FreenetIS DHCP deamon: "
|
||
nohup "$DHCP_SYNCFILE" >> "$LOG_FILE" 2>&1 &
|
||
|
||
# test if daemon is started
|
||
if [ `ps aux | grep "$DHCP_SYNCFILE" | grep -v grep | wc -l` -gt 0 ];
|
||
then
|
||
echo "OK"
|
||
else
|
||
echo "FAILED!"
|
||
fi
|
||
|
||
return 0
|
||
}
|
||
|
||
stop_dhcp ()
|
||
{
|
||
if [ `ps aux | grep "$DHCP_SYNCFILE" | grep -v grep | wc -l` -lt 1 ]; then
|
||
echo "Already stopped"
|
||
return 0
|
||
fi
|
||
|
||
#Killing of process by sigterm
|
||
echo -n "Stopping FreenetIS DHCP deamon: "
|
||
set +e
|
||
killall freenetis-dhcp-sync
|
||
set -e
|
||
|
||
# test if daemon is stopped
|
||
if [ `ps aux | grep "$DHCP_SYNCFILE" | grep -v grep | wc -l` -eq 0 ];
|
||
then
|
||
echo "OK"
|
||
else
|
||
echo "FAILED!";
|
||
fi
|
||
|
||
return 0
|
||
}
|
||
|
||
status_dhcp ()
|
||
{
|
||
if [ `ps aux | grep "$DHCP_SYNCFILE" | grep -v grep | wc -l` -gt 0 ]; then
|
||
echo -n "Freenetis DHCP is running with PID "
|
||
echo `ps aux | grep "$DHCP_SYNCFILE" | grep -v grep | awk '{print $2}'`
|
||
return 0
|
||
else
|
||
echo "Freenetis DHCP is not running"
|
||
return 0
|
||
fi
|
||
}
|
||
|
||
usage_dhcp ()
|
||
{
|
||
echo "usage : `echo $0` (start|stop|restart|status|help)"
|
||
}
|
||
|
||
help_dhcp ()
|
||
{
|
||
echo " start - initialization of synchronization of DHCP"
|
||
echo " stop - stops synchronization of DHCP"
|
||
echo " restart - restarts synchronization of DHCP"
|
||
echo " status - returns current state of DHCP synchronization"
|
||
echo " help - prints help for DHCP synchronization"
|
||
}
|
||
|
||
# Is parameter #1 zero length?
|
||
if [ -z "$1" ]; then
|
||
usage_dhcp
|
||
exit 0
|
||
fi;
|
||
|
||
case "$1" in
|
||
|
||
start)
|
||
start_dhcp
|
||
exit 0
|
||
;;
|
||
|
||
restart|reload|force-reload) # reload is same thing as reload
|
||
stop_dhcp
|
||
start_dhcp
|
||
exit 0
|
||
;;
|
||
|
||
stop)
|
||
stop_dhcp
|
||
exit 0
|
||
;;
|
||
|
||
status)
|
||
status_dhcp
|
||
exit 0
|
||
;;
|
||
|
||
help)
|
||
usage_dhcp
|
||
help_dhcp
|
||
exit 0
|
||
;;
|
||
|
||
*)
|
||
usage_dhcp
|
||
exit 0
|
||
;;
|
||
|
||
esac
|
||
|
||
exit 0
|
freenetis-dhcp.lenny.conf | ||
---|---|---|
################################################################################
|
||
# #
|
||
# Author: Michal Kliment, Ondrej Fibich #
|
||
# Description: This script generates config file of DHCP3 server #
|
||
# from FreenetIS. #
|
||
# #
|
||
################################################################################
|
||
|
||
# Base PATH_FN to running FreenetIS instance
|
||
PATH_FN=http://localhost/freenetis
|
||
|
||
# ID of device from FreenetIS
|
||
DEVICE_ID=0
|
||
|
||
# Timeout in seconds after that the synchronization is made
|
||
TIMEOUT=300
|
||
|
||
# Log file, change to /dev/null to disable logging
|
||
LOG_FILE=/var/log/freenetis-dhcp.log
|
||
|
||
# Filename with ISC DHCP server config
|
||
DHCP_CONF="/etc/dhcp3/dhcpd.conf"
|
||
|
||
# This file (if exists) is attached to generated DHCP conf file
|
||
CUSTOM_DHCP_CONF="/etc/dhcp3/dhcpd.conf.custom"
|
||
|
||
# Full path [DO NOT CHANGE THIS VARIABLE!!!]
|
||
FULL_PATH=$PATH_FN"/index.php/en/devices/export/"$DEVICE_ID"/debian-etc-dhcp-dhcpd/text"
|
||
|
||
# Debian version for init script
|
||
DEBIAN_VERSION=lenny
|
Také k dispozici: Unified diff
Adds files from the main FreenetIS repository and enhances DEB package.