Example #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
Example #2
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
Example #3
0
 def install_barebones_root_filesystem( self ):
     unmount_sys_tmp_proc_n_dev( self.mountpoint )
     system_or_die( '''curl https://www.offensive-security.com/kali-linux-vmware-arm-image-download/ | grep Samsung | cut -d'"' -f4 > /tmp/url.txt''' )
     url = read_oneliner_file( '/tmp/url.txt' )
     assert( url.find( 'xz' ) >= 0 )
     wget( url = url, extract_to_path = self.mountpoint, decompression_flag = 'J', title_str = self.title_str, status_lst = self.status_lst, attempts = 1 )
     mount_sys_tmp_proc_n_dev( self.mountpoint )
     return 0
Example #4
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')
Example #5
0
 def install_barebones_root_filesystem(self):
     unmount_sys_tmp_proc_n_dev(self.mountpoint)
     system_or_die(
         '''curl https://www.offensive-security.com/kali-linux-vmware-arm-image-download/ | grep Samsung | cut -d'"' -f4 > /tmp/url.txt'''
     )
     url = read_oneliner_file('/tmp/url.txt')
     assert (url.find('xz') >= 0)
     wget(url=url,
          extract_to_path=self.mountpoint,
          decompression_flag='J',
          title_str=self.title_str,
          status_lst=self.status_lst,
          attempts=1)
     mount_sys_tmp_proc_n_dev(self.mountpoint)
     return 0
Example #6
0
    def monitor( self ):
        noof_checks = DELAY_BEFORE_HIDING / TIME_BETWEEN_CHECKS
        if self.cycles > noof_checks:
            self.hide()
#            print( 'hiding again' )
        else:
            self.cycles += 1
#        print( 'checking' )
        if os.path.exists( self.volnow_fname ):
            try:
                new_vol = int( read_oneliner_file( self.volnow_fname ) )
                if new_vol != self.old_vol:
                    self.setVolume( new_vol )
                    self.old_vol = new_vol
            except ValueError:
                logme( 'Bad entry for %s' % ( self.volnow_fname ) )
#        else:
#            print( 'Waiting for .volnow to appear' )
        QTimer.singleShot( TIME_BETWEEN_CHECKS, self.monitor )
Example #7
0
    def monitor( self ):
        noof_checks = DELAY_BEFORE_HIDING / TIME_BETWEEN_CHECKS
        if self.cycles > noof_checks:
            self.hide()
#            print( 'hiding again' )
        else:
            self.cycles += 1
#        print( 'checking' )
        if os.path.exists( self.brightnow_fname ):
            try:
                new_brightness = int( read_oneliner_file( self.brightnow_fname ) )
#                logme( 'curr bri = %d' % ( new_brightness ) )
                if new_brightness != self.old_brightness:
                    self.setBrightness( new_brightness )
                    self.old_brightness = new_brightness
#                    logme( 'Updating brightness to %d' % ( new_brightness ) )
            except ValueError:
                logme( 'Bad entry for %s' % ( self.brightnow_fname ) )
#        else:
#            print( 'Waiting for .brightnow to appear' )
        QTimer.singleShot( TIME_BETWEEN_CHECKS, self.monitor )
Example #8
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' )
Example #9
0
        if real_path.find( os.path.basename( home_drv ) ) >= 0:
#            print( 'Found home drive %s in uuid file %s => %s' % ( home_drv, full_path, real_path ) )
# FIXME Does this subroutine successfully detect the removal of a micro SD card from an SD adapter? I hope so...
            found = True
            break
    return found


#---------------------------------------------------------------------------------------
# TODO: Should we wipe RAM? I think we should.... but HOW?
# See https://bbs.archlinux.org/viewtopic.php?id=136283
#
#---------------------------------------------------------------------------------------

if __name__ == "__main__":
    cmdline = read_oneliner_file( '/proc/cmdline' )
    if cmdline.find( 'cryptdevice=' ) >= 0:
        i = cmdline.find( 'cryptdevice=' )
        home_drive = cmdline[i:].split( '=' )[1].split( ':' )[0]
    else:
        i = cmdline.find( 'root=' )
        home_drive = cmdline[i:].split( '=' )[1].split( ' ' )[0]
    print( 'home_drive = %s' % ( home_drive ) )
    if not home_drive_found_in_udev( home_drive ):
        logme( 'Something is wrong with this program. I cannot find my home drive, even at the start...' )
        sys.exit( 1 )
    while True:
        os.system( 'sleep 0.5' )
        if not home_drive_found_in_udev( home_drive ):
            poweroff_now()
            sys.exit( 0 )