Skip to content

Commit 1fe764d

Browse files
ali-essamdragosprju
authored andcommitted
Fix install.sh script (#3)
* use separate sudoers file, use system instead of user service
1 parent 8f393c3 commit 1fe764d

File tree

2 files changed

+26
-26
lines changed

2 files changed

+26
-26
lines changed

install.sh

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1-
sudo apt-get install alsa-tools
1+
sudo apt-get install -y alsa-tools
22
username="$(/usr/bin/getent passwd 1000 | /usr/bin/cut -d: -f1)"
3-
sudo echo $username' ALL=NOPASSWD: /usr/bin/hda-verb' >> /etc/sudoers
4-
sudo echo 'guest ALL=NOPASSWD: /usr/bin/hda-verb' >> /etc/sudoers
3+
echo $username' ALL=NOPASSWD: /usr/bin/hda-verb' | sudo EDITOR='tee' visudo -f /etc/sudoers.d/subwoofer
4+
echo 'guest ALL=NOPASSWD: /usr/bin/hda-verb' | sudo EDITOR='tee -a' visudo -f /etc/sudoers.d/subwoofer
55
sudo cp ./subwoofer.py /opt/subwoofer.py
66
sudo chmod +x /opt/subwoofer.py
7-
sudo cp ./subwoofer.service /etc/systemd/user/subwoofer.service
8-
systemctl --user daemon-reload
9-
systemctl --user enable subwoofer
7+
sudo cp ./subwoofer.service /etc/systemd/system/subwoofer.service
8+
systemctl daemon-reload
9+
systemctl enable subwoofer.service
1010
echo "Please restart the computer to start the 'subwoofer' service."

subwoofer.py

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ def calculate_subwoofer_volume(spk_vol, balance):
6767
else:
6868
balL = balL - balance
6969
balR = 100
70-
70+
7171
valL = 87 * spk_vol * balL / 100 / 100 + extraVolume
7272
valR = 87 * spk_vol * balR / 100 / 100 + extraVolume
7373

@@ -77,7 +77,7 @@ def calculate_subwoofer_volume(spk_vol, balance):
7777

7878
def set_subwoofer():
7979
vol = get_biggest_volume()
80-
subVols = calculate_subwoofer_volume(vol, subwooferBalance)
80+
subVols = calculate_subwoofer_volume(vol, subwooferBalance)
8181
set_subwoofer_volume(subVols)
8282

8383
# Speaker part
@@ -97,8 +97,8 @@ def calculate_speaker_balance(spk_vol, balance):
9797

9898
valL = spk_vol * balL / 100
9999
valR = spk_vol * balR / 100
100-
101-
return [valL, valR]
100+
101+
return [valL, valR]
102102

103103
def set_speaker_volumes(volumes):
104104
volumes = calibrate100(volumes)
@@ -116,8 +116,8 @@ def set_speakers():
116116
headphones_set = False
117117

118118
vol = get_biggest_volume()
119-
spkVols = calculate_speaker_balance(vol, speakerBalance)
120-
set_speaker_volumes( spkVols)
119+
spkVols = calculate_speaker_balance(vol, speakerBalance)
120+
set_speaker_volumes( spkVols)
121121

122122
def get_biggest_volume():
123123
volumes = get_volumes()
@@ -136,8 +136,8 @@ def get_volumes():
136136
if '%' in line:
137137
vol = line.split('[')[1].split('%]')[0]
138138
output.append(int(vol))
139-
140-
return output
139+
140+
return output
141141

142142
# Headphones part
143143
#################
@@ -153,14 +153,14 @@ def set_headphones():
153153
speakers_set = False
154154

155155
vol = get_biggest_volume()
156-
spkVols = calculate_speaker_balance(vol, headphonesBalance)
157-
set_speaker_volumes(spkVols)
156+
spkVols = calculate_speaker_balance(vol, headphonesBalance)
157+
set_speaker_volumes(spkVols)
158158

159159
def headphones_in_query():
160160
global headphones_in
161161
amixer = subprocess.Popen(["amixer", "-c", str(devId), "cget", "numid=22"], stdout=subprocess.PIPE, stderr=subprocess.PIPE)
162162

163-
i = 0
163+
i = 0
164164
count = False
165165
for line in iter(amixer.stdout.readline, ''):
166166
if "numid=22" in line:
@@ -172,9 +172,9 @@ def headphones_in_query():
172172
headphones_in = False
173173
elif "values=on" in line:
174174
headphones_in = True
175-
break
176-
177-
amixer.terminate()
175+
break
176+
177+
amixer.terminate()
178178

179179
def check_headphones():
180180
headphones_in_query()
@@ -201,22 +201,22 @@ def calibrate(volumes, limit):
201201
elif volumes[1] < 0:
202202
volumes[1] = 0
203203

204-
return [volumes[0], volumes[1]]
205-
204+
return [volumes[0], volumes[1]]
205+
206206
def calibrate100(volumes):
207207
return calibrate(volumes, 100)
208208

209209
def calibrate87(volumes):
210-
return calibrate(volumes, 87)
210+
return calibrate(volumes, 87)
211211

212-
def check_volume():
212+
def check_volume():
213213
global curr_volume
214214
new_volume = get_biggest_volume()
215215

216216
if curr_volume != new_volume:
217217
curr_volume = new_volume
218218
print "Volume change detected: ", curr_volume
219-
219+
220220
if headphones_in == False:
221221
set_subwoofer()
222222

@@ -259,7 +259,7 @@ def on_exit():
259259
if "Event 'change' on sink #" + sinkNo in line:
260260
check_headphones()
261261
check_volume()
262-
262+
263263

264264

265265

0 commit comments

Comments
 (0)