File: gomconfig

package info (click to toggle)
gom 0.29.10-3
  • links: PTS
  • area: main
  • in suites: hamm
  • size: 416 kB
  • ctags: 290
  • sloc: ansic: 3,183; sh: 529; makefile: 68
file content (414 lines) | stat: -rw-r--r-- 11,597 bytes parent folder | download
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
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
#!/bin/bash -e
#
# Configuration script for gom, user or systemwide.
#
#
# (c) 1998 Stephan Alexander Suerken <absurd@debian.org>
#

#
# Variables
#
gom_test_options_log=/tmp/gom_test_options.log.$$
gom_test_settings_log=/tmp/gom_test_settings.log.$$

if test `whoami` == root;
    then gomrc_file=/etc/gom/gomrc ;
	 default_settings_file=/etc/gom/default
    else gomrc_file=${HOME}/.gom/gomrc ;
	 default_settings_file=${HOME}/.gom/default
fi

#
# Continue Break
#
gomconfig_break ()
{
    echo -n "Hit RETURN to continue..."; read
}

#
# Test Prototype: $1:gom_options, $2:logfile, $3:logchoice
#
test_status ()
{
    if gom $1 >$2 2>&1 ;
	then echo -n "Fine.      Use '$3' for the log."
             return 0
	else echo -n "Problem.   Error(s) found - use '$3' for the log."
	     return 1
    fi
}

#
# Intro
#
intro ()
{
    echo
    echo "==========================================================================="
    echo "                   Configuring gom for user `whoami`.";
    # Warning for root
    if test `whoami` == root ;
	then echo "                ** Changing SYSTEM configuration **";
    fi
    echo "==========================================================================="
    echo " This configuration script assumes a correctly installed and configured"
    echo "sound driver. If you are using this as part of package configuration"
    echo "(especially when installing from scratch with a default kernel), you"
    echo "possibly need to fix the sound driver first, and rerun this script"
    echo "(gomconfig) later."
    echo
}

#
# Audio Users
#

# a recursive helper
add_audio_users ()
{
    if test -e /etc/debian_version;
	then echo
	     echo "'<user> [RETURN]': Add user to group audio."
	     echo "'[RETURN]'       : Quit adding users."
	     echo
	     echo -n "Add user: "
	     read user
	     if test ! "${user}" == "" ;
		then adduser ${user} audio ;
		     add_audio_users ;
	     fi
	else echo "This is not Debian GNU/Linux."
             echo "I don't know the recommended way to give users audio access on this system."
             echo "You need to figure this out by yourself."
    fi
}

# yet another (not yet recursive) helper
del_audio_users ()
{
    if test -e /etc/debian_version;
	then echo
	     echo "Sorry -- I don't yet know a reasonable and recommended"
	     echo "way to delete a user from a certain group in Debian GNU/Linux."
             echo "Please edit /etc/group manually."
             echo
	else echo
	     echo "This is not Debian GNU/Linux."
             echo "I don't know the recommended way to deny users audio access on this system."
             echo "You need to figure this out by yourself."
	     echo
    fi
}

audio_users_status ()
{
    # Test for Debian
    if test ! -e /etc/debian_version;
	then echo -n "Unknown.  This is not Debian GNU/Linux.";
	else if test `whoami` == root ;
		then if grep --quiet "^audio:.*:.*:$" /etc/group ;
			then echo -n "Problem.   No user in group audio."
			else echo -n "Fine.      At least one user in group audio."
                     fi
		else if grep --quiet "^audio.*`whoami`" /etc/group ;
			then echo -n "Fine.      `whoami` is audio user."
			else echo -n "Problem.   `whoami` is _not_ audio user."
		     fi
	     fi
    fi
}

