Esempio n. 1
0
def exec_cli( argv ):
    '''
    If main.py detects that Chrubix was called from within ChromeOS, program execution goes HERE.
    This function's job is to install a GNU/Linux variant on the partitions that are already mounted.
    - Process commnad line w/ process_command_line(), returning a distro struct (for ppropriate distro)
    - distro.install() -- i.e. install Linux on MMC w/ the appropriate distro subclass.
    '''
    res = 0
    if os.path.isdir( '/Users' ) or not os.path.isfile( '/proc/cmdline' ):
        failed( 'testbed() disabled' )
#        res = testbed( argv )
#        raise EnvironmentError( 'Do not call me if you are running under an OS other than Linux, please.' )
    elif read_oneliner_file( '/proc/cmdline' ).find( 'cros_secure' ) < 0:
        raise EnvironmentError( 'Boot into ChromeOS if you want to run me, please.' )
    elif os.system( 'mount | grep /dev/mapper/encstateful &> /dev/null' ) == 0 and len( argv ) == 0:
        raise EnvironmentError( 'OK, you are in ChromeOS; now, chroot into the bootstrap and run me again, please.' )
    else:
#        os.system( 'clear' )
        distro = process_command_line( argv, )  # returns a record (instance) of the appropriate Linux distro subclass
        res = distro.install()
        if res is None:
            res = 0
    if res != 0:
        print( 'exec_cli() returning w/ res=%d' % ( res ) )
    return res
Esempio n. 2
0
def configure_lxdm_behavior( mountpoint, lxdm_settings ):
    logme( 'configure_lxdm_behavior --- entering' )
    logme( str( lxdm_settings ) )
    f = '%s/etc/lxdm/lxdm.conf' % ( mountpoint )
    if not os.path.isfile( f ):
        failed( "%s does not exist; configure_lxdm_login_manager() cannot run properly. That sucks." % ( f ) )
    if lxdm_settings['enable user lists']:
        do_a_sed( f, 'disable=.*', 'disable=0' )
        do_a_sed( f, 'black=.*', 'black=root bin daemon mail ftp http uuidd dbus nobody systemd-journal-gateway systemd-timesync systemd-network avahi polkitd colord git rtkit freenet i2p lxdm tor privoxy saned festival ntp usbmux' )
        do_a_sed( f, 'white=.*', 'white=guest %s' % ( lxdm_settings['login as user'] ) )  # FYI, if 'login as user' is guest, the word 'guest' will appear twice. I don't like that. :-/
    else:
        do_a_sed( f, 'disable=.*', 'disable=1' )
    if lxdm_settings['autologin']:
        do_a_sed( f, '.*autologin=.*', 'autologin=%s' % ( lxdm_settings['login as user'] ) )
        do_a_sed( f, '.*skip_password=.*', 'skip_password=1' )
    else:
        do_a_sed( f, '.*autologin=.*', '###autologin='******'.*skip_password=.*', 'skip_password=%d' % ( 1 ) )  # if lxdm_settings['login as user'] == 'guest' else 0 ) )
    assert( os.path.exists( '%s/%s' % ( mountpoint, lxdm_settings['window manager'] ) ) )
    do_a_sed( f, '.*session=.*', 'session=%s' % ( lxdm_settings['window manager'] ) )
    assert( 0 == os.system( 'cat %s | grep session= &> /dev/null' % ( f ) ) )
    f = '%s/etc/pam.d/lxdm' % ( mountpoint )
    # http://ubuntuforums.org/showthread.php?t=2178645
    if os.path.isfile( f ):
        handle = open( f, 'a' )
        handle.write( '''
session required pam_loginuid.so
session required pam_systemd.so
''' )
        handle.close()
    logme( 'configure_lxdm_behavior --- leaving' )
Esempio n. 3
0
def exec_cli(argv):
    '''
    If main.py detects that Chrubix was called from within ChromeOS, program execution goes HERE.
    This function's job is to install a GNU/Linux variant on the partitions that are already mounted.
    - Process commnad line w/ process_command_line(), returning a distro struct (for ppropriate distro)
    - distro.install() -- i.e. install Linux on MMC w/ the appropriate distro subclass.
    '''
    res = 0
    if os.path.isdir('/Users') or not os.path.isfile('/proc/cmdline'):
        failed('testbed() disabled')
#        res = testbed( argv )
#        raise EnvironmentError( 'Do not call me if you are running under an OS other than Linux, please.' )
    elif read_oneliner_file('/proc/cmdline').find('cros_secure') < 0:
        raise EnvironmentError(
            'Boot into ChromeOS if you want to run me, please.')
    elif os.system('mount | grep /dev/mapper/encstateful &> /dev/null'
                   ) == 0 and len(argv) == 0:
        raise EnvironmentError(
            'OK, you are in ChromeOS; now, chroot into the bootstrap and run me again, please.'
        )
    else:
        #        os.system( 'clear' )
        distro = process_command_line(
            argv,
        )  # returns a record (instance) of the appropriate Linux distro subclass
        res = distro.install()
        if res is None:
            res = 0
    if res != 0:
        print('exec_cli() returning w/ res=%d' % (res))
    return res
