Revize 2255
Přidáno uživatelem Ondřej Fibich před téměř 11 roky(ů)
freenetis/branches/1.1/application/vendors/ssh-keys/freenetis-ssh-keys.conf | ||
---|---|---|
################################################################################
|
||
# #
|
||
# Author: Michal Kliment, Ondrej Fibich #
|
||
# Description: This script updates public SSH keys of admins of the device #
|
||
# given by his freenetIS ID. #
|
||
# #
|
||
################################################################################
|
||
|
||
# Base PATH_FN to running FreenetIS instance
|
||
PATH_FN=http://localhost/freenetis
|
||
|
||
# ID of device from FreenetIS
|
||
DEVICE_ID=0
|
||
|
||
# Log file, change to /dev/null to disable logging
|
||
LOG_FILE=/var/log/freenetis-ssh-keys.log
|
||
|
||
# Filename with authorized keys (commonly authorized_key2 or authorized_keys)
|
||
AUTHORIZED_KEYS="authorized_keys2"
|
||
|
||
# Full path [DO NOT CHANGE THIS VARIABLE!!!]
|
||
FULL_PATH=$PATH_FN"/index.php/en/web_interface/authorized_keys/"$DEVICE_ID
|
freenetis/branches/1.1/application/vendors/ssh-keys/freenetis-ssh-keys-sync.sh | ||
---|---|---|
#!/bin/bash
|
||
################################################################################
|
||
# #
|
||
# Author: Michal Kliment, Ondrej Fibich #
|
||
# Description: This script updates public SSH keys of admins of the device #
|
||
# given by his freenetIS ID. #
|
||
# #
|
||
# Version: 0.2.0 #
|
||
# #
|
||
################################################################################
|
||
|
||
CONFIG=/etc/freenetis/freenetis-ssh-keys.conf
|
||
|
||
# Load variables
|
||
if [ -e $CONFIG ]; then
|
||
. $CONFIG || true
|
||
TMPFILE="/tmp/"$AUTHORIZED_KEYS
|
||
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
|
||
|
||
# SSH config folder
|
||
mkdir -p "$HOME/.ssh/"
|
||
chmod 0700 "$HOME/.ssh/"
|
||
|
||
# download
|
||
rm -f "$TMPFILE"
|
||
echo "[INFO] `date -R` Downloading public SSH keys from (${PATH_FN})"
|
||
status=`wget --no-check-certificate --server-response -q "$FULL_PATH" -O "$TMPFILE" 2>&1 | awk '/^ HTTP/{print $2}'`
|
||
|
||
# check download
|
||
if [ "$status" = "200" ]; then
|
||
# change keys
|
||
if [ $(cat "$TMPFILE" 2> /dev/null | wc -l) -gt 2 ]; then
|
||
echo "[INFO] `date -R` Downloaded (code: $status)"
|
||
echo "[INFO] `date -R` Backuping old keys to $HOME/.ssh/$AUTHORIZED_KEYS.old"
|
||
mv -f "$HOME/.ssh/$AUTHORIZED_KEYS" "$HOME/.ssh/$AUTHORIZED_KEYS.old"
|
||
echo "[INFO] `date -R` Loading bew keys to $HOME/.ssh/$AUTHORIZED_KEYS..."
|
||
mv -f "$TMPFILE" "$HOME/.ssh/$AUTHORIZED_KEYS"
|
||
else
|
||
echo "[ERROR] `date -R` Empty response body -> keeping old configuration"
|
||
fi
|
||
else
|
||
echo "[ERROR] `date -R` Download failed (code: $status)"
|
||
fi
|
freenetis/branches/1.1/application/vendors/deb/freenetis-ssh-keys/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:
|
||
Hack for propper working of loading package.
|
freenetis/branches/1.1/application/vendors/deb/freenetis-ssh-keys/debianization.sh | ||
---|---|---|
#!/bin/sh
|
||
################################################################################
|
||
# Script for debianization of FreenetIS rSSH 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 deb_packages/tmp
|
||
cd deb_packages/tmp
|
||
|
||
mkdir DEBIAN
|
||
mkdir etc
|
||
mkdir etc/freenetis
|
||
mkdir etc/cron.d
|
||
mkdir usr
|
||
mkdir usr/sbin
|
||
|
||
# copy content of package ######################################################
|
||
cp ../../../ssh-keys/freenetis-ssh-keys-sync.sh usr/sbin/freenetis-ssh-keys-sync
|
||
cp ../../../ssh-keys/freenetis-ssh-keys.conf etc/freenetis/
|
||
cp ../../freenetis-ssh-keys/freenetis-ssh-keys.cron etc/cron.d/freenetis-ssh-keys
|
||
|
||
# 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
|
||
cat ../../${NAME}/control >> DEBIAN/control
|
||
|
||
# change log
|
||
|
||
cat ../../${NAME}/changelog >> DEBIAN/changelog
|
||
|
||
# copywriting
|
||
|
||
echo "This package was debianized by Ondrej Fibich <ondrej.fibich@gmail.com> on" >> DEBIAN/copyright
|
||
date -R >> DEBIAN/copyright
|
||
echo "" >> DEBIAN/copyright
|
||
echo "It was downloaded from <http://freenetis.org/>" >> DEBIAN/copyright
|
||
echo "" >> DEBIAN/copyright
|
||
echo "Upstream Author:" >> DEBIAN/copyright
|
||
cat ../../../../../AUTHORS >> DEBIAN/copyright
|
||
echo "" >> DEBIAN/copyright
|
||
echo "License:" >> DEBIAN/copyright
|
||
cat ../../../../../COPYING >> DEBIAN/copyright
|
||
|
||
# scripts ######################################################################
|
||
|
||
cat ../../${NAME}/postinst >> DEBIAN/postinst
|
||
cat ../../${NAME}/postrm >> DEBIAN/postrm
|
||
cat ../../${NAME}/templates >> DEBIAN/templates
|
||
cat ../../${NAME}/config >> DEBIAN/config
|
||
|
||
chmod +x DEBIAN/postinst DEBIAN/postrm DEBIAN/config
|
||
|
||
# create deb ###################################################################
|
||
|
||
# change owner of files to root (security)
|
||
cd ..
|
||
sudo chown -hR root:root *
|
||
sudo chmod g-w tmp/etc/cron.d/freenetis-ssh-keys
|
||
|
||
# make package
|
||
sudo dpkg-deb -b tmp ${NAME}_${VERSION}+${DEBIAN}.deb
|
||
|
||
# clean-up mess ################################################################
|
||
|
||
# clean
|
||
sudo rm -rf tmp
|
||
freenetis/branches/1.1/application/vendors/deb/freenetis-ssh-keys/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
|
freenetis/branches/1.1/application/vendors/deb/freenetis-ssh-keys/control | ||
---|---|---|
Priority: optional
|
||
Section: web
|
||
Pre-Depends: debconf (>= 0.5) | debconf-2.0
|
||
Depends: coreutils, wget, ssh
|
||
Suggests: freenetis
|
||
Architecture: all
|
||
Maintainer: Ondrej Fibich <ondrej.fibich@gmail.com>
|
||
Homepage: http://www.freenetis.org
|
||
Description: FreenetIS SSH keys
|
||
Synchronize public SSH keys of admins of a device in order to allow access via SSH to this 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.
|
freenetis/branches/1.1/application/vendors/deb/freenetis-ssh-keys/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
|
||
|
freenetis/branches/1.1/application/vendors/deb/freenetis-ssh-keys/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
|
freenetis/branches/1.1/application/vendors/deb/freenetis-ssh-keys/conffiles | ||
---|---|---|
/etc/freenetis/freenetis-ssh-keys.conf
|
freenetis/branches/1.1/application/vendors/deb/freenetis-ssh-keys/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
|
freenetis/branches/1.1/application/vendors/deb/freenetis-ssh-keys/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
|
freenetis/branches/1.1/application/vendors/deb/debianization.sh | ||
---|---|---|
exit 1
|
||
fi
|
||
|
||
NAMES=(freenetis freenetis-monitoring freenetis-redirection freenetis-ulogd freenetis-ssh-keys)
|
||
NAMES=(freenetis freenetis-monitoring freenetis-redirection freenetis-ulogd)
|
||
DEBIANS=(lenny squeeze wheezy)
|
||
VERSION=$1
|
||
|
Také k dispozici: Unified diff
Upravy:
- uplne odstraneni freenetis-ssh-keys z hlavniho repozitare, nahrazeno https://github.com/freenetis/freenetis-ssh-keys. Dalsi vyvoj bude probihat pouze v novem repozitari.