~isantop/system76-driver/pkexec

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
#!/usr/bin/env python
#
## System76, Inc.
## Copyright System76, Inc.
## Released under the GNU General Public License (See LICENSE)
##
## Hotkey setup for keys unsupported by Ubuntu vanilla

## FORMATTING:
## Add new entries like this template:
"""
class exampleDriver():
    def install(self):
        ##Install example Driver
        {code to install goes here}
        {More code}
        
    def describe(self):
        os.system("echo 'Describe example driver here' >> " + descriptionFile)
"""

import os
import fileinput

descriptionFile = "/tmp/sys76-drivers"

class daru1_monitor_switch():
    def install(self):
        
        # Copies required files
        os.system('sudo cp /opt/system76/system76-driver/src/acpi/daru1/asus-display-switch /etc/acpi/events/asus-display-switch')
        os.system('sudo cp /opt/system76/system76-driver/src/acpi/daru1/asus-display-switch.sh /etc/acpi/asus-display-switch.sh')
        os.system('sudo chmod a+x /etc/acpi/asus-display-switch.sh')
        
    def describe(self):
        os.system("echo 'Monitor switch hotkey fix' >> " + descriptionFile)
    
class daru1_touchpad_switch():
    def install(self):
        
        # Enables SHMConfig for FN+F9 touchpad on/off switch
        marker="""<match key="info.product" contains="Synaptics TouchPad">"""
        newLine="""<merge key="input.x11_options.SHMConfig" type="string">On</merge>\n"""
        present = 0
    
        #Check for presence of newLine
        synapticsFile = open('/usr/share/hal/fdi/policy/20thirdparty/11-x11-synaptics.fdi','r')
        for line in synapticsFile:
            if line.strip() == newLine.strip():
                present = 1
    
        #Insert newLine if necessary
        synapticsFile.close()
        synapticsFile = open('/usr/share/hal/fdi/policy/20thirdparty/11-x11-synaptics.fdi','r')
        newFile = open('/opt/system76/newFile.txt','w')
        if present == 0:
            for line in synapticsFile:
                newFile.write(line)
                if line.strip() == marker.strip():
                    newFile.write("        " + newLine)
            synapticsFile.close()
            newFile.close()
            command = "mv /opt/system76/newFile.txt /usr/share/hal/fdi/policy/20thirdparty/11-x11-synaptics.fdi"
            os.system(command)
            
    def describe(self):
        os.system("echo 'Touchpad hotkey fix' >> " + descriptionFile)
        
class star1_904():
    def install(self):
        
        # Copy required files
        os.system('sudo cp /opt/system76/system76-driver/src/hotkeys/star1_904_30-keymap-system76.fdi /usr/share/hal/fdi/information/10freedesktop/30-keymap-system76.fdi')
        os.system('sudo cp /opt/system76/system76-driver/src/hotkeys/star1_904_wlonoff.sh /usr/local/bin/wlonoff.sh')
        os.system('sudo chmod a+x /usr/local/bin/wlonoff.sh')
        
        # Setup sudoers so user can turn on/off wireless without sudo
        for line in fileinput.input("/etc/sudoers",inplace =1):
            line = line.strip()
            if not 'WLTOGGLE' in line:
                print line
                
        os.system("echo Cmnd_Alias      WLTOGGLE=/usr/local/bin/wlonoff.sh | sudo tee -a /etc/sudoers")
        os.system("echo '%admin ALL=(ALL) NOPASSWD: WLTOGGLE' | sudo tee -a /etc/sudoers")
        
        # configure keybinding in gnome
        os.system("gconftool-2 --config-source xml:readwrite:/etc/gconf/gconf.xml.mandatory -s --type string /apps/metacity/keybinding_commands/command_2 'sudo /usr/local/bin/wlonoff.sh'")
        os.system("gconftool-2 --config-source xml:readwrite:/etc/gconf/gconf.xml.mandatory -s --type string /apps/metacity/global_keybindings/run_command_2 XF86WLAN")
        
    def describe(self):
        os.system("echo 'Hotkey fix' >> " + descriptionFile)