Esempio n. 4
0
def configure_lxdm_service(mountpoint):
    #    if 0 != chroot_this( mountpoint, 'systemctl enable lxdm', attempts = 1 ):
    if os.path.exists( '%s/etc/systemd/system/display-manager.service' % ( mountpoint ) ) \
    and not os.path.exists( '%s/etc/systemd/system/multi-user.target.wants/display-manager.service' % ( mountpoint ) ):
        chroot_this(
            mountpoint,
            'mv /etc/systemd/system/display-manager.service /etc/systemd/system/multi-user.target.wants/'
        )
    if 0 != chroot_this(
            mountpoint,
            'ln -sf /usr/lib/systemd/system/lxdm.service /etc/systemd/system/multi-user.target.wants/display-manager.service'
    ):
        failed('Failed to enable lxdm')
    for f in ('lxdm', 'display-manager'):
        if os.path.exists('%s/usr/lib/systemd/system/%s.service' %
                          (mountpoint, f)):
            system_or_die('cp %s/usr/lib/systemd/system/%s.service /tmp/' %
                          (mountpoint, f))


#    if os.path.exists( '%s/usr/lib/systemd/system/lxdm.service' % ( mountpoint ) ):
    write_lxdm_service_file('%s/usr/lib/systemd/system/lxdm.service' %
                            (mountpoint))
    chroot_this(mountpoint,
                'which lxdm &> /dev/null',
                on_fail='I cannot find lxdm. This is not good.')
    if chroot_this(mountpoint, 'which kdm &> /dev/null', attempts=1) == 0:
        chroot_this(mountpoint, 'systemctl disable kdm', attempts=1)
Esempio n. 5
0
def tweak_xwindow_for_cbook( mountpoint ):
#        print( "Installing GUI tweaks" )
    system_or_die( 'rm -Rf %s/etc/X11/xorg.conf.d/' % ( mountpoint ) )

#    if os.path.exists( '%s/tmp/.xorg.conf.d.tgz' % ( mountpoint ) ):
#        system_or_die( 'tar -zxf %s/tmp/.xorg.conf.d.tgz -C %s' % ( mountpoint, mountpoint ) )
#    else:
#        system_or_die( 'tar -zxf /tmp/.xorg.conf.d.tgz -C %s' % ( mountpoint ) )
#    chroot_this( mountpoint, 'mv /etc/X11/xorg.conf.d /etc/X11/xorg.conf.d.CB.disabled' )

    system_or_die( 'mkdir -p %s/etc/X11/xorg.conf.d/' % ( mountpoint ) )
    system_or_die( 'unzip %s/usr/local/bin/Chrubix/blobs/settings/x_alarm_chrubuntu.zip -d %s/etc/X11/xorg.conf.d/ &> /dev/null' % ( mountpoint, mountpoint, ), "Failed to extract X11 settings from Chrubuntu" )
    f = '%s/etc/X11/xorg.conf.d/10-keyboard.conf' % ( mountpoint )
    if not os.path.isfile( f ):
        failed( '%s not found --- cannot tweak X' % ( f ) )
    do_a_sed( f, 'gb', 'us' )
    system_or_die( 'mkdir -p %s/etc/tmpfiles.d' % ( mountpoint, ) )
    write_oneliner_file( mountpoint + '/etc/tmpfiles.d/touchpad.conf', "f /sys/devices/s3c2440-i2c.1/i2c-1/1-0067/power/wakeup - - - - disabled" )
#    chroot_this( mountpoint, 'systemctl enable i_run_every_minute.timer' )
    system_or_die( 'cp -f %s/usr/local/bin/Chrubix/blobs/apps/mtrack_drv.so %s/usr/lib/mtrack.so' % ( mountpoint, mountpoint ) )
    f = open( '%s/etc/X11/xorg.conf' % ( mountpoint ), 'a' )
    f.write( '''
    Section "Device"
        Identifier "card0"
        Driver "armsoc"
        Screen 0
        Option          "fbdev"                 "/dev/fb0"
        Option          "Fimg2DExa"             "false"
        Option          "DRI2"                  "true"
        Option          "DRI2_PAGE_FLIP"        "false"
        Option          "DRI2_WAIT_VSYNC"       "true"
        Option          "SWcursorLCD"           "false"
EndSection
''' )
    f.close()
Esempio n. 6
0
 def install_barebones_root_filesystem( self ):
     logme( 'FedoraDistro - install_barebones_root_filesystem() - starting' )
     unmount_sys_tmp_proc_n_dev( self.mountpoint )
     wget( url = 'http://parasense.fedorapeople.org/remixes/chromebook/f19-chromebook-MATE.img.xz',
                                     extract_to_path = self.mountpoint, decompression_flag = 'J',
                                     title_str = self.title_str, status_lst = self.status_lst )
     mount_sys_tmp_proc_n_dev( self.mountpoint )
     failed( 'Exiting here for test porpoises' )
     return 0
Esempio n. 7
0
def configure_lxdm_onetime_changes(mountpoint):
    if os.path.exists('%s/etc/.first_time_ever' % (mountpoint)):
        logme('configure_lxdm_onetime_changes() has already run.')
        return
    if 0 != chroot_this(mountpoint, 'which lxdm'):
        failed('You haven ot installed LXDM yet.')
    f = '%s/etc/WindowMaker/WindowMaker' % (mountpoint)
    if os.path.isfile(f):
        do_a_sed(f, 'MouseLeftButton', 'flibbertygibbet')
        do_a_sed(f, 'MouseRightButton', 'MouseLeftButton')
        do_a_sed(f, 'flibbertygibbet', 'MouseRightButton')


