-
Notifications
You must be signed in to change notification settings - Fork 1
/
camcfg
executable file
·308 lines (273 loc) · 9.7 KB
/
camcfg
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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
#! /bin/bash
# gphoto2 configuration with shell dialog
note() {
echo "camcfg: $*" >&2
}
failure() {
echo "camcfg FAILURE: $*" >&2
}
gphoto2_wrap() {
#note "gphoto2 $@"
gphoto2 "$@" || {
failure "gphoto2 failed. Is the camera plugged in and turned on?"
return 1
}
return 0
}
gphoto2_switch_config() {
## Funktion=Konfiguration vom Typ RADIO umschalten mit + oder -
# $1 Zu verändernder Konfigurationswert, Name im Config-Baum
# $2 + oder - für nächsten oder vorherigen Wert.
# +n oder -n für n-weiten Schritt im config-Index
# keine Angabe = +1
# n ohne '+' oder '-' => +n
# Bei Überschreiten/Unterschreiten des Index wird auf Anfang/Ende vom Index gesetzt
local Choicecount Configlabel Configtype Configcurrent
local Dumpline Dumplineleft Dumplineright
# Konfiguration parsen
while read Dumpline ; do
Dumplineleft="$(cut -d: -f1 <<< $Dumpline)"
Dumplineright="$(cut -d' ' -f2- <<< $Dumpline)"
case $Dumplineleft in
Label) Configlabel="$Dumplineright" ;;
Type) Configtype="$Dumplineright" ;;
Current) Configcurrent="$Dumplineright" ;;
Readonly) ;;
END) ;;
Choice)
[ "$(cut -d' ' -f2 <<<"$Dumplineright")" = "$Configcurrent" ] && Configcurrentindex="$(cut -d' ' -f1 <<<"$Dumplineright")"
Choicecount=$((Choicecount + 1))
;;
"") ;;
esac
done <$Kameradumpfile
case $Configtype in
RADIO) ;;
TEXT|DATE|TOGGLE)
failure "Fehler: Werte vom Typ $TYPE können nicht mit Kommando 'switch' geändert werden."
failure " Bitte Kommando 'set-config-value $1=WERT' oder 'set-config $1' verwenden."
return 1
;;
esac
# Indexänderung berechnen
case $2 in
"+"|"") Change="+1" ;;
"-") Change="-1" ;;
*)
case $(cut -c1 <<< $2) in
"+"|"-") Change="$2" ;;
*) Change="+$2" ;;
esac
;;
esac
Newindex=$(($Configcurrentindex $Change))
# wrap index out of range
[ "$Newindex" -ge "$Choicecount" ] && Newindex=0
[ "$Newindex" -lt "0" ] && Newindex=$((Choicecount -1))
# Neuen Wert ermitteln
while read Dumpline; do
[ "$(cut -d' ' -f2 <<<"$Dumpline")" = "$Newindex" ] && Newcurrent="$(cut -d' ' -f3- <<<"$Dumpline")" && break
done < <(grep Choice <$Kameradumpfile)
# Neuen Index setzen
gphoto2_wrap --set-config-index $1=$Newindex || {
failure "Fehler: $1: $Configlabel $Configcurrent konnte nicht geändert werden"
echo $Configcurrent
return 1
}
echo "$Newcurrent"
return 0
}
gphoto2_get_config() {
## Funktion: Kameraeinstellungen anzeigen
# Usage: [-a | all] [ENTRY]
# ohne Optionen Tabelle aller RADIO/MENU Einstellungen ausgeben
# ENTRY Einstellung von ENTRY ausgeben
# -a, all Tabelle aller Einstellungen ausgeben
# Mit ENTRY: Dump des ENTRY Eintrags ausgeben
local Tabelle Configentry Configlabel Configtype Configcurrent Dumpline Showall
case "${1:-}" in
"-a"|"all") Showall="yes" && shift ;;
*) Showall="no" ;;
esac
case "${1:-}" in
"") # Keine einzelne Einstellung angegeben: Alle RADIO und MENU Einstellungen anzeigen
gphoto2_wrap --list-all-config > $Kameradumpfile || {
failure "Konnte Kamera nicht auslesen"
return 1
}
while read Dumpline ; do
Dumplineleft="$(cut -d: -f1 <<< "$Dumpline")"
case $Dumplineleft in
Label|Type|Current) Dumplineright="$(cut -d' ' -f2- <<< "$Dumpline")" ;;
esac
case $Dumplineleft in
Label) Configlabel="$Dumplineright" ;;
Type) Configtype="$Dumplineright" ;;
Current) Configcurrent="$Dumplineright" ;;
Readonly) ;;
Choice) ;;
END)
echo -n "." >&2 # ...
case $Configtype in
RADIO|MENU)
Tabelle="$Tabelle
${Configentry}§${Configlabel}§${Configcurrent}"
;;
*|TOGGLE|TEXT|DATE)
[ "$Showall" = "yes" ] && Tabelle="$Tabelle
${Configentry}§${Configlabel}§${Configcurrent}"
;;
esac
;;
*) [ "$(cut -c1 <<< "$Dumpline")" = "/" ] && Configentry="$(basename "$Dumpline")" ;;
esac
done < "$Kameradumpfile"
echo ""
# Ergebnis in eine übersichtliche Tabelle verwandeln
Tabelle="$(sort <<< "$Tabelle")"
column -t -s"§" <<< "$Tabelle"
;;
*) # einzelnes Config als Option angegeben
gphoto2_wrap --get-config $1 > $Kameradumpfile && {
case $Showall in
yes) cat $Kameradumpfile ;;
no) grep "Current" <$Kameradumpfile | cut -d' ' -f2- ;;
esac
} || failure "Fehler: Konfiguration der Kamera konnte nicht gelesen werden"
;;
esac
}
gphoto2_configdialog_main() {
# Show overview dialog with all configurable entrys
local Configentry Count Dialogoptions Dialogtitle Line
local ENTRY LABEL TYPE CURRENT
note "Reading config entrys of camera, please wait."
gphoto2_wrap --list-all-config > "$Kameradumpfile" || {
failure "Could not read camera configuration."
return 1
}
declare -i Count="0"
while read -r Line ; do
ENTRY[$Count]="$(basename $Line)"
Count=$Count+1
done < <(look "/" $Kameradumpfile)
declare -i Count="0"
while read -r Line ; do
LABEL[$Count]="$(cut -d ' ' -f2- <<<"$Line")"
Count=$Count+1
done < <(look "Label:" $Kameradumpfile)
declare -i Count="0"
while read -r Line ; do
TYPE[$Count]="$(cut -d ' ' -f2- <<<"$Line")"
Count=$Count+1
done < <(look "Type:" $Kameradumpfile)
declare -i Count="0"
while read -r Line ; do
CURRENT[$Count]="$(cut -d ' ' -f2- <<< "$Line")"
Count=$Count+1
done < <(look "Current:" $Kameradumpfile)
# Sort options, type RADIO first
:> $Kameradumpfile
while [ "$Count" -ge "1" ] ; do
Count=$Count-1
case ${TYPE[$Count]} in
RADIO|MENU) echo -n "AAAA " >> "$Kameradumpfile" ;;
TOGGLE) echo -n "BBBB " >> "$Kameradumpfile" ;;
TEXT) echo -n "DDDD " >> "$Kameradumpfile" ;;
DATE) echo -n "EEEE " >> "$Kameradumpfile" ;;
*) echo -n "CCCC " >> "$Kameradumpfile" ;;
esac
echo "'${ENTRY[$Count]}' '${LABEL[$Count]}§${TYPE[$Count]}§${CURRENT[$Count]}'" >> "$Kameradumpfile"
done
while read -r Line ; do
Dialogoptions="$Dialogoptions $(echo $Line | cut -d ' ' -f2-)"
done < <(sort -V $Kameradumpfile)
Dialogtitle="Choose camera configuration entry."
Configentry=$(eval dialog --column-separator '§' --menu "'$Dialogtitle'" 40 120 30 $Dialogoptions 3>&1 1>&2 2>&3 3>&-)
[ -z "$Configentry" ] && return 1
echo "$Configentry"
return 0
}
gphoto2_configdialog_entry() {
# Show config dialog for single entry
# $1 config entry
local Configentry Count Dialogoptions Line
local INDEX LABEL TYPE CURRENT CHOICE
Configentry="$1"
[ -z "$Configentry" ] && return 1
note "Reading config of $Configentry from camera, please wait."
gphoto2_wrap --get-config $Configentry > $Kameradumpfile || {
failure "Could not read configuration of $Configentry"
return 1
}
INDEX="0"
Dialogoptions=""
LABEL="$(look "Label:" $Kameradumpfile | cut -d ' ' -f2-)"
TYPE="$(look "Type:" $Kameradumpfile | cut -d ' ' -f2-)"
CURRENT="$(look "Current:" $Kameradumpfile | cut -d ' ' -f2-)"
while read -r Line ; do
#CHOICE[$INDEX]=`echo -n $Line | cut -d ' ' -f3-`
CHOICE[$INDEX]="$(cut -d ' ' -f3- <<< "$Line")"
Dialogoptions="$Dialogoptions $INDEX '${CHOICE[$INDEX]}'"
[ "${CHOICE[$INDEX]}" = "$CURRENT" ] && Dialogoptions="$Dialogoptions on" || Dialogoptions="$Dialogoptions off"
INDEX="$((INDEX+1))"
done < <(look "Choice:" "$Kameradumpfile")
case $TYPE in
RADIO|MENU)
INDEX="$(eval dialog --radiolist '"Choice for $Configentry: $LABEL \nCurrent: $CURRENT"' 40 120 30 $Dialogoptions 3>&1 1>&2 2>&3 3>&-)"
[ "$INDEX" ] && {
note "Setting $Configentry=$INDEX => $LABEL ${CHOICE[$INDEX]}"
gphoto2_wrap --set-config-index "$Configentry=$INDEX" || return 1
}
;;
TEXT)
CHOICE="$(eval dialog --inputbox '"New value for $Configentry: $LABEL \nCurrent: $CURRENT"' 12 78 '"$CURRENT"' 3>&1 1>&2 2>&3 3>&-)"
[ "$CHOICE" ] && {
note "Setting $Configentry: $LABEL from $CURRENT to $CHOICE"
gphoto2_wrap --set-config-value "$Configentry=$CHOICE" || return 1
}
;;
TOGGLE)
Dialogoptions="1 Ein off 0 Aus off"
#eval echo --radiolist '"Schalter: $Configentry: $LABEL' 15 70 2 $Dialogoptions
CHOICE="$(eval dialog --radiolist '"Switch: $Configentry: $LABEL"' 15 70 2 $Dialogoptions 3>&1 1>&2 2>&3 3>&-)"
[ "$CHOICE" ] && {
note "Switching $Configentry to $CHOICE"
gphoto2_wrap --set-config-value "$Configentry=$CHOICE" || return 1
}
;;
*)
DIALOGTEXT="Unknown configuration type $TYPE. Output of get-config $Configentry:\n"
while read -r LINE ; do
DIALOGTEXT="${DIALOGTEXT}${LINE}\n"
done < "$Kameradumpfile"
CHOICE="$(eval dialog --inputbox '"$DIALOGTEXT"' 12 78 '"$CURRENT"' 3>&1 1>&2 2>&3 3>&-)"
[ "$CHOICE" ] && {
note "Setting $Configentry to $CHOICE"
gphoto2_wrap --set-config-value "$Configentry=$CHOICE" || return 1
}
;;
esac
return 0
}
main() {
local Kameradumpfile Configentry
Configentry="$@"
Kameradumpfile=/tmp/camcfg.dump
:> $Kameradumpfile
Showall=no
while :; do
# Main dialog
[ -z "$Configentry" ] && {
Configentry="$(gphoto2_configdialog_main)"
}
# Single entry dialog
[ -z "$Configentry" ] && break
gphoto2_configdialog_entry "$Configentry" || break
Configentry=""
done
rm $Kameradumpfile
return 0
}
#gphoto2_get_config "$@"
main "$@"