audio_users ()
{
    echo
    echo "Audio users"
    echo "============"
    echo " Adding a user to the group 'audio' is the recommended way (at least"
    echo "in Debian GNU/Linux) to grant a user to 'do sound', including"
    echo "controlling the soundcard mixer(s) with gom."
    echo
    echo    "[RETURN] : Cancel  (don't touch current settings)."
    echo    "0        : Add     (add user(s) to group audio)."
    echo    "1        : Delete  (delete user(s) from group audio)."
    echo
    echo -n "Current status: "; audio_users_status; echo
    echo -n "Current value : "; grep audio /etc/group || true
    echo 
    if test `whoami` == root ;
       then echo -n "Your choice: "
	    read choice
	    if test "${choice}" == "0" ;
		then add_audio_users
	    elif test "${choice}" == "1"
		then del_audio_users
		else echo
                     echo "Not touching anything...done."
		     echo
	    fi
       else echo "These system settings can only be changed by root."
	    echo
    fi
    gomconfig_break
}

#
# Startup Options
#
startup_options_status ()
{
    if test -e ${gomrc_file} ;
	then echo -n "Installed."
	else if test -e /etc/gom/gomrc ;
                 then echo -n "Purged.    Using system options."
		 else echo -n "Purged.    "
                      if test `whoami` != root ;
			  then echo -n "No system options available!"
		      fi
             fi
    fi
}

startup_options ()
{
    options_stubborn_default="-d/dev/mixer"
    echo
    echo "Startup options"
    echo "================"
    echo " These options are stored in the file '${gomrc_file}'; they"
    echo "will be loaded on every startup of gom."
    if test `whoami` == root ;
       then echo " These system options only have effect if there are no own"
            echo "user options."
       else echo " These user options make the system startup options"
            echo "ineffective."
    fi
    echo " I recommend to only supply one default mixer device (most likely"
    echo "'-d/dev/mixer'); however, you can use all gom one-character"
    echo "options just like on the command line here (but there must not"
    echo "be spaces between an option and its argument!)."
    echo " If you don't have any default options (with at least the mixer"
    echo "device given), you'll need to always explicitly name a mixer as"
    echo "option to gom."
    echo
    echo    "[RETURN] : Cancel  (don't touch anything)."
    echo    "0        : Default (use stubborn default '${options_stubborn_default}')."
    echo    "1        : Purge   (remove configuration file)."
    echo    "2        : Custom  (enter own configuration)."
    echo
    echo -n "Current status: "
    startup_options_status
    echo
    echo -n "Current value : "
    if test -e ${gomrc_file} ;
	then echo "'`cat ${gomrc_file}`'."
	else echo "NULL."
    fi
    echo 
    echo -n "Your choice: "
    read choice
    if test "${choice}" == "0" ;
	then echo -n "Writing default options to '${gomrc_file}'..."
             echo ${options_stubborn_default} >${gomrc_file}
    elif test "${choice}" == "1"
	then echo -n "Purging '${gomrc_file}'..."
	     rm -f ${gomrc_file} 
    elif test "${choice}" == "2"
	then echo -n "Enter custom options: "
	     read options_custom
             echo -n "Writing custom options to '${gomrc_file}'..."
 	     echo ${options_custom} >${gomrc_file}
	else echo
             echo -n "Not touching anything..."
    fi
    echo "done."
    echo
    gomconfig_break
}

#
# Default Settings
#
default_settings_status ()
{
    if test -e ${default_settings_file} ;
	then echo -n "Installed."
	else echo -n "Purged."
    fi
}