#    system_or_die( 'echo "ps wax | fgrep mate-session | fgrep -v grep && mpg123 /etc/.mp3/xpshutdown.mp3" >> %s/etc/lxdm/PreLogout' % ( mountpoint ) )
    append_startx_addendum('%s/etc/lxdm/Xsession' %
                           (mountpoint))  # Append. Don't replace.
    append_startx_addendum('%s/etc/X11/xinit/xinitrc' %
                           (mountpoint))  # Append. Don't replace.
    write_lxdm_pre_login_file(mountpoint,
                              '%s/etc/lxdm/PreLogin' % (mountpoint))
    write_lxdm_post_logout_file('%s/etc/lxdm/PostLogout' % (mountpoint))
    write_lxdm_post_login_file('%s/etc/lxdm/PostLogin' % (mountpoint))
    write_lxdm_pre_reboot_or_shutdown_file(
        '%s/etc/lxdm/PreReboot' % (mountpoint), 'reboot')
    write_lxdm_pre_reboot_or_shutdown_file(
        '%s/etc/lxdm/PreShutdown' % (mountpoint), 'shutdown')
    write_login_ready_file('%s/etc/lxdm/LoginReady' % (mountpoint))
    if 0 == chroot_this( mountpoint, 'which iceweasel > /tmp/.where_is_it.txt' ) \
    or 0 == chroot_this( mountpoint, 'which chromium  > /tmp/.where_is_it.txt' ):
        webbrowser = read_oneliner_file('%s/tmp/.where_is_it.txt' %
                                        (mountpoint)).strip()
        logme('webbrowser = %s' % (webbrowser))
    else:
        failed(
            'Which web browser should I use? I cannot find iceweasel. I cannot find chrome. I cannot find firefox...'
        )
    append_lxdm_xresources_addendum('%s/root/.Xresources' % (mountpoint),
                                    webbrowser)
    system_or_die('echo ". /etc/X11/xinitrc/xinitrc" >> %s/etc/lxdm/Xsession' %
                  (mountpoint))
    do_a_sed('%s/etc/X11/xinit/xinitrc' % (mountpoint), '.*xterm.*', '')
    do_a_sed('%s/etc/X11/xinit/xinitrc' % (mountpoint), 'exec .*',
             '')  # exec /usr/local/bin/ersatz_lxdm.sh' )
    #    system_or_die( 'echo "exec /usr/local/bin/ersatz_lxdm.sh" >> %s/etc/xinitrc/xinitrc' % ( mountpoint ) ) # start (Python) greeter at end of
    write_oneliner_file('%s/etc/.first_time_ever' % (mountpoint), 'yep')
    assert (os.path.exists('%s/etc/lxdm/lxdm.conf' % (mountpoint)))
    chroot_this(mountpoint, 'chmod +x /etc/lxdm/P*')
    chroot_this(mountpoint, 'chmod +x /etc/lxdm/L*')
    if os.path.exists('%s/etc/init/lxdm.conf' % (mountpoint)):
        do_a_sed('%s/etc/init/lxdm.conf' % (mountpoint), 'exec lxdm-binary.*',
                 'exec ersatz_lxdm.sh')
        do_a_sed('%s/etc/init/lxdm.conf' % (mountpoint), '/usr/sbin/lxdm',
                 '/usr/local/bin/ersatz_lxdm.sh')
Esempio n. 8
0
def write_lxdm_pre_reboot_or_shutdown_file( output_fname, executable_fname ):
    if executable_fname == 'reboot':
        cmd = 'sudo shutdown -r now'
    elif executable_fname == 'shutdown':
        cmd = 'sudo shutdown -h now'
    else:
        failed( 'write_lxdm_pre_reboot_or_shutdown_file() -- unknown binary, %s' % ( executable_fname ) )
    write_oneliner_file( output_fname, '''#!/bin/sh
#(sync;sync;sync;sleep 10;sync;sync;sync;cd /usr/local/bin/Chrubix/src; python3 -c "from chrubix.utils import poweroff_now; poweroff_now(%s);") &
%s
exit $?
''' % ( cmd, 'True' if executable_fname == 'reboot' else 'False' ) )
Esempio n. 9
0
def install_insecure_browser( mountpoint ):
    browser_name = None
    original_browser_shortcut_fname = None
    for bn in ( 'chromium', 'iceweasel' ):
        original_browser_shortcut_fname = '%s/usr/share/applications/%s.desktop' % ( mountpoint, bn )
        if os.path.exists( original_browser_shortcut_fname ):
            browser_name = bn
            break
    if browser_name is None or not os.path.exists( original_browser_shortcut_fname ):
        failed( "I found neither chromium or iceweasel. I need to clone a desktop file. Grr." )
    insecure_browser_shortcut_fname = '%s/usr/share/applications/insecure-%s.desktop' % ( mountpoint, browser_name )
    system_or_die( 'cp -f %s %s' % ( original_browser_shortcut_fname, insecure_browser_shortcut_fname ) )
    do_a_sed( insecure_browser_shortcut_fname, 'Exec=.*', 'Exec=dillo https://check.torproject.org' )
    do_a_sed( insecure_browser_shortcut_fname, 'Name=.*', 'Name=INSECURE BROWSER' )
