Projekt

Obecné

Profil

« Předchozí | Další » 

Revize 972ee172

Přidáno uživatelem Ondřej Fibich před téměř 11 roky(ů)

Adds script and files for debianization. Adds man page for sync script

Zobrazit rozdíly:

deb/changelog
freenetis-ssh-keys (0.2.0) stable; urgency=low
* First release
-- Ondrej Fibich <ondrej.fibich@gmail.com> Mon, 20 Aug 2012 10:42:19 +0200
deb/conffiles
/etc/freenetis/freenetis-ssh-keys.conf
/etc/cron.d/freenetis-ssh-keys
deb/config
#!/bin/sh
set -e
. /usr/share/debconf/confmodule
CONFIGFILE=/etc/freenetis/freenetis-ssh-keys.conf
# Load config file, if it exists.
if [ -e $CONFIGFILE ]; then
db_get freenetis-ssh-keys/hack_reload
if [ "$RET" = true ]; then
. $CONFIGFILE || true
db_set freenetis-ssh-keys/path_freenetis "$PATH_FN"
db_set freenetis-ssh-keys/device_id "$DEVICE_ID"
fi
fi
# h@ck for not reloading variables from config file (enabled again by postinst)
db_set freenetis-ssh-keys/hack_reload false
# Ask questions.
db_input critical freenetis-ssh-keys/path_freenetis || true
db_input critical freenetis-ssh-keys/device_id || true
db_go || true
deb/control
Priority: optional
Section: web
Pre-Depends: debconf (>= 0.5) | debconf-2.0
Depends: coreutils (>= 6.10-6), wget (>= 1.11-4.1), ssh
Architecture: all
Maintainer: Ondrej Fibich <ondrej.fibich@gmail.com>
Homepage: http://www.freenetis.org
Description: FreenetIS SSH keys
Synchronize public SSH keys of device admins in order to allow access via SSH
to a device that is specified by his FreenetIS ID.
Description-cs.UTF-8: FreenetIS SSH klíče
Synchronizuje veřejné SSH klíče aministrátorů zařizení pro zajištění přístupu
skrze SSH na toto zařízení, které je specifikováno svým FreenetIS ID.
deb/debianization.sh
#!/bin/sh
################################################################################
# Script for debianization of FreenetIS SSH keys
# (c) Ondrej Fibich, 2012
#
# Takes two arguments (version of package - FreenetIS and debian version).
#
################################################################################
if [ $# -ne 2 ]; then
echo "Wrong arg count.. Terminating"
exit 1
fi
NAME=freenetis-ssh-keys
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/cron.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}
mkdir -m 755 usr/share/man
mkdir -m 755 usr/share/man/man1
# copy content of package ######################################################
cp ../../../freenetis-ssh-keys-sync.sh usr/sbin/freenetis-ssh-keys-sync
cp ../../../freenetis-ssh-keys.conf etc/freenetis/
cp ../../freenetis-ssh-keys.cron etc/cron.d/freenetis-ssh-keys
# create info files ############################################################
# create package info
echo "Package: ${NAME}" >> DEBIAN/control
echo "Version: ${VERSION}-${DEBIAN}" >> DEBIAN/control
echo "Installed-Size: ${SIZE}" >> DEBIAN/control
cat ../../control >> DEBIAN/control
# 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
cp ../../../man/freenetis-ssh-keys-sync.1 usr/share/man/man1/
# rights
chmod 644 usr/share/doc/${NAME}/changelog usr/share/doc/${NAME}/changelog.Debian \
usr/share/doc/${NAME}/copyright usr/share/man/man1/freenetis-ssh-keys-sync.1
# compress doc
gzip --best usr/share/doc/${NAME}/changelog
gzip --best usr/share/doc/${NAME}/changelog.Debian
gzip --best usr/share/man/man1/freenetis-ssh-keys-sync.1
# count size
SIZE=`du -s etc usr | cut -f1 | paste -sd+ | bc`
# calculate checksum ###########################################################
find * -type f ! -regex '^DEBIAN/.*' -exec md5sum {} \; >> DEBIAN/md5sums
# scripts ######################################################################
cat ../../postinst >> DEBIAN/postinst
cat ../../postrm >> DEBIAN/postrm
cat ../../templates >> DEBIAN/templates
cat ../../config >> DEBIAN/config
cat ../../conffiles >> DEBIAN/conffiles
chmod 644 DEBIAN/control DEBIAN/md5sums DEBIAN/templates DEBIAN/conffiles \
etc/freenetis/freenetis-ssh-keys.conf etc/cron.d/freenetis-ssh-keys
chmod 755 DEBIAN/postinst DEBIAN/postrm DEBIAN/config \
usr/sbin/freenetis-ssh-keys-sync
# create deb ###################################################################
# change owner of files to root (security)
cd ..
fakeroot chown -hR root:root *
fakeroot chmod g-w tmp/etc/cron.d/freenetis-ssh-keys
# make package
fakeroot dpkg-deb -b tmp ${NAME}_${VERSION}+${DEBIAN}.deb
# clean-up mess ################################################################
# clean
rm -rf tmp
deb/freenetis-ssh-keys.cron
# /etc/cron.d/freenetis-ssh-keys: Regular CRON file for freenetis-ssh-keys package (triggered each minute)
SHELL=/bin/sh
PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin
deb/postinst
#!/bin/bash
# FreenetIS-ssh-keys DEB: actions after installing of package
set -e
. /usr/share/debconf/confmodule
NAME=freenetis-ssh-keys
CONFIGFILE=/etc/freenetis/freenetis-ssh-keys.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-ssh-keys/path_freenetis
PATH_FN="$RET"
db_get freenetis-ssh-keys/device_id
DEVICE_ID="$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
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
PATH_FN_ESCAPED="${PATH_FN//\//\\/}"
DEVICE_ID_ESCAPED="${DEVICE_ID//\//\\/}"
sed -e "s/^ *PATH_FN=.*/PATH_FN=\"$PATH_FN_ESCAPED\"/" \
-e "s/^ *DEVICE_ID=.*/DEVICE_ID=\"$DEVICE_ID_ESCAPED\"/" < $CONFIGFILE > $CONFIGFILE.tmp
mv -f $CONFIGFILE.tmp $CONFIGFILE
# Make post install things
# 1) Rights
# set rights
chmod u+x /usr/sbin/freenetis-ssh-keys-sync
# 2) CRON
echo "Preparing CRON"
echo "# /etc/cron.d/freenetis-ssh-keys: Regular CRON file for freenetis-ssh-keys package (triggered each minute)" > /etc/cron.d/freenetis-ssh-keys
echo "" >> /etc/cron.d/freenetis-ssh-keys
echo "SHELL=/bin/sh" >> /etc/cron.d/freenetis-ssh-keys
echo "PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin" >> /etc/cron.d/freenetis-ssh-keys
echo "* * * * * root /usr/sbin/freenetis-ssh-keys-sync 1>>\"$LOG_FILE\"" >> /etc/cron.d/freenetis-ssh-keys
if [ -x /usr/sbin/invoke-rc.d ]; then
invoke-rc.d cron restart 3>/dev/null || true
else
/etc/init.d/cron restart 3>/dev/null || true
fi
exit 0
deb/postrm
#!/bin/sh
# FreenetIS-ssh-keys DEB: actions before uninstalling of package
set -e
CONFIGFILE=/etc/freenetis/freenetis-ssh-keys.conf
# remove all configuration if purge
if [ "$1" = purge ]; then
# remove defconf values
if [ -e /usr/share/debconf/confmodule ]; then
. /usr/share/debconf/confmodule
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/templates
Template: freenetis-ssh-keys/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-ssh-keys/device_id
Type: string
Default:
Description: Device ID:
ID of device from FreenetIS.
Description-cs.UTF-8: Vstupní rozhraní:
ID zařízení z FreenetISu.
Template: freenetis-ssh-keys/hack_reload
Type: boolean
Default: true
Description: Hack for propper working of loading package?
man/freenetis-ssh-keys-sync.1
.\" Manpage for freenetis-http-302-redirection.1.
.\" Contact ondrej.fibich@gmail.com.in to correct errors or typos.
.TH man 1 "05 November 2013" "1.0" "freenetis-ssh-keys-sync man page"
.SH NAME
freenetis-ssh-keys-sync \- Updates public SSH keys of admins of the device
.SH SYNOPSIS
freenetis-ssh-keys-sync
.SH DESCRIPTION
freenetis-ssh-keys-sync is a part of FreenetIS SSK keys it servers for updating of public SSH keys of admins of the device given by his FreenetIS ID. Path to the FreenetIS and the device ID must be set in the config file.
.SH AUTHOR
Ondrej Fibich <ondrej.fibich@gmail.com>

Také k dispozici: Unified diff