default_settings ()
{
    settings_stubborn_default='-M'
    echo
    echo "Default Settings"
    echo "================="
    echo " The file '${default_settings_file}' holds the default mixer"
    echo "settings (loaded with 'gom --get-settings')."
    if test `whoami` == root;
	then echo " These settings should preferably be loaded thusly"
	     echo "at some point of system bootup."
             echo " For the prepackaged version for Debian GNU/Linux, purging"
	     echo "(removing) this file implicitly means not to configure the"
	     echo "mixer at system bootup."
	else echo " These settings should preferably be loaded thusly"
	     echo "at some point of user login."
    fi
    echo
    echo    "[RETURN] : Cancel  (don't touch anything)."
    echo    "0        : Default (use stubborn default '${settings_stubborn_default}', muting all channels)."
    echo    "1        : Purge   (remove configuration file)."
    echo    "2        : Custom  (edit (existing) configuration using interactive gom)."
    echo
    echo -n "Current status: "; default_settings_status; echo
    echo -n "Current value : "
    if test -e ${default_settings_file} ;
	then echo "Sorry, can't display settings in reasonable form here."
	else echo "NULL."
    fi
    echo 
    echo -n "Your choice: "
    read choice
    if test "${choice}" == "0" ;
	then echo -n "Writing default settings to '${default_settings_file}'..."
             echo ${settings_stubborn_default} >${default_settings_file}
    elif test "${choice}" == "1"
	then echo -n "Purging '${default_settings_file}'..."
	     rm -f ${default_settings_file} 
    elif test "${choice}" == "2"
	then echo
	     echo "About to start gom (ncurses interface) to edit the default settings."
 	     echo "You only need to change settings, and then leave with 'q'."
	     echo
	     gomconfig_break
	     echo
	     gom --load-settings --interface=t --save-settings || true
	     echo
             echo -n "Editing default settings..."
	else echo
             echo -n "Not touching anything..."
    fi
    echo "done."
    echo
    gomconfig_break
}


test_anygomrc_file ()
{
    test -e ${gomrc_file} -o -e /etc/gom/gomrc
}

#
# Test Options Run
#
test_options_status ()
{
    if test_anygomrc_file ;
        then test_status "" "${gom_test_options_log}" "4"
	else echo -n "Need some option file first to test."
             return 1
    fi
}

#
# Test Default Load
#
test_settings_status ()
{
    if test_anygomrc_file
        then if test -e ${default_settings_file};
		 then test_status "--get-settings" "${gom_test_settings_log}" "5"
		 else echo -n "Need default settings file first to test."
                      return 1
	     fi
	else echo -n "Need some option file first to test."
             return 1
    fi
}

#
# Overall conf. status:
#
# 0: unconfigured
# 1: sufficiently configured
# 2: fully configured
#
unconfigured ()
{
    echo
    if test_options_status >/dev/null 2>&1 ;
	then if test_settings_status >/dev/null 2>&1 ;
		 then echo "Gom is fully configured for `whoami`."; return 2
		 else echo "Gom is sufficiently configured for `whoami`."; return 1
	     fi
	else echo "Gom is unconfigured for `whoami`."; return 0
    fi
}

#
# View err log
#
view_log ()
{
    echo
    echo "Showing log $1:"
    if test -s $1 ;
	then echo "--START LOG--"
             cat $1
	     echo "---END LOG---"
	else echo "Nothing logged!"
    fi
    gomconfig_break
}

#
# Gom_Configure
#
gom_configure ()
{
    selection='none'
    until test "${selection}" == "q" -o "${selection}" == "Q" ; do
	intro
	echo    "   1. Audio users     : `audio_users_status`"
	echo    "   2. Startup options : `startup_options_status`"
	echo    "      Testing stage 2 : `test_options_status`"
	echo    "   3. Default settings: `default_settings_status`"
	echo    "      Testing stage 3 : `test_settings_status`"
	echo
	echo    "  q,Q: Quit.  (It's save to simply quit if you are unsure.)"
	echo
	echo -n "  Quit or select number: "
	read selection
	if   test "${selection}" == "1"; then audio_users
	elif test "${selection}" == "2"; then startup_options
	elif test "${selection}" == "3"; then default_settings
	elif test "${selection}" == "4"; then view_log ${gom_test_options_log}
	elif test "${selection}" == "5"; then view_log ${gom_test_settings_log}
	fi;
    done
#
# Cleanup
#
    rm -f ${gom_test_options_log} ${gom_test_settings_log}
#
# Write Status
#
    unconfigured || true
}

#
# Start code
#
if unconfigured
    then gom_configure
elif  test "$1" == "--force"
    then gom_configure
elif test "$1" == ""
    then echo
         echo "Use '$0 --force' to reconfigure."
    else echo
         echo "Usage: $0 [--force]"
	 echo "--force forces reconfiguration."
fi