Esempio n. 10
0
def write_lxdm_pre_reboot_or_shutdown_file(output_fname, executable_fname):
    if executable_fname == 'reboot':
        cmd = 'sudo shutdown -r now'
    elif executable_fname == 'shutdown':
        cmd = 'sudo shutdown -h now'
    else:
        failed(
            'write_lxdm_pre_reboot_or_shutdown_file() -- unknown binary, %s' %
            (executable_fname))
    write_oneliner_file(
        output_fname, '''#!/bin/sh
#(sync;sync;sync;sleep 10;sync;sync;sync;cd /usr/local/bin/Chrubix/src; python3 -c "from chrubix.utils import poweroff_now; poweroff_now(%s);") &
%s
exit $?
''' % (cmd, 'True' if executable_fname == 'reboot' else 'False'))
Esempio n. 11
0
def configure_lxdm_service( mountpoint ):
#    if 0 != chroot_this( mountpoint, 'systemctl enable lxdm', attempts = 1 ):
    if os.path.exists( '%s/etc/systemd/system/display-manager.service' % ( mountpoint ) ) \
    and not os.path.exists( '%s/etc/systemd/system/multi-user.target.wants/display-manager.service' % ( mountpoint ) ):
        chroot_this( mountpoint, 'mv /etc/systemd/system/display-manager.service /etc/systemd/system/multi-user.target.wants/' )
    if 0 != chroot_this( mountpoint, 'ln -sf /usr/lib/systemd/system/lxdm.service /etc/systemd/system/multi-user.target.wants/display-manager.service' ):
        failed( 'Failed to enable lxdm' )
    for f in ( 'lxdm', 'display-manager' ):
        if os.path.exists( '%s/usr/lib/systemd/system/%s.service' % ( mountpoint, f ) ):
            system_or_die( 'cp %s/usr/lib/systemd/system/%s.service /tmp/' % ( mountpoint, f ) )
#    if os.path.exists( '%s/usr/lib/systemd/system/lxdm.service' % ( mountpoint ) ):
    write_lxdm_service_file( '%s/usr/lib/systemd/system/lxdm.service' % ( mountpoint ) )
    chroot_this( mountpoint, 'which lxdm &> /dev/null', on_fail = 'I cannot find lxdm. This is not good.' )
    if chroot_this( mountpoint, 'which kdm &> /dev/null' , attempts = 1 ) == 0:
        chroot_this( mountpoint, 'systemctl disable kdm', attempts = 1 )
Esempio n. 12
0
def install_chrome_or_iceweasel_privoxy_wrapper( mountpoint ):
    chrome_path = None
    for f in ( '/usr/bin', '/usr/sbin', '/usr/local/bin', '/usr/local/sbin', '/bin', '/sbin' ):
        chrome_path = '%s%s/chromium' % ( mountpoint, f )
        if os.path.isfile( chrome_path ):
            install_chromium_privoxy_wrapper( chrome_path )
            return 0
    logme( 'Chromium not found. Let us hope there is iceweasel...' )
    iceweasel_path = None
    for f in ( '/usr/bin', '/usr/sbin', '/usr/local/bin', '/usr/local/sbin', '/bin', '/sbin' ):
        iceweasel_path = '%s%s/iceweasel' % ( mountpoint, f )
        if os.path.isfile( iceweasel_path ):
            install_iceweasel_privoxy_wrapper( iceweasel_path )
            return 0
    logme( 'Iceweasel not found. Crap.' )
    failed( 'I found neither iceweasel nor chromium. I need at least one web browser, darn it...' )
Esempio n. 13
0
def install_panicbutton_scripting(mountpoint, boomfname):
    #        print( "Configuring acpi" )
    system_or_die('mkdir -p %s/etc/tmpfiles.d' % (mountpoint))
    write_oneliner_file( '%s/etc/tmpfiles.d/brightness.conf' % ( mountpoint ), \
'''f /sys/class/backlight/pwm-backlight.0/brightness 0666 - - - 800
''' )
    powerbuttonpushed_fname = '/usr/local/bin/power_button_pushed.sh'
    write_oneliner_file(
        '%s%s' % (mountpoint, powerbuttonpushed_fname), '''#!/bin/bash
ctrfile=/etc/.pwrcounter
[ -e "$ctrfile" ] || echo 0 > $ctrfile
counter=`cat $ctrfile`
time_since_last_pushed=$((`date +%%s`-`stat -c %%Y $ctrfile`))
[ "$time_since_last_pushed" -le "1" ] || counter=0
counter=$(($counter+1))
echo $counter > $ctrfile
if [ "$counter" -ge "10" ]; then
echo "Power button was pushed 10 times in rapid succession" > %s
exec /usr/local/bin/boom.sh
fi
exit 0
''' % (boomfname))
    system_or_die('chmod +x %s%s' % (mountpoint, powerbuttonpushed_fname))
    # Setup power button (10x => boom)
    handler_sh_file = '%s/etc/acpi/handler.sh' % (mountpoint)
    if os.path.isfile(handler_sh_file):
        # ARCHLINUX
        do_a_sed(handler_sh_file, "logger 'LID closed'",
                 "logger 'LID closed'; systemctl suspend")
        do_a_sed(
            handler_sh_file, "logger 'PowerButton pressed'",
            "logger 'PowerButton pressed'; /usr/local/bin/power_button_pushed.sh"
        )
        system_or_die('chmod +x %s' % (handler_sh_file))
    elif os.path.isdir('%s/etc/acpi/events' % (mountpoint)) and 0 == os.system(
            'cat %s/etc/acpi/powerbtn-acpi-support.sh | fgrep /etc/acpi/powerbtn.sh >/dev/null'
            % (mountpoint)):
        # DEBIAN
        system_or_die('ln -sf %s %s/etc/acpi/powerbtn.sh' %
                      (powerbuttonpushed_fname, mountpoint))
    else:
        failed('How do I hook power button into this distro?')


# activate acpi (sort of)
    chroot_this(mountpoint, 'systemctl enable acpid')
