|
| 1 | +#!/bin/bash |
| 2 | +# |
| 3 | +# This is an sdm plugin for: logwatch |
| 4 | +# |
| 5 | +# The plugin is called three times: for Phase 0, Phase 1, and post-install. |
| 6 | +# |
| 7 | + |
| 8 | +function loadparams() { |
| 9 | + source $SDMPT/etc/sdm/sdm-readparams |
| 10 | +} |
| 11 | + |
| 12 | +# $1 is the phase: "0", "1", or "post-install" |
| 13 | +# $2 is the argument list: arg1=val1|arg2=val2|arg3=val3| ... |
| 14 | +# |
| 15 | +# Main code for the Plugin |
| 16 | +# |
| 17 | +phase=$1 |
| 18 | +pfx="$(basename $0)" #For messages |
| 19 | +args="$2" |
| 20 | +vldargs="|config|sendto|sendfrom|" |
| 21 | +assetdir="$SDMPT/etc/sdm/assets/logwatch" |
| 22 | +loadparams |
| 23 | + |
| 24 | +if [ "$phase" == "0" ] |
| 25 | +then |
| 26 | + # |
| 27 | + # In Phase 0 all references to directories in the image must be preceded by $SDMPT |
| 28 | + # |
| 29 | + |
| 30 | + logtoboth "* Plugin $pfx: Start Phase 0" |
| 31 | + plugin_getargs $pfx "$args" "$vldargs" || exit |
| 32 | + plugin_printkeys |
| 33 | + mkdir -p $assetdir |
| 34 | + if [ "$config" != "" ] |
| 35 | + then |
| 36 | + if [ -d $config ] |
| 37 | + then |
| 38 | + logtoboth "> Plugin $pfx: Copy local logwatch config subtree to $assetdir/config" |
| 39 | + mkdir -p $assetdir/config |
| 40 | + rsync -a $config/ $assetdir/config |
| 41 | + |
| 42 | + fi |
| 43 | + fi |
| 44 | + logtoboth "* Plugin $pfx: Complete Phase 0" |
| 45 | + |
| 46 | +elif [ "$phase" == "1" ] |
| 47 | +then |
| 48 | + # |
| 49 | + # Phase 1 (in nspawn) |
| 50 | + # |
| 51 | + logtoboth "* Plugin $pfx: Start Phase 1" |
| 52 | + plugin_getargs $pfx "$args" "$vldargs" || exit |
| 53 | + logtoboth "> Plugin $pfx: Install logwatch" |
| 54 | + installpkgsif logwatch |
| 55 | + if [ -d $assetdir/config ] |
| 56 | + then |
| 57 | + logtoboth "> Plugin $pfx: Copy local logwatch config files into /etc/logwatch" |
| 58 | + rsync -a $assetdir/config/ /etc/logwatch |
| 59 | + if [ -f /etc/logwatch/conf/logwatch.conf ] |
| 60 | + then |
| 61 | + cp /etc/logwatch/conf/logwatch.conf /etc/logwatch/conf/logwatch.conf.sdm |
| 62 | + if [ "$sendto" != "" ] |
| 63 | + then |
| 64 | + sendto=$(stripquotes "$sendto") |
| 65 | + logtoboth "> Plugin $pfx: Set MailTo '$sendto' in logwatch.conf" |
| 66 | + sed -i "s/^MailTo = .*/MailTo = $sendto/" /etc/logwatch/conf/logwatch.conf |
| 67 | + fi |
| 68 | + if [ "$sendfrom" != "" ] |
| 69 | + then |
| 70 | + sendfrom=$(stripquotes "$sendfrom") |
| 71 | + logtoboth "> Plugin $pfx: Set MailFrom '$sendfrom' in logwatch.conf" |
| 72 | + sed -i "s/^MailFrom = .*/MailFrom = $sendfrom/" /etc/logwatch/conf/logwatch.conf |
| 73 | + fi |
| 74 | + fi |
| 75 | + fi |
| 76 | + logtoboth "* Plugin $pfx: Complete Phase 1" |
| 77 | +else |
| 78 | + # |
| 79 | + # Plugin Post-install edits |
| 80 | + # |
| 81 | + logtoboth "* Plugin $pfx: Start Phase post-install" |
| 82 | + |
| 83 | + logtoboth "* Plugin $pfx: Complete Phase post-install" |
| 84 | +fi |
0 commit comments