Debian Codegraph @

tools/configure_pulse.sh

raw
1 #!/bin/bash
2
3 # This script configures Pulse to work both in the graphical environment and in the console with root apps.
4
5 if [[ $(whoami) != "root" ]]; then
6 # Get the current user's XDG_HOME
7 xdgPath="${XDG_CONFIG_HOME:-$HOME/.config}"
8 mkdir -p "$xdgPath/pulse"
9
10 # Warn user if we are going to overwrite an existing default.pa
11 if [ -f "$xdgPath/pulse/default.pa" ]; then
12 read -p "This will replace the current file located at $xdgPath/pulse/default.pa, press enter to continue or control+c to abort. " continue
13 fi
14 echo '.include /etc/pulse/default.pa
15 load-module module-switch-on-connect
16 load-module module-native-protocol-unix auth-anonymous=1 socket=/tmp/pulse.sock' > $xdgPath/pulse/default.pa
17 echo "If you have not yet done so, please run this script as root to write the client.conf file."
18 else
19 # This section does the root part:
20 xdgPath="/root/.config"
21 mkdir -p "$xdgPath/pulse"
22
23 # Warn user if we are going to overwrite an existing default.pa
24 if [ -f "$xdgPath/pulse/default.pa" ]; then
25 read -p "This will replace the current file located at $xdgPath/pulse/default.pa, press enter to continue or control+c to abort. " continue
26 fi
27
28 cat << EOF > "$xdgPath/pulse/client.conf"
29 # This file is part of PulseAudio.
30 #
31 # PulseAudio is free software; you can redistribute it and/or modify
32 # it under the terms of the GNU Lesser General Public License as published by
33 # the Free Software Foundation; either version 2 of the License, or
34 # (at your option) any later version.
35 #
36 # PulseAudio is distributed in the hope that it will be useful, but
37 # WITHOUT ANY WARRANTY; without even the implied warranty of
38 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
39 # General Public License for more details.
40 #
41 # You should have received a copy of the GNU Lesser General Public License
42 # along with PulseAudio; if not, see <http://www.gnu.org/licenses/>.
43
44 ## Configuration file for PulseAudio clients. See pulse-client.conf(5) for
45 ## more information. Default values are commented out. Use either ; or # for
46 ## commenting.
47
48 ; default-sink =
49 ; default-source =
50 default-server = unix:/tmp/pulse.sock
51 ; default-dbus-server =
52
53 autospawn = no
54 ; autospawn = yes
55 ; daemon-binary = /usr/bin/pulseaudio
56 ; extra-arguments = --log-target=syslog
57
58 ; cookie-file =
59
60 ; enable-shm = yes
61 ; shm-size-bytes = 0 # setting this 0 will use the system-default, usually 64 MiB
62
63 ; auto-connect-localhost = no
64 ; auto-connect-display = no
65 EOF
66 echo "If you have not yet done so, run this script as your normal user to write the user default.pa"
67 fi
68
69 # If there were no errors tell user to restart, else warn them errors happened.
70 if [ $? -eq 0 ]; then
71 echo "Configuration created successfully, please restart Pulseaudio or your system, for changes to take affect."
72 else
73 echo "Errors were encountered whilst writing the configuration, please correct them manually."
74 fi
75 exit 0