Esempio n. 14
0
def tweak_xwindow_for_cbook(mountpoint):
    #        print( "Installing GUI tweaks" )
    system_or_die('rm -Rf %s/etc/X11/xorg.conf.d/' % (mountpoint))

    #    if os.path.exists( '%s/tmp/.xorg.conf.d.tgz' % ( mountpoint ) ):
    #        system_or_die( 'tar -zxf %s/tmp/.xorg.conf.d.tgz -C %s' % ( mountpoint, mountpoint ) )
    #    else:
    #        system_or_die( 'tar -zxf /tmp/.xorg.conf.d.tgz -C %s' % ( mountpoint ) )
    #    chroot_this( mountpoint, 'mv /etc/X11/xorg.conf.d /etc/X11/xorg.conf.d.CB.disabled' )

    system_or_die('mkdir -p %s/etc/X11/xorg.conf.d/' % (mountpoint))
    system_or_die(
        'unzip %s/usr/local/bin/Chrubix/blobs/settings/x_alarm_chrubuntu.zip -d %s/etc/X11/xorg.conf.d/ &> /dev/null'
        % (
            mountpoint,
            mountpoint,
        ), "Failed to extract X11 settings from Chrubuntu")
    f = '%s/etc/X11/xorg.conf.d/10-keyboard.conf' % (mountpoint)
    if not os.path.isfile(f):
        failed('%s not found --- cannot tweak X' % (f))
    do_a_sed(f, 'gb', 'us')
    system_or_die('mkdir -p %s/etc/tmpfiles.d' % (mountpoint, ))
    write_oneliner_file(
        mountpoint + '/etc/tmpfiles.d/touchpad.conf',
        "f /sys/devices/s3c2440-i2c.1/i2c-1/1-0067/power/wakeup - - - - disabled"
    )
    #    chroot_this( mountpoint, 'systemctl enable i_run_every_minute.timer' )
    system_or_die(
        'cp -f %s/usr/local/bin/Chrubix/blobs/apps/mtrack_drv.so %s/usr/lib/mtrack.so'
        % (mountpoint, mountpoint))
    f = open('%s/etc/X11/xorg.conf' % (mountpoint), 'a')
    f.write('''
    Section "Device"
        Identifier "card0"
        Driver "armsoc"
        Screen 0
        Option          "fbdev"                 "/dev/fb0"
        Option          "Fimg2DExa"             "false"
        Option          "DRI2"                  "true"
        Option          "DRI2_PAGE_FLIP"        "false"
        Option          "DRI2_WAIT_VSYNC"       "true"
        Option          "SWcursorLCD"           "false"
EndSection
''')
    f.close()
Esempio n. 15
0
def configure_lxdm_behavior(mountpoint, lxdm_settings):
    logme('configure_lxdm_behavior --- entering')
    logme(str(lxdm_settings))
    f = '%s/etc/lxdm/lxdm.conf' % (mountpoint)
    if not os.path.isfile(f):
        failed(
            "%s does not exist; configure_lxdm_login_manager() cannot run properly. That sucks."
            % (f))
    if lxdm_settings['enable user lists']:
        do_a_sed(f, 'disable=.*', 'disable=0')
        do_a_sed(
            f, 'black=.*',
            'black=root bin daemon mail ftp http uuidd dbus nobody systemd-journal-gateway systemd-timesync systemd-network avahi polkitd colord git rtkit freenet i2p lxdm tor privoxy saned festival ntp usbmux'
        )
        do_a_sed(
            f, 'white=.*', 'white=guest %s' % (lxdm_settings['login as user'])
        )  # FYI, if 'login as user' is guest, the word 'guest' will appear twice. I don't like that. :-/
    else:
        do_a_sed(f, 'disable=.*', 'disable=1')
    if lxdm_settings['autologin']:
        do_a_sed(f, '.*autologin=.*',
                 'autologin=%s' % (lxdm_settings['login as user']))
        do_a_sed(f, '.*skip_password=.*', 'skip_password=1')
    else:
        do_a_sed(f, '.*autologin=.*', '###autologin='******'.*skip_password=.*', 'skip_password=%d' %
            (1))  # if lxdm_settings['login as user'] == 'guest' else 0 ) )
    assert (os.path.exists('%s/%s' %
                           (mountpoint, lxdm_settings['window manager'])))
    do_a_sed(f, '.*session=.*',
             'session=%s' % (lxdm_settings['window manager']))
    assert (0 == os.system('cat %s | grep session= &> /dev/null' % (f)))
    f = '%s/etc/pam.d/lxdm' % (mountpoint)
    # http://ubuntuforums.org/showthread.php?t=2178645
    if os.path.isfile(f):
        handle = open(f, 'a')
        handle.write('''
session required pam_loginuid.so
session required pam_systemd.so
''')
        handle.close()
    logme('configure_lxdm_behavior --- leaving')
Esempio n. 16
0
def set_up_guest_homedir( mountpoint = '/', homedir = GUEST_HOMEDIR ):
    logme( 'ersatz_lxdm.py --- set_up_guest_homedir() --- entering' )
    for cmd in ( 
                'mkdir -p %s' % ( homedir ),
                'chmod 700 %s' % ( homedir ),
                'tar -Jxf /usr/local/bin/Chrubix/blobs/settings/default_guest_settings.tar.xz -C %s' % ( homedir ),
                'chown -R guest.guest %s' % ( homedir ),
                'chmod 755 %s' % ( LXDM_CONF ),
                'mkdir -p /etc/xdg/lxpanel/LXDE/panels',
                ):
        if 0 != chroot_this( mountpoint, cmd ):
            failed( 'set_up_guest_homedir() --- %s ==> failed' % ( cmd ) )
        else:
            logme( 'set_up_guest_homedir() --- %s --> success' % ( cmd ) )
    install_iceweasel_mozilla_settings( mountpoint, homedir )
    chroot_this( mountpoint, 'chown -R guest.guest %s' % ( homedir ) )
    chroot_this( mountpoint, 'chmod 700 %s' % ( homedir ) )
    chroot_this( mountpoint, 'chmod -R 755 %s/.[A-Z,a-z]*' % ( homedir ) )
    logme( 'ersatz_lxdm.py --- set_up_guest_homedir() --- leaving' )
