Ich hatte oft das Problem, dass ich auf allen moeglichen Plattformen fhem laufen liess.
Natuerlich musste man dann wieder alles zusammenkrabbeln ....
Jeder der alteratives kennt, weiss um die Vorzuege von zentral verwalteten symlinks
Aus diesem Grund habe ich mir etwas einfach zu verwaltendes zurecht gelegt.
Natuerlich will ich meine Arbeit mit euch Teilen und bin fuer Vorschlaege/Mitarbeit dankbar :-)
Bis jetzt wird nur verteilt ... vielleicht spaeter noch eine einfache Verwaltung
Verzeichnisstruktur:
Hauptverzeichnis (variabel, hier package)
|-- config
|-- gplot
|-- icons
Nun das Tool
#!/bin/bash
# Deloyment for custom fhem templates
# Push the whole packages directory into the fhem main directory and
# start this tool from packages as working/current directory
# fhem.cfg will be exchanged from main dir
# all other config-parts will be linked to .../fhem/config: Include ./config/[conffile]
# Have fun ... P33dy
usr="fhem"
grp="fhem"
if [ ! -e fhem.cfg ]; then echo "Fail: you are not current in package directory! Exit"; exit 1; fi
if [ ! -e ../fhem.cfg ]; then echo "Fail: package directory has to be placed in fhem rootdir! Exit"; exit 1; fi
cmp --silent fhem.cfg ../fhem.cfg && echo 'fhem.cfg is up to date ...' || echo -e "fhem.cfg:\tfiles are different! copying ..."; cp fhem.cfg ../fhem.cfg; chown $usr:$grp ../fhem.cfg
if [ ! -d ../config ]; then mkdir ../config; fi
cd ./config
for file in *; do
if [ ! -e ../../config/$file ]; then
pfile=$(realpath $file)
echo -e "$file:\tcreating symlink"
ln -s $pfile ../../config/$file
chown -R $usr:$grp ../../config
else
echo -e "$file:\talready linked"
fi
done
cd ..
cd ./gplot
for file in *; do
if [ ! -h ../../www/gplot/$file ]; then
pfile=$(realpath $file)
echo -e "$file:\tcreating symlink"
ln -s $pfile ../../www/gplot/$file
chown -R $usr:$grp ../../www/gplot
else
echo -e "$file:\talready linked"
fi
done
cd ..
iconalias="../www/images/openautomation/iconalias.txt"
template="./iconalias.txt"
cmp --silent $template $iconalias && echo 'iconalias.txt is up to date ...' || echo -e "iconalias.txt:\tfiles are different! copying ..."; cp $template $iconalias; chown $usr:$grp ../fhem.cfg
# defining your favourite default Icons edit: .../fhem/www/images/openautomation/iconalias.txt
cd ./icons
for file in *; do
if [ ! -h ../../www/images/openautomation/$file ]; then
pfile=$(realpath $file)
echo -e "$file:\tcreating symlink"
ln -s $pfile ../../www/images/openautomation/$file
chown -R $usr:$grp ../../www/images/openautomation
else
echo -e "$file:\talready linked"
fi
done
cd ..
Das war's schon ... viel Spass ;-)
Ich habe das ganze vorherige Scipt ueberarbeitet und es nun aehnlich wie Parcels bei Cloudera umgesetzt.
Somit ist eine wiklich zentrale Verwaltung moeglich, womit ein einfaches Schwenken auf Testszenarien moeglich ist.
Alle Scnarien befinden sich nun in .parcel Verzeichnissen.
in jedem Parcel-Verzeichnis befindet sich eine parcel.info Datei, welche die Verteilung des Inhalts beschreibt.
Deploy und Purge werden dann mit dem Parcelverzeichnis aufgerufen.
Hierbei muss das Tool parcel.sh aus dem "parcels" Verzeichnis aufgerufen werden, welches sich im FHEM-Hauptverzeichnis befinden muss.
Struktur:
fhem (Hauptverzeichnis)
|-- parcels
|-- parcel.sh
|-- test.parcel
|-- parcel.info
|-- ... (content)
parcel.info (Bsp.):
#!/bin/bash
# this parcel file declares which files and places for symlinks
# are deployable
#relation is file to location
#default fhem maindir is declared in $fhemdir
hard=(
["fhem.cfg"]="/"
["iconalias.txt"]="/www/images/openautomation/"
)
#relation is directoy to directory
links=(
["./config"]="/config/"
["./gplot"]="/www/gplot/"
["./svg"]="/www/images/openautomation/"
["./FHEM"]="/FHEM/"
)
und nun zum Tool (Update):
#!/bin/bash
#!/bin/bash
# Deloyment for custom fhem parcels
# start this tool from packages as working/current directory
# Have fun ... P33dy
usr="fhem"
grp="fhem"
fhemdir="../.."
init () {
cd $parceldir || { echo "Can't access $1. EXIT"; exit 1; }
declare -gA hard
declare -gA links
source parcel.info || { echo "Cant't read parcel info file. EXIT"; exit 1; }
}
hardcp () {
cmp --silent $1 $2 \
&& { echo -e "$1\tis up to date ..."; } \
|| { echo -e "$1:\tfiles are different! copying ..."; \
cp $1 $2; \
chown $usr:$grp $2; }
}
linker () {
cd $1
for file in *; do
if [ ! -h $2$file ]; then
pfile=$(realpath $file)
echo -e "$file:\tcreating symlink"
ln -s $pfile $2$file
chown -R $usr:$grp $2
else
echo -e "$file:\talready linked"
fi
done
cd ..
}
rmlnks () {
cd $1
for file in *; do
if [ -h $2$file ]; then
echo -e "Removed: $2$file"
rm -f $2$file
else
echo "Not found: $2$file"
fi
done
cd ..
}
deploy () {
#create backups if not already existent
init
for key in "${!hard[@]}"
do
if [ ! -f "$fhemdir${hard[$key]}$key.bak" ]; then
echo "creating backup of $key"
cp "$fhemdir${hard[$key]}$key" "$fhemdir${hard[$key]}$key.bak"
chown $usr:$grp "$fhemdir${hard[$key]}$key.bak"
fi
done
#copy files
for key in "${!hard[@]}"
do
hardcp $key $fhemdir${hard[$key]}$key
done
#create symlinks
if [ ! -d $fhemdir/config ]; then mkdir $fhemdir/config; fi
for key in "${!links[@]}"
do
linker $key $fhemdir/..${links[$key]}
done
}
purge () {
#restore files
init
pwd
for key in "${!hard[@]}"
do
if [ -f "$fhemdir/${hard[$key]}$key.bak" ]; then
echo "restoring $key"
mv "$fhemdir${hard[$key]}$key.bak" "$fhemdir${hard[$key]}$key"
rm -f "$fhemdir/${hard[$key]}$key.bak"
else
echo "no backup for $key found!"
echo "$fhemdir${hard[$key]}$key.bak"
fi
done
#remove symlinks
for key in "${!links[@]}"
do
rmlnks $key $fhemdir/..${links[$key]}
done
}
parceldir="$2"
case "$1" in
purge)
purge
;;
save)
echo "TBD ..."
;;
deploy)
echo "case"
deploy
;;
*)
echo $"Usage: $0 {deploy|save|purge} [parceldir]"
exit 1
esac
Achja ... beim schwenken von Parcels erst die Verteilung des aktuellen Parcels mit "Purge" entfernen, danach das neue Parcel verteilen :-)