-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathdefaultaction
executable file
·85 lines (68 loc) · 2.17 KB
/
defaultaction
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
#!/bin/bash
# Skript zum einfachen umschalten des Sync-Verhaltens start.conf
# [email protected] Juni 2013
#
#
# usage: defaultaction GRUPPE LABEL [sync/start]
#
# Der betroffene DefaultAction-Eintrag braucht ein Hilfslabel am Ende der Zeile:
# Bsp:
# DefaultAction = sync # ubuntu12-sync
# Wird sync/start weggelassen, schaltet das Skript den Status einfach um.
# Konfiguration
LINBOPFAD=/var/linbo
PREFIX=start.conf
# Parameter in Variablen speichern, dabei den Linbo-Pfad automatisch ergänzen.
STARTCONF=$LINBOPFAD/$PREFIX.$1
LABEL=$2
# offensichtliche Bedienfehler abfangen
# Startkonfiguration existiert nicht:
if [ ! -e $STARTCONF ]
then
echo $STARTCONF existiert nicht... Abbruch >&2
exit 1
fi
# Label nicht vorhanden oder mehrdeutig
UNIQUE=$(grep "$LABEL" "$STARTCONF" | grep -c "efaultAction")
if [ "$UNIQUE" != "1" ]
then
echo Label nicht vorhanden, nicht eindeutig oder nicht in einer Autostart-Zeile... >&2
echo 'USAGE: defaultaction <GRUPPE> <LABEL> <sync|start|status>'
exit 1
fi
case "$3" in
[sS][yY][nN][cC])
SWITCH=SYNC
;;
[sS][tT][aA][rR][tT])
SWITCH=START
;;
[sS][tT][aA][tT][uU][sS])
STATUSQUO=$(grep "$LABEL" "$STARTCONF" |grep "efaultAction" | cut -d" " -f3)
echo -e "DefaultAction in $STARTCONF ist jetzt: $STATUSQUO"
exit 0
;;
*)
STATUSQUO=$(grep "$LABEL" "$STARTCONF" |grep "efaultAction" | cut -d" " -f3)
[[ "$STATUSQUO" == "start" ]] && SWITCH=SYNC || SWITCH=START
;;
esac
# Zeile aus start.conf extrahieren
OLDLINE=$(grep "$LABEL" "$STARTCONF")
case "$SWITCH" in
START)
echo -e "DefaultAction auf \e[00;31mstart OHNE Sync\e[00m schalten..."
NEWLINE=$(echo $OLDLINE | sed -e 's/[sS][yY][nN][cC]/start/g')
;;
SYNC)
echo -e "DefaultAction auf \e[00;32mSYNC\e[00m schalten..."
NEWLINE=$(echo $OLDLINE | sed -e 's/[sS][tT][aA][rR][tT]/sync/g')
;;
*)
echo "Irgendwas ist schief gelaufen, diese Zeile hätte nie ausgeführt werden dürfen..." >&2
exit 1
;;
esac
sed -e "s/$OLDLINE/$NEWLINE/g" -i $STARTCONF
STATUSQUO=$(grep "$LABEL" "$STARTCONF" |grep efaultAction | cut -d" " -f3)
echo -e "DefaultAction in $STARTCONF ist jetzt: $STATUSQUO"