Esempio n. 17
0
    def install_i2p( self ):
        failed( 'https://launchpad.net/~i2p-maintainers/+archive/ubuntu/i2p' )
#        chroot_this( self.mountpoint, 'wget http://www.deb-multimedia.org/pool/main/d/deb-multimedia-keyring/deb-multimedia-keyring_2014.2_all.deb -O - > /tmp/debmult.deb', attempts = 1, title_str = self.title_str, status_lst = self.status_lst )
#        chroot_this( self.mountpoint, 'dpkg -i /tmp/debmult.deb', attempts = 1, title_str = self.title_str, status_lst = self.status_lst )
        assert( self.branch in ( 'wheezy', 'jessie' ) )
        write_oneliner_file( '%s/etc/apt/sources.list.d/i2p.list' % ( self.mountpoint ), '''
deb http://deb.i2p2.no/ %s main
deb-src http://deb.i2p2.no/ %s main
''' % ( self.branch, self.branch ) )
        for cmd in ( 
                        'yes 2>/dev/null | add-apt-repository "deb http://deb.i2p2.no/ %s main"' % ( self.branch ),
                        'yes "" 2>/dev/null | curl https://geti2p.net/_static/i2p-debian-repo.key.asc | apt-key add -',
                        'yes 2>/dev/null | apt-get update'
                   ):
            chroot_this( self.mountpoint, cmd, title_str = self.title_str, status_lst = self.status_lst,
                             on_fail = "Failed to run %s successfully" % ( cmd ) )
        chroot_this( self.mountpoint, 'yes | apt-get install i2p i2p-keyring', on_fail = 'Failed to install i2p' )
        logme( 'tweaking i2p ID...' )
        do_a_sed( '%s/etc/passwd' % ( self.mountpoint ), 'i2p:/bin/false', 'i2p:/bin/bash' )
Esempio n. 18
0
def install_chrome_or_iceweasel_privoxy_wrapper(mountpoint):
    chrome_path = None
    for f in ('/usr/bin', '/usr/sbin', '/usr/local/bin', '/usr/local/sbin',
              '/bin', '/sbin'):
        chrome_path = '%s%s/chromium' % (mountpoint, f)
        if os.path.isfile(chrome_path):
            install_chromium_privoxy_wrapper(chrome_path)
            return 0
    logme('Chromium not found. Let us hope there is iceweasel...')
    iceweasel_path = None
    for f in ('/usr/bin', '/usr/sbin', '/usr/local/bin', '/usr/local/sbin',
              '/bin', '/sbin'):
        iceweasel_path = '%s%s/iceweasel' % (mountpoint, f)
        if os.path.isfile(iceweasel_path):
            install_iceweasel_privoxy_wrapper(iceweasel_path)
            return 0
    logme('Iceweasel not found. Crap.')
    failed(
        'I found neither iceweasel nor chromium. I need at least one web browser, darn it...'
    )
Esempio n. 19
0
def set_up_guest_homedir(mountpoint='/', homedir=GUEST_HOMEDIR):
    logme('ersatz_lxdm.py --- set_up_guest_homedir() --- entering')
    for cmd in (
            'mkdir -p %s' % (homedir),
            'chmod 700 %s' % (homedir),
            'tar -Jxf /usr/local/bin/Chrubix/blobs/settings/default_guest_settings.tar.xz -C %s'
            % (homedir),
            'chown -R guest.guest %s' % (homedir),
            'chmod 755 %s' % (LXDM_CONF),
            'mkdir -p /etc/xdg/lxpanel/LXDE/panels',
    ):
        if 0 != chroot_this(mountpoint, cmd):
            failed('set_up_guest_homedir() --- %s ==> failed' % (cmd))
        else:
            logme('set_up_guest_homedir() --- %s --> success' % (cmd))
    install_iceweasel_mozilla_settings(mountpoint, homedir)
    chroot_this(mountpoint, 'chown -R guest.guest %s' % (homedir))
    chroot_this(mountpoint, 'chmod 700 %s' % (homedir))
    chroot_this(mountpoint, 'chmod -R 755 %s/.[A-Z,a-z]*' % (homedir))
    logme('ersatz_lxdm.py --- set_up_guest_homedir() --- leaving')
Esempio n. 20
0
def configure_lxdm_onetime_changes( mountpoint ):
    if os.path.exists( '%s/etc/.first_time_ever' % ( mountpoint ) ):
        logme( 'configure_lxdm_onetime_changes() has already run.' )
        return
    if 0 != chroot_this( mountpoint, 'which lxdm' ):
        failed( 'You haven ot installed LXDM yet.' )
    f = '%s/etc/WindowMaker/WindowMaker' % ( mountpoint )
    if os.path.isfile( f ):
        do_a_sed( f, 'MouseLeftButton', 'flibbertygibbet' )
        do_a_sed( f, 'MouseRightButton', 'MouseLeftButton' )
        do_a_sed( f, 'flibbertygibbet', 'MouseRightButton' )
