Example #1
0
def setup_i2c():
    if cuisine.file_exists('/etc/modprobe.d/raspi-blacklist.conf'):
        sudo('sed -i -e \'s/^blacklist i2c-bcm2708/# blacklist i2c-bcm2708/g\' ' +
             '/etc/modprobe.d/raspi-blacklist.conf')
    else:
        # RASPBIAN Release 2015-01-31 or later
        boot_conf = cuisine.text_ensure_line(
            cuisine.file_read('/boot/config.txt'),
            'dtparam=i2c_arm=on'
            )
        cuisine.file_write(
            location = '/boot/config.txt',
            content  = boot_conf,
            mode='755',
            sudo=True
            )
        modules_conf = cuisine.text_ensure_line(
            cuisine.file_read('/etc/modules'),
            'i2c-dev'
            )
        cuisine.file_write(
            location = '/etc/modules',
            content  = modules_conf,
            mode='644',
            sudo=True
            )

    # Repeated Start Condition
    cuisine.file_write(
        location = '/etc/modprobe.d/i2c.conf',
        content  = 'options i2c_bcm2708 combined=1\n',
        mode='644',
        sudo=True
        )
Example #2
0
def config_puppet():
    '''
    Ensure the server directive is in puppet.conf
    '''
    print(green("Writing puppet config file"))
    config_file = '/etc/puppet/puppet.conf'
    line1 = "[agent]"
    line2 = "server = %s" % env.puppet_server
    config_content = file_read(config_file)
    updated_config = text_ensure_line(config_content, line1, line2)
    file_write(config_file, updated_config)
Example #3
0
def setup_wlan():
    if not cuisine.file_exists('/sys/class/net/wlan0'):
        return

    puts(fabric.colors.green('[Setting Wireless LAN]', True))
    wifi_config = None
    try:
        (file, pathname, description) = imp.find_module('wifi_config', ['.'])
        wifi_config = imp.load_module("wifi_config", file, pathname, description)
    except ImportError:
        puts(fabric.colors.red('SKIP WiFi Configuration. (FAILED to load wifi_config.py)', True))
        return 

    cuisine.file_write(
        location = '/etc/wpa_supplicant/wpa_supplicant.conf',
        content  = 'ctrl_interface=DIR=/var/run/wpa_supplicant GROUP=netdev\n'
                 + 'update_config=1\n'
                 + 'network={\n'
                 + ('    ssid=\"%s\"\n' % (wifi_config.WIFI_SSID))
                 + ('    psk=%s\n' % (wifi_config.WIFI_PSK))
                 + '    key_mgmt=WPA-PSK\n'
                 + '    proto=WPA2\n'
                 + '    pairwise=CCMP\n'
                 + '    group=CCMP\n'
                 + '}\n',
        mode='600',
        sudo=True
        )

    sudo('sed -i -e \'s/^wpa-roam \/etc\/wpa_supplicant\/wpa_supplicant.conf/'
         + 'wpa-conf \/etc\/wpa_supplicant\/wpa_supplicant.conf/\' /etc/network/interfaces') 
    sudo('sed -i -e \'s/^iface wlan0 inet manual/iface wlan0 inet dhcp/\' /etc/network/interfaces')

    # NOTE: Wifi の場合は「ホスト名-wifi」でアクセスできるようにする
    dhclient_conf = cuisine.text_ensure_line(
        cuisine.file_read('/etc/dhcp/dhclient.conf'),
        'interface "wlan0" { send host-name = concat (gethostname(), "-wifi"); }'
        )

    cuisine.file_write(
        location = '/etc/dhcp/dhclient.conf',
        content  = dhclient_conf,
        mode='644',
        sudo=True
        )
Example #4
0
	def testEnsureLine( self ):
		some_text = "foo"
		some_text = cuisine.text_ensure_line(some_text, "bar")
		assert some_text == 'foo\nbar'
		some_text = cuisine.text_ensure_line(some_text, "bar")
		assert some_text == 'foo\nbar'
Example #5
0
 def testEnsureLine(self):
     some_text = "foo"
     some_text = cuisine.text_ensure_line(some_text, "bar")
     assert some_text == 'foo\nbar'
     some_text = cuisine.text_ensure_line(some_text, "bar")
     assert some_text == 'foo\nbar'
Example #6
0
def mount_line(line):
    if file_update('/etc/fstab', lambda _: text_ensure_line(_, line)):
        run_as_root('mount -a')