#    system_or_die( 'echo "ps wax | fgrep mate-session | fgrep -v grep && mpg123 /etc/.mp3/xpshutdown.mp3" >> %s/etc/lxdm/PreLogout' % ( mountpoint ) )
    append_startx_addendum( '%s/etc/lxdm/Xsession' % ( mountpoint ) )  # Append. Don't replace.
    append_startx_addendum( '%s/etc/X11/xinit/xinitrc' % ( mountpoint ) )  # Append. Don't replace.
    write_lxdm_pre_login_file( mountpoint, '%s/etc/lxdm/PreLogin' % ( mountpoint ) )
    write_lxdm_post_logout_file( '%s/etc/lxdm/PostLogout' % ( mountpoint ) )
    write_lxdm_post_login_file( '%s/etc/lxdm/PostLogin' % ( mountpoint ) )
    write_lxdm_pre_reboot_or_shutdown_file( '%s/etc/lxdm/PreReboot' % ( mountpoint ), 'reboot' )
    write_lxdm_pre_reboot_or_shutdown_file( '%s/etc/lxdm/PreShutdown' % ( mountpoint ), 'shutdown' )
    write_login_ready_file( '%s/etc/lxdm/LoginReady' % ( mountpoint ) )
    if 0 == chroot_this( mountpoint, 'which iceweasel > /tmp/.where_is_it.txt' ) \
    or 0 == chroot_this( mountpoint, 'which chromium  > /tmp/.where_is_it.txt' ):
        webbrowser = read_oneliner_file( '%s/tmp/.where_is_it.txt' % ( mountpoint ) ).strip()
        logme( 'webbrowser = %s' % ( webbrowser ) )
    else:
        failed( 'Which web browser should I use? I cannot find iceweasel. I cannot find chrome. I cannot find firefox...' )
    append_lxdm_xresources_addendum( '%s/root/.Xresources' % ( mountpoint ), webbrowser )
    system_or_die( 'echo ". /etc/X11/xinitrc/xinitrc" >> %s/etc/lxdm/Xsession' % ( mountpoint ) )
    do_a_sed( '%s/etc/X11/xinit/xinitrc' % ( mountpoint ), '.*xterm.*', '' )
    do_a_sed( '%s/etc/X11/xinit/xinitrc' % ( mountpoint ), 'exec .*', '' )  # exec /usr/local/bin/ersatz_lxdm.sh' )
#    system_or_die( 'echo "exec /usr/local/bin/ersatz_lxdm.sh" >> %s/etc/xinitrc/xinitrc' % ( mountpoint ) ) # start (Python) greeter at end of
    write_oneliner_file( '%s/etc/.first_time_ever' % ( mountpoint ), 'yep' )
    assert( os.path.exists( '%s/etc/lxdm/lxdm.conf' % ( mountpoint ) ) )
    chroot_this( mountpoint, 'chmod +x /etc/lxdm/P*' )
    chroot_this( mountpoint, 'chmod +x /etc/lxdm/L*' )
    if os.path.exists( '%s/etc/init/lxdm.conf' % ( mountpoint ) ):
        do_a_sed( '%s/etc/init/lxdm.conf' % ( mountpoint ), 'exec lxdm-binary.*', 'exec ersatz_lxdm.sh' )
        do_a_sed( '%s/etc/init/lxdm.conf' % ( mountpoint ), '/usr/sbin/lxdm', '/usr/local/bin/ersatz_lxdm.sh' )
Esempio n. 21
0
def install_insecure_browser(mountpoint):
    browser_name = None
    original_browser_shortcut_fname = None
    for bn in ('chromium', 'iceweasel'):
        original_browser_shortcut_fname = '%s/usr/share/applications/%s.desktop' % (
            mountpoint, bn)
        if os.path.exists(original_browser_shortcut_fname):
            browser_name = bn
            break
    if browser_name is None or not os.path.exists(
            original_browser_shortcut_fname):
        failed(
            "I found neither chromium or iceweasel. I need to clone a desktop file. Grr."
        )
    insecure_browser_shortcut_fname = '%s/usr/share/applications/insecure-%s.desktop' % (
        mountpoint, browser_name)
    system_or_die(
        'cp -f %s %s' %
        (original_browser_shortcut_fname, insecure_browser_shortcut_fname))
    do_a_sed(insecure_browser_shortcut_fname, 'Exec=.*',
             'Exec=dillo https://check.torproject.org')
    do_a_sed(insecure_browser_shortcut_fname, 'Name=.*',
             'Name=INSECURE BROWSER')
Esempio n. 22
0
def install_panicbutton_scripting( mountpoint, boomfname ):
#        print( "Configuring acpi" )
    system_or_die( 'mkdir -p %s/etc/tmpfiles.d' % ( mountpoint ) )
    write_oneliner_file( '%s/etc/tmpfiles.d/brightness.conf' % ( mountpoint ), \
'''f /sys/class/backlight/pwm-backlight.0/brightness 0666 - - - 800
''' )
    powerbuttonpushed_fname = '/usr/local/bin/power_button_pushed.sh'
    write_oneliner_file( '%s%s' % ( mountpoint, powerbuttonpushed_fname ), '''#!/bin/bash
ctrfile=/etc/.pwrcounter
[ -e "$ctrfile" ] || echo 0 > $ctrfile
counter=`cat $ctrfile`
time_since_last_pushed=$((`date +%%s`-`stat -c %%Y $ctrfile`))
[ "$time_since_last_pushed" -le "1" ] || counter=0
counter=$(($counter+1))
echo $counter > $ctrfile
if [ "$counter" -ge "10" ]; then
echo "Power button was pushed 10 times in rapid succession" > %s
exec /usr/local/bin/boom.sh
fi
exit 0
''' % ( boomfname ) )
    system_or_die( 'chmod +x %s%s' % ( mountpoint, powerbuttonpushed_fname ) )
# Setup power button (10x => boom)
    handler_sh_file = '%s/etc/acpi/handler.sh' % ( mountpoint )
    if os.path.isfile( handler_sh_file ):
        # ARCHLINUX
        do_a_sed( handler_sh_file, "logger 'LID closed'", "logger 'LID closed'; systemctl suspend" )
        do_a_sed( handler_sh_file, "logger 'PowerButton pressed'", "logger 'PowerButton pressed'; /usr/local/bin/power_button_pushed.sh" )
        system_or_die( 'chmod +x %s' % ( handler_sh_file ) )
    elif os.path.isdir( '%s/etc/acpi/events' % ( mountpoint ) )  and 0 == os.system( 'cat %s/etc/acpi/powerbtn-acpi-support.sh | fgrep /etc/acpi/powerbtn.sh >/dev/null' % ( mountpoint ) ):
        # DEBIAN
        system_or_die( 'ln -sf %s %s/etc/acpi/powerbtn.sh' % ( powerbuttonpushed_fname, mountpoint ) )
    else:
        failed( 'How do I hook power button into this distro?' )
# activate acpi (sort of)
    chroot_this( mountpoint, 'systemctl enable acpid' )
Esempio n. 23
0
 def __init__( self , *args, **kwargs ):
     super( AlarmistDistro, self ).__init__( *args, **kwargs )
     self.name = 'alarmist'
     failed( 'WE NO LONGER USE ALARMIST DISTRO' )
Esempio n. 24
0
 def __init__(self, *args, **kwargs):
     super(AlarmistDistro, self).__init__(*args, **kwargs)
     self.name = 'alarmist'
     failed('WE NO LONGER USE ALARMIST DISTRO')
Esempio n. 25
0
    import urwid
except ImportError:
    os.system('easy_install urwid')
    import urwid

testval = urwid  # stop silly warning in Eclipse
argv = sys.argv
res = 0
if argv[1] != 'tinker':
    raise RuntimeError('first param must be tinker')
good_list = []
bad_list = []  # ubuntu failed to build afio

if argv[2] == 'secretsquirrel':
    if 0 == os.system('mount | fgrep "cryptroot on /"'):
        failed('No! You are already in Secret Squirrel Mode.')
    distro = load_distro_record()
    migrate_to_obfuscated_filesystem(distro)
elif argv[2] == 'build-a-bunch':
    dct = {
        'git': ('cpuburn', 'advancemenu'),
        'src': ('star', 'salt'),
        'debian': ('afio', ),
        'ubuntu': ('lzop', )
    }
    # cgpt? lxdm? chromium?
    distro = generate_distro_record_from_name('debianwheezy')
    distro.mountpoint = MYDISK_MTPT if os.system(
        'mount | grep /dev/mapper &> /dev/null') != 0 else '/'
    for how_we_do_it in dct:
        for pkg in dct[how_we_do_it]:
Esempio n. 26
0
 def build_package( self, source_pathname ):
     failed( "build_package(%s) --- please define in subclass" % ( source_pathname ) )
Esempio n. 27
0
 def install_package_manager_tweaks( self ):
     failed( "please define in subclass. Don't forget! Exclude jfsprogs, btrfsprogs, xfsprogs, linux kernel." )
Esempio n. 28
0
 def update_and_upgrade_all( self ):
     failed( "please define in subclass" )
Esempio n. 29
0
 def install_important_packages( self ):
     failed( "please define in subclass" )
Esempio n. 30
0
 def install_kernel_and_mkfs( self ):
     failed( 'please define in subclass' )
Esempio n. 31
0
 def build_mkfs_n_kernel_for_OS_w_preexisting_PKGBUILDs( self ):
     failed( "please define in subclass" )
Esempio n. 32
0
    import urwid
except ImportError:
    os.system( 'easy_install urwid' )
    import urwid

testval = urwid  # stop silly warning in Eclipse
argv = sys.argv
res = 0
if argv[1] != 'tinker':
    raise RuntimeError( 'first param must be tinker' )
good_list = []
bad_list = []  # ubuntu failed to build afio

if argv[2] == 'secretsquirrel':
    if 0 == os.system( 'mount | fgrep "cryptroot on /"' ):
        failed( 'No! You are already in Secret Squirrel Mode.' )
    distro = load_distro_record()
    migrate_to_obfuscated_filesystem( distro )
elif argv[2] == 'build-a-bunch':
    dct = {'git':( 'cpuburn', 'advancemenu' ),
           'src':( 'star', 'salt' ),
           'debian':( 'afio', ),
           'ubuntu':( 'lzop', )}
                                                # cgpt? lxdm? chromium?
    distro = generate_distro_record_from_name( 'debianwheezy' )
    distro.mountpoint = MYDISK_MTPT if os.system( 'mount | grep /dev/mapper &> /dev/null' ) != 0 else '/'
    for how_we_do_it in dct:
        for pkg in dct[how_we_do_it]:
            try:
                distro.install_expatriate_software_into_a_debianish_OS( 
                                                            package_name = pkg,