def configure_X_and_start_some_apps(): '''Configure keyboard. Start WindowMaker system tray, florence, GPG applet, and a few other tools. Also, initiate the nm (NetworkManager[sp?]) applet. ''' logme('lxdm_post_login.py --- calling configure_X_and_start_some_apps()') sound_vision_keyboard_list = ( # 'start-pulseaudio-x11', 'pulseaudio -k; xset s off; xset -dpms', '\ xmodmap -e "keycode 72=XF86MonBrightnessDown"; \ xmodmap -e "keycode 73=XF86MonBrightnessUp"; \ xmodmap -e "keycode 74=XF86AudioMute"; \ xmodmap -e "keycode 75=XF86AudioLowerVolume"; \ xmodmap -e "keycode 76=XF86AudioRaiseVolume"; \ xmodmap -e "pointer = 1 2 3 5 4 7 6 8 9 10 11 12"', 'check_ya_battery.sh', 'adjust_volume.sh', 'adjust_brightness.sh', ) applets_list = ( # & sleep 3; florence hide 'ps -o pid -C wmaker && wmsystemtray', 'florence', 'gpgApplet', 'keepassx -min', 'xbindkeys', 'sleep 3; if ps wax | fgrep mate-session | fgrep -v grep &>/dev/null ; then pulseaudio -k; mpg123 /etc/.mp3/winxp.mp3; fi', 'dconf write /apps/florence/controller/floaticon false', # 'ip2router start', # 'su freenet -c “/opt/freenet/run.sh start"', # /opt/freenet start', ) execute_this_list(sound_vision_keyboard_list) execute_this_list(applets_list) logme( 'lxdm_post_login.py --- returning from configure_X_and_start_some_apps()' )
def configure_X_and_start_some_apps(): '''Configure keyboard. Start WindowMaker system tray, florence, GPG applet, and a few other tools. Also, initiate the nm (NetworkManager[sp?]) applet. ''' logme( 'lxdm_post_login.py --- calling configure_X_and_start_some_apps()' ) sound_vision_keyboard_list = ( # 'start-pulseaudio-x11', 'pulseaudio -k; xset s off; xset -dpms', '\ xmodmap -e "keycode 72=XF86MonBrightnessDown"; \ xmodmap -e "keycode 73=XF86MonBrightnessUp"; \ xmodmap -e "keycode 74=XF86AudioMute"; \ xmodmap -e "keycode 75=XF86AudioLowerVolume"; \ xmodmap -e "keycode 76=XF86AudioRaiseVolume"; \ xmodmap -e "pointer = 1 2 3 5 4 7 6 8 9 10 11 12"', 'check_ya_battery.sh', 'adjust_volume.sh', 'adjust_brightness.sh', ) applets_list = ( # & sleep 3; florence hide 'ps -o pid -C wmaker && wmsystemtray', 'florence', 'gpgApplet', 'keepassx -min', 'xbindkeys', 'sleep 3; if ps wax | fgrep mate-session | fgrep -v grep &>/dev/null ; then pulseaudio -k; mpg123 /etc/.mp3/winxp.mp3; fi', 'dconf write /apps/florence/controller/floaticon false', # 'ip2router start', # 'su freenet -c “/opt/freenet/run.sh start"', # /opt/freenet start', ) execute_this_list( sound_vision_keyboard_list ) execute_this_list( applets_list ) logme( 'lxdm_post_login.py --- returning from configure_X_and_start_some_apps()' )
def install_important_packages( self ): logme( 'ArchlinuxDistro - install_important_packages() - starting' ) self.package_group_size = 2 os.system( 'clear' ) print( 'Chroot into the distro. Try running pacman -Syu. See if it works. Then, exit.' ) os.system( 'bash' ) chroot_this( self.mountpoint, 'yes "" 2> /dev/null | pacman -Syu', title_str = self.title_str, status_lst = self.status_lst ) chroot_this( self.mountpoint, 'yes "" 2>/dev/null | pacman -S --needed --force fakeroot', title_str = self.title_str, status_lst = self.status_lst ) system_or_die( 'rm -f %s/var/lib/pacman/db.lck; sync; sync; sync; sleep 2; sync; sync; sync; sleep 2' % ( self.mountpoint ) ) packages_lst = [ r for r in self.important_packages.split( ' ' ) if r != ''] list_of_groups = [ packages_lst[i:i + self.package_group_size] for i in range( 0, len( packages_lst ), self.package_group_size ) ] for lst in list_of_groups: s = ''.join( [r + ' ' for r in lst] ) chroot_this( self.mountpoint, 'yes "" 2>/dev/null | pacman -Syu --needed ' + s, title_str = self.title_str, status_lst = self.status_lst, on_fail = 'Failed to install %s' % ( ''.join( [' ' + r for r in lst] ) ) ) logme( 'Installed%s OK' % ( ''.join( [' ' + r for r in lst] ) ) ) self.update_status( '.' ) # self.update_and_upgrade_all() # fix_perl_cpan( self.mountpoint ) # abort_if_make_is_segfaulting( self.mountpoint ) chroot_this( self.mountpoint, 'yes "" 2>/dev/null | pacman -Syu --needed --force fakeroot', title_str = self.title_str, status_lst = self.status_lst, on_fail = 'Failed to install fakeroot' ) for pkg in ( 'shiboken', 'python-pyside' ): abort_if_make_is_segfaulting( self.mountpoint ) self.update_status( '.' ) self.build_and_install_software_from_archlinux_source( pkg, quiet = False ) self.update_status_with_newline( 'installed.' ) chroot_this( self.mountpoint, 'yes "" 2>/dev/null | pacman -Syu --needed --force cgpt', title_str = self.title_str, status_lst = self.status_lst, on_fail = 'Failed to install cgpt' ) system_or_die( 'rm -Rf %s/var/cache/apt/archives/*' % ( self.mountpoint ) )
def tidy_up_alarpy(): # Tidy up Alarpy, the (bootstrap) mini-OS, to reduce the size footprint of _D posterity file. os.system('mv /usr/share/locale/locale.alias /usr/share/ 2> /dev/null') for path_to_delete in ( '/usr/lib/python2.7', '/usr/lib/gcc', '/usr/include', '/usr/lib/gitcore', '/usr/lib/modules', '/usr/lib/perl5', '/usr/lib/zoneinfo', '/usr/lib/udev', # '/usr/lib/python2.7' '/usr/share/doc', '/usr/share/groff', '/usr/share/info', '/usr/share/man', '/usr/share/perl5', '/usr/share/texinfo', '/usr/share/xml', '/usr/share/zoneinfo', '/usr/share/locale/[a-d,f-z]*', '/usr/share/locale/e[a-m,o-z]*'): logme('Removing %s' % (path_to_delete)) system_or_die('rm -Rf %s' % (path_to_delete)) os.system('mv /usr/share/locale.alias /usr/share/locale/ 2> /dev/null')
def wait_until_truly_online(): while 0 != os.system( 'wget --spider https://dl.dropboxusercontent.com/u/59916027/chrubix/skeletons/alarpy.tar.xz -O /dev/null 2> /dev/null ' ): os.system('sleep 3') logme('still not truly online...') logme('i am TRULY online - yay')
def download_package_source( self, package_name, filenames_lst = None ): logme( 'ArchlinuxDistro - download_package_source() - starting' ) # self.update_status(( [ "Downloading %s package into %s OS" % ( package_name, self.name ) ] ) system_or_die( 'mkdir -p %s/%s/%s' % ( self.mountpoint, self.sources_basedir, package_name ) ) os.chdir( '%s/%s/%s' % ( self.mountpoint, self.sources_basedir, package_name ) ) if os.path.isfile( '%s/%s/%s/PKGBUILD' % ( self.mountpoint, self.sources_basedir, package_name ) ): self.update_status( '' ) # += "." # ..Still working" # No need to download anything. We have PKGBUILD already. elif filenames_lst in ( None, [] ): url = 'aur.archlinux.org/packages/%s/%s/%s.tar.gz' % ( package_name[:2], package_name, package_name ) wget( url = url, extract_to_path = '%s/%s' % ( self.mountpoint, self.sources_basedir ), quiet = True , title_str = self.title_str, status_lst = self.status_lst ) else: for fname in filenames_lst: file_to_download = '%s/%s/%s/%s' % ( self.mountpoint, self.sources_basedir, package_name, fname ) try: os.unlink( file_to_download ) except IOError: pass wget( url = 'http://projects.archlinux.org/svntogit/packages.git/plain/trunk/%s?h=packages/%s' \ % ( fname, package_name ), save_as_file = file_to_download, attempts = 20, quiet = True, title_str = self.title_str, status_lst = self.status_lst ) system_or_die( 'mv PKGBUILD PKGBUILD.ori' ) system_or_die( r"cat PKGBUILD.ori | sed s/march/phr34k/ | sed s/\'libutil-linux\'// | sed s/\'java-service-wrapper\'// | sed s/arch=\(.*/arch=\(\'%s\'\)/ | sed s/phr34k/march/ > PKGBUILD" % ( self.architecture ) ) chroot_this( self.mountpoint, 'chown -R guest %s/%s' % ( self.sources_basedir, package_name ) ) call_makepkg_or_die( mountpoint = self.mountpoint, \ package_path = '%s/%s' % ( self.sources_basedir, package_name ), \ cmd = 'cd %s/%s && makepkg --skipchecksums --nobuild -f' % ( self.sources_basedir, package_name ), errtxt = 'Failed to download %s' % ( package_name ) ) return 0
def configure_paranoidguestmode_before_calling_lxdm( password, direct, spoof, camouflage ): ''' Greeter calls me before it calls lxdm. This is my chance to set up the XP look, enable MAC spoofing, etc. ''' # Set password, if appropriate logme( 'configure_para....() - password=%s, direct=%s, spoof=%s, camouflage=%s' % ( str( password ), str( direct ), str( spoof ), str( camouflage ) ) ) distro = load_distro_record() logme( 'At present, windo manager = %s' % ( distro.lxdm_settings['window manager'] ) ) if password in ( None, '' ): disable_root_password( '/' ) else: set_user_password( 'root', password ) # Enable MAC spoofing, if appropriate if spoof: # https://wiki.archlinux.org/index.php/MAC_Address_Spoofing write_spoof_script_file( '/etc/NetworkManager/dispatcher.d/99spoofmymac.sh' ) # NetworkManager will run it, automatically, as soon as network goes up/down system_or_die( '''macchanger -r `ifconfig | grep lan0 | cut -d':' -f1 | head -n1`''' ) else: os.system( 'rm -f /etc/NetworkManager/dispatcher.d/99spoofmymac.sh' ) if camouflage: distro.lxdm_settings['window manager'] = '/usr/bin/mate-session' else: distro.lxdm_settings['window manager'] = distro.lxdm_settings['default wm'] distro.lxdm_settings['internet directly'] = direct save_distro_record( distro ) os.system( 'echo "configure_paranoid... - part E --- BTW, wm is now %s" >> /tmp/log.txt' % ( distro.lxdm_settings['window manager'] ) ) assert( camouflage is False or ( camouflage is True and 0 == os.system( 'cat /etc/lxdm/lxdm.conf | fgrep mate-session' ) ) ) os.system( 'cp /etc/lxdm/lxdm.conf /etc/lxdm/lxdm.conf.doin-the-doo' ) os.system( 'sync;sync;sync' )
def tidy_up_alarpy(): # Tidy up Alarpy, the (bootstrap) mini-OS, to reduce the size footprint of _D posterity file. os.system( 'mv /usr/share/locale/locale.alias /usr/share/ 2> /dev/null' ) for path_to_delete in ( '/usr/lib/python2.7', '/usr/lib/gcc', '/usr/include', '/usr/lib/gitcore', '/usr/lib/modules', '/usr/lib/perl5', '/usr/lib/zoneinfo', '/usr/lib/udev', # '/usr/lib/python2.7' '/usr/share/doc', '/usr/share/groff', '/usr/share/info', '/usr/share/man', '/usr/share/perl5', '/usr/share/texinfo', '/usr/share/xml', '/usr/share/zoneinfo', '/usr/share/locale/[a-d,f-z]*', '/usr/share/locale/e[a-m,o-z]*' ): logme( 'Removing %s' % ( path_to_delete ) ) system_or_die( 'rm -Rf %s' % ( path_to_delete ) ) os.system( 'mv /usr/share/locale.alias /usr/share/locale/ 2> /dev/null' )
def install_iceweasel_mozilla_settings( mountpoint, path ): logme( 'install_iceweasel_mozilla_settings(%s,%s) --- entering' % ( mountpoint, path ) ) dirname = os.path.dirname( path ) basename = os.path.basename( path ) username = os.path.basename( path ) if username[0] == '.': username = username[1:] # just in case the path is '.guest' => user is 'guest' assert( path.count( '/' ) == 2 ) assert( os.path.exists( '%s/home/guest' % ( mountpoint ) ) ) system_or_die( 'tar -zxf /usr/local/bin/Chrubix/blobs/settings/iceweasel-moz.tgz -C %s%s' % ( mountpoint, path ) ) # for stub in ( '.gtkrc-2.0', '.config/chromium/Default/Preferences', '.config/chromium/Local State' ): # do_a_sed( '%s/home/%s/%s' % ( mountpoint, user_name, stub ), GUEST_HOMEDIR, '/home/%s' % ( user_name ) ) f = '%s%s/.mozilla/firefox/ygkwzm8s.default/secmod.db' % ( mountpoint, path ) logme( 'f = %s' % ( f ) ) assert( os.path.exists( f ) ) s = r"cat %s | sed s/'\/home\/wharbargl\/'/'\/%s\/%s\/'/ > %s.new" % ( f, dirname.strip( '/' ), basename.strip( '/' ), f ) logme( 'calling ==> %s' % ( s ) ) if 0 != os.system( s ): # do_a_sed() does not work. That's why we are using the sed binary instead. logme( 'WARNING - failed to install iceweasel settings for %s' % ( username ) ) os.system( 'xmessage -buttons OK:0 -default Yes -nearmouse "install_iceweasel_mozilla_settings() is broken" -timeout 30' ) else: system_or_die( 'mv %s.new %s' % ( f, f ) ) chroot_this( mountpoint, 'chown -R %s %s' % ( username, path ) ) assert( os.path.exists( f ) ) logme( 'install_iceweasel_mozilla_settings() --- leaving' )
def process_command_line(argv): do_distro = None do_device = None do_root_dev = None do_kernel_dev = None do_spare_dev = None do_evil_maid = False do_latest_kernel = False install_to_plain_p3 = False print("Running chrubix from command line.") if len(sys.argv) <= 1: list_command_line_options() raise getopt.GetoptError( "In command line, please specify name of distro") optlist, args = getopt.getopt(argv[1:], 'hEZK:P:D:d:r:s:k:m:') args = args # hide Eclipse warning for (opt, param) in optlist: if opt == '-h': list_command_line_options() sys.exit(1) elif opt == '-D': do_distro = param # print( 'Distro = %s' % ( do_distro ) ) elif opt == '-d': do_device = param elif opt == '-r': do_root_dev = param elif opt == '-s': do_spare_dev = param elif opt == '-k': do_kernel_dev = param elif opt == '-m': do_mountpoint = param elif opt == '-K': do_latest_kernel = True if param == 'yes' else False elif opt == '-E': do_evil_maid = True elif opt == '-Z': install_to_plain_p3 = True else: raise getopt.GetoptError( str(opt) + " is an unrecognized command-line parameter") distro = generate_distro_record_from_name(do_distro) distro.device = do_device distro.root_dev = do_root_dev distro.kernel_dev = do_kernel_dev distro.spare_dev = do_spare_dev distro.mountpoint = do_mountpoint distro.install_to_plain_p3 = install_to_plain_p3 distro.use_latest_kernel = do_latest_kernel if do_evil_maid: distro.reboot_into_stage_two = True distro.kernel_rebuild_required = True distro.kthx = True distro.pheasants = True logme('Configuring for Evil Maid Protection Mode') return distro
def configure_distrospecific_tweaks( self ): logme( 'ArchlinuxDistro - configure_distrospecific_tweaks() - starting' ) self.update_status_with_newline( 'Installing distro-specific tweaks' ) friendly_list_of_packages_to_exclude = ''.join( r + ' ' for r in self.list_of_mkfs_packages ) + os.path.basename( self.kernel_src_basedir ) do_a_sed( '%s/etc/pacman.conf' % ( self.mountpoint ), '#.*IgnorePkg.*', 'IgnorePkg = %s' % ( friendly_list_of_packages_to_exclude ) ) chroot_this( self.mountpoint, 'systemctl enable lxdm.service' ) # logme( 'FYI, ArchLinux has no distro-specific post-install tweaks at present' ) self.update_status_with_newline( '...tweaked.' )
def start_privoxy_freenet_i2p_and_tor(): if 0 == os.system( 'sudo /usr/local/bin/start_privoxy_freenet_i2p_and_tor.sh'): logme('ran /usr/local/bin/start_privoxy_freenet_i2p_and_tor.sh OK') else: logme( '/usr/local/bin/start_privoxy_freenet_i2p_and_tor.sh returned error(s)' )
def download_mkfs_sources( self ): logme( 'ArchlinuxDistro - download_mkfs_sources() - starting' ) assert( self.list_of_mkfs_packages[0].find( 'btrfs' ) >= 0 ) assert( self.list_of_mkfs_packages[1].find( 'jfs' ) >= 0 ) assert( self.list_of_mkfs_packages[2].find( 'xfs' ) >= 0 ) self.download_package_source( self.list_of_mkfs_packages[0], ( 'PKGBUILD', 'btrfs-progs.install', 'initcpio-hook-btrfs', 'initcpio-install-btrfs' ) ) # , '01-fix-manpages.patch' ) ) self.download_package_source( self.list_of_mkfs_packages[1], ( 'PKGBUILD', 'inttypes.patch' ) ) self.download_package_source( self.list_of_mkfs_packages[2], ( 'PKGBUILD', ) )
def install_important_packages(self): logme('ArchlinuxDistro - install_important_packages() - starting') self.package_group_size = 2 os.system('clear') print( 'Chroot into the distro. Try running pacman -Syu. See if it works. Then, exit.' ) os.system('bash') chroot_this(self.mountpoint, 'yes "" 2> /dev/null | pacman -Syu', title_str=self.title_str, status_lst=self.status_lst) chroot_this(self.mountpoint, 'yes "" 2>/dev/null | pacman -S --needed --force fakeroot', title_str=self.title_str, status_lst=self.status_lst) system_or_die( 'rm -f %s/var/lib/pacman/db.lck; sync; sync; sync; sleep 2; sync; sync; sync; sleep 2' % (self.mountpoint)) packages_lst = [ r for r in self.important_packages.split(' ') if r != '' ] list_of_groups = [ packages_lst[i:i + self.package_group_size] for i in range(0, len(packages_lst), self.package_group_size) ] for lst in list_of_groups: s = ''.join([r + ' ' for r in lst]) chroot_this(self.mountpoint, 'yes "" 2>/dev/null | pacman -Syu --needed ' + s, title_str=self.title_str, status_lst=self.status_lst, on_fail='Failed to install %s' % (''.join([' ' + r for r in lst]))) logme('Installed%s OK' % (''.join([' ' + r for r in lst]))) self.update_status('.') # self.update_and_upgrade_all() # fix_perl_cpan( self.mountpoint ) # abort_if_make_is_segfaulting( self.mountpoint ) chroot_this( self.mountpoint, 'yes "" 2>/dev/null | pacman -Syu --needed --force fakeroot', title_str=self.title_str, status_lst=self.status_lst, on_fail='Failed to install fakeroot') for pkg in ('shiboken', 'python-pyside'): abort_if_make_is_segfaulting(self.mountpoint) self.update_status('.') self.build_and_install_software_from_archlinux_source(pkg, quiet=False) self.update_status_with_newline('installed.') chroot_this(self.mountpoint, 'yes "" 2>/dev/null | pacman -Syu --needed --force cgpt', title_str=self.title_str, status_lst=self.status_lst, on_fail='Failed to install cgpt') system_or_die('rm -Rf %s/var/cache/apt/archives/*' % (self.mountpoint))
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
def add_user_to_the_relevant_groups(username, distro_name, mountpoint): for group_to_add_me_to in ( '%s' % ('debian-tor' if distro_name == 'debian' else 'tor'), 'freenet', 'audio', 'pulse-access', 'pulse', 'users'): logme('Adding %s to %s' % (username, group_to_add_me_to)) # if group_to_add_me_to != 'pulse-access' and 0 != chroot_this(mountpoint, 'usermod -a -G %s %s 2> /dev/null' % (group_to_add_me_to, username), attempts=1)
def install_kernel_and_mkfs ( self ): # Technically, this won't install Linux-latest, which wasn't built with makepkg's help anyway. However, it WILL install # 3.4.0-ARCH (built w/ makepkg). Two kernels wait in PKGBUILDs/ore: one in linux-latest, the other in linux-chromebook. logme( 'ArchlinuxDistro - install_kernel_and_mkfs() - starting' ) chroot_this( self.mountpoint, r'yes "" 2>/dev/null | pacman -U `find %s | grep -x ".*\.tar\.xz"`' % ( self.sources_basedir ), title_str = self.title_str, status_lst = self.status_lst ) # if self.use_latest_kernel: # chroot_this( self.mountpoint, 'cd %s/linux-latest && make install && make modules_install' % ( self.sources_basedir ), # title_str = self.title_str, status_lst = self.status_lst, # on_fail = "Failed to install the standard ChromeOS kernel and/or modules" ) self.update_status_with_newline( '...kernel installed.' )
def install_barebones_root_filesystem( self ): logme( 'ArchlinuxDistro - install_barebones_root_filesystem() - starting' ) # wget( url = 'http://us.mirror.archlinuxarm.org/os/ArchLinuxARM-chromebook-latest.tar.gz', \ os.system( 'umount %s/dev &>/dev/null' % ( self.mountpoint ) ) my_url = 'http://us.mirror.archlinuxarm.org/os/ArchLinuxARM-chromebook-latest.tar.gz' # my_url = 'https://dl.dropboxusercontent.com/u/59916027/chrubix/skeletons/ArchLinuxARM-chromebook-latest.tar.gz' wget( url = my_url, \ extract_to_path = self.mountpoint, decompression_flag = 'z', \ title_str = self.title_str, status_lst = self.status_lst ) return 0
def process_command_line( argv ): do_distro = None do_device = None do_root_dev = None do_kernel_dev = None do_spare_dev = None do_evil_maid = False do_latest_kernel = False install_to_plain_p3 = False print( "Running chrubix from command line." ) if len( sys.argv ) <= 1: list_command_line_options() raise getopt.GetoptError( "In command line, please specify name of distro" ) optlist, args = getopt.getopt( argv[1:], 'hEZK:P:D:d:r:s:k:m:' ) args = args # hide Eclipse warning for ( opt, param ) in optlist: if opt == '-h': list_command_line_options() sys.exit( 1 ) elif opt == '-D': do_distro = param # print( 'Distro = %s' % ( do_distro ) ) elif opt == '-d': do_device = param elif opt == '-r': do_root_dev = param elif opt == '-s': do_spare_dev = param elif opt == '-k': do_kernel_dev = param elif opt == '-m': do_mountpoint = param elif opt == '-K': do_latest_kernel = True if param == 'yes' else False elif opt == '-E': do_evil_maid = True elif opt == '-Z': install_to_plain_p3 = True else: raise getopt.GetoptError( str( opt ) + " is an unrecognized command-line parameter" ) distro = generate_distro_record_from_name( do_distro ) distro.device = do_device distro.root_dev = do_root_dev distro.kernel_dev = do_kernel_dev distro.spare_dev = do_spare_dev distro.mountpoint = do_mountpoint distro.install_to_plain_p3 = install_to_plain_p3 distro.use_latest_kernel = do_latest_kernel if do_evil_maid: distro.reboot_into_stage_two = True distro.kernel_rebuild_required = True distro.kthx = True distro.pheasants = True logme( 'Configuring for Evil Maid Protection Mode' ) return distro
def save_distro_record( distro_rec = None, mountpoint = '/' ): assert( distro_rec is not None ) original_status_lst = distro_rec.status_lst try: distro_rec.status_lst = original_status_lst[-5:] except ( IndexError, SyntaxError ): logme( 'Unable to truncate status_lst. Bummer, man...' ) dct_to_save = {'name':distro_rec.name, 'branch':distro_rec.branch, 'dct':distro_rec.__dict__} pickle.dump( dct_to_save, open( '%s/etc/.distro.rec' % ( mountpoint ), "wb" ) ) if os.path.exists( '%s/etc/lxdm/lxdm.conf' % ( mountpoint ) ): configure_lxdm_behavior( mountpoint, distro_rec.lxdm_settings )
def install_barebones_root_filesystem(self): logme( 'ArchlinuxDistro - install_barebones_root_filesystem() - starting') # wget( url = 'http://us.mirror.archlinuxarm.org/os/ArchLinuxARM-chromebook-latest.tar.gz', \ os.system('umount %s/dev &>/dev/null' % (self.mountpoint)) my_url = 'http://us.mirror.archlinuxarm.org/os/ArchLinuxARM-chromebook-latest.tar.gz' # my_url = 'https://dl.dropboxusercontent.com/u/59916027/chrubix/skeletons/ArchLinuxARM-chromebook-latest.tar.gz' wget( url = my_url, \ extract_to_path = self.mountpoint, decompression_flag = 'z', \ title_str = self.title_str, status_lst = self.status_lst ) return 0
def configure_distrospecific_tweaks(self): logme('ArchlinuxDistro - configure_distrospecific_tweaks() - starting') self.update_status_with_newline('Installing distro-specific tweaks') friendly_list_of_packages_to_exclude = ''.join( r + ' ' for r in self.list_of_mkfs_packages) + os.path.basename( self.kernel_src_basedir) do_a_sed('%s/etc/pacman.conf' % (self.mountpoint), '#.*IgnorePkg.*', 'IgnorePkg = %s' % (friendly_list_of_packages_to_exclude)) chroot_this(self.mountpoint, 'systemctl enable lxdm.service') # logme( 'FYI, ArchLinux has no distro-specific post-install tweaks at present' ) self.update_status_with_newline('...tweaked.')
def install_final_push_of_packages( self ): # See https://twiki.grid.iu.edu/bin/view/Documentation/Release3/YumRpmBasics logme( 'Fedora - install_final_push_of_packages() - starting' ) # self.build_and_install_software_from_archlinux_source( 'wmsystemtray' ) self.update_status_with_newline( 'Installing %s' % ( self.final_push_packages.replace( ' ', ' ' ).replace( ' ', ', ' ) ) ) res = 999 attempts = 5 while res != 0 and attempts > 0: attempts -= 1 res = chroot_this( self.mountpoint, 'yes 2>/dev/null | yum install %s' % ( self.final_push_packages ), title_str = self.title_str, status_lst = self.status_lst ) if res != 0: system_or_die( 'rm -f %s/var/lib/pacman/db.lck; sync; sync; sync; sleep 3' % ( self.mountpoint ) ) assert( attempts > 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')
def install_barebones_root_filesystem(self): logme('SuseDistro - install_barebones_root_filesystem() - starting') unmount_sys_tmp_proc_n_dev(self.mountpoint) wget( url= 'http://download.opensuse.org/repositories/devel:/ARM:/13.1:/Contrib:/Chromebook/images/openSUSE-13.1-ARM-XFCE-chromebook.armv7l.raw.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) return 0
def install_final_push_of_packages( self ): logme( 'Fedora - install_final_push_of_packages() - starting' ) # self.build_and_install_software_from_archlinux_source( 'wmsystemtray' ) self.update_status_with_newline( 'Installing %s' % ( self.final_push_packages.replace( ' ', ' ' ).replace( ' ', ', ' ) ) ) res = 999 attempts = 5 while res != 0 and attempts > 0: attempts -= 1 res = chroot_this( self.mountpoint, 'yes 2>/dev/null | yum install %s' % ( self.final_push_packages ), title_str = self.title_str, status_lst = self.status_lst ) if res != 0: system_or_die( 'rm -f %s/var/lib/pacman/db.lck; sync; sync; sync; sleep 3' % ( self.mountpoint ) ) assert( attempts > 0 )
def install_final_push_of_packages(self): logme('ArchlinuxDistro - install_final_push_of_packages() - starting') self.update_status('Installed') for my_fname in ('ssss-0.5-3-armv7h.pkg.tar.xz', 'florence-0.6.2-1-armv7h.pkg.tar.xz'): try: system_or_die( 'cp /usr/local/bin/Chrubix/blobs/apps/%s /%s/tmp/' % (my_fname, self.mountpoint)) except RuntimeError: wget( url = 'https://dl.dropboxusercontent.com/u/59916027/chrubix/%s' % ( my_fname ), \ save_as_file = '%s/tmp/%s' % ( self.mountpoint, my_fname ), \ status_lst = self.status_lst, \ title_str = self.title_str ) if 0 == chroot_this(self.mountpoint, 'yes "" | pacman -U /tmp/%s' % (my_fname)): self.update_status(' ' + my_fname.split('-')[0]) # else: # failed( 'Failed to install ' + my_fname.split( '-' )[0]) # perl-cpan-meta-check perl-class-load-xs perl-eval-closure perl-mro-compat perl-package-depreciationmanager perl-sub-name perl-task-weaken \ # perl-test-checkdeps perl-test-without-module perl-moose failed_pkgs = self.install_from_AUR attempts = 0 while failed_pkgs != '' and attempts < 5: self.update_and_upgrade_all() attempts += 1 packages_to_install = failed_pkgs failed_pkgs = '' for pkg_name in packages_to_install.split(' '): if pkg_name in (None, '', ' '): continue try: self.build_and_install_software_from_archlinux_source( pkg_name, quiet=True) self.update_status(' %s' % (pkg_name)) except RuntimeError: failed_pkgs += ' %s' % (pkg_name) self.update_status('...OK.') if failed_pkgs != '': self.update_status( ['Warning - failed to install%s' % (failed_pkgs)]) # self.update_status(' etc. ') # self.update_status(( ['Installing %s' % ( self.final_push_packages.replace( ' ', ' ' ).replace( ' ', ', ' ) )] ) chroot_this(self.mountpoint, 'yes "" 2>/dev/null | pacman -S --needed %s' % (self.final_push_packages), title_str=self.title_str, status_lst=self.status_lst, on_fail='Failed to install final push of packages', attempts=20) self.update_and_upgrade_all() self.update_status_with_newline('...complete.')
def update_and_upgrade_all(self): logme('ArchlinuxDistro - update_and_upgrade_all() - starting') # system_or_die( 'sync; sync; sync; sleep 1' ) system_or_die( 'rm -f %s/var/lib/pacman/db.lck; sync; sync; sync; sleep 2; sync; sync; sync; sleep 2' % (self.mountpoint)) chroot_this(self.mountpoint, r'yes "" 2>/dev/null | pacman -Syu', "Failed to upgrade OS", attempts=5, title_str=self.title_str, status_lst=self.status_lst) system_or_die('sync; sync; sync; sleep 1; sync; sync; sync; sleep 1')
def download_mkfs_sources(self): logme('ArchlinuxDistro - download_mkfs_sources() - starting') assert (self.list_of_mkfs_packages[0].find('btrfs') >= 0) assert (self.list_of_mkfs_packages[1].find('jfs') >= 0) assert (self.list_of_mkfs_packages[2].find('xfs') >= 0) self.download_package_source( self.list_of_mkfs_packages[0], ('PKGBUILD', 'btrfs-progs.install', 'initcpio-hook-btrfs', 'initcpio-install-btrfs')) # , '01-fix-manpages.patch' ) ) self.download_package_source(self.list_of_mkfs_packages[1], ('PKGBUILD', 'inttypes.patch')) self.download_package_source(self.list_of_mkfs_packages[2], ('PKGBUILD', ))
def build_package( self, source_pathname ): logme( 'ArchlinuxDistro - build_package() - starting' ) package_name = os.path.basename( source_pathname ) package_path = os.path.dirname( source_pathname ) str_to_add = "Kernel & rootfs" if package_name == 'linux-chromebook' else "%s" % ( package_name ) self.update_status( '...' + str_to_add ) chroot_this( self.mountpoint, 'chown -R guest %s/%s' % ( self.sources_basedir, package_name ) ) chroot_this( self.mountpoint, 'cd %s && makepkg --skipchecksums --noextract -f ' % ( source_pathname ), \ "Failed to chroot make %s within %s" % ( package_name, package_path ), title_str = self.title_str, status_lst = self.status_lst , user = '******' ) chroot_this( self.mountpoint, 'chown -R root %s/%s' % ( self.sources_basedir, package_name ) ) self.update_status_with_newline( '...Built.' )
def main(): '''Fire up the GUI. Let the user do their thing. Apply changes if necessary. ''' logme( 'main.py ----- __main__' ) if os.system( 'mount | grep /dev/mapper/encstateful &> /dev/null' ) == 0 \ or os.system( 'mount | grep hfs &> /dev/null' ) == 0: regenerate_pyqt_bindings() app = QtGui.QApplication( sys.argv ) window = MainWindow() window.show() window.raise_() # if os.system("mount | grep -i crypt") == 0: # dlg = ReconfigureorexitDialog() sys.exit( app.exec_() )
def regenerate_pyqt_bindings(): '''Just in case the author recently updated the Qt GUI design files, we'll recompile the PyQt bindings and resource files. ''' # compile Qt Creator UI files into Python bindings # os.system( "rm -f ui_AlarmistGreeter.py ui/ui_AlarmistGreeter.py qrc_resources.py" ) os.system( 'export PATH=/opt/local/bin:$PATH' ) logme( 'ui etc.' ) for fname in [f for f in os.listdir( "ui" ) if f[-3:] == ".ui" and f[0] != "." ]: if not os.path.exists( 'ui/ui_%s.py' % ( fname[:-3] ) ): logme( '=> %s' % ( fname ) ) os.system( "PATH=/opt/local/bin:$PATH pyuic4 -o ui/ui_" + fname[:-3] + ".py ui/" + fname[:-3] + ".ui" ) print ( "Processing " + fname ) if not os.path.exists( 'resources_rc.py' ): os.system( "PATH=/opt/local/bin:$PATH pyrcc4 -py3 -o resources_rc.py ui/resources.qrc" )
def main(): '''Fire up the GUI. Let the user do their thing. Apply changes if necessary. ''' logme('main.py ----- __main__') if os.system( 'mount | grep /dev/mapper/encstateful &> /dev/null' ) == 0 \ or os.system( 'mount | grep hfs &> /dev/null' ) == 0: regenerate_pyqt_bindings() app = QtGui.QApplication(sys.argv) window = MainWindow() window.show() window.raise_() # if os.system("mount | grep -i crypt") == 0: # dlg = ReconfigureorexitDialog() sys.exit(app.exec_())
def save_distro_record(distro_rec=None, mountpoint='/'): assert (distro_rec is not None) original_status_lst = distro_rec.status_lst try: distro_rec.status_lst = original_status_lst[-5:] except (IndexError, SyntaxError): logme('Unable to truncate status_lst. Bummer, man...') dct_to_save = { 'name': distro_rec.name, 'branch': distro_rec.branch, 'dct': distro_rec.__dict__ } pickle.dump(dct_to_save, open('%s/etc/.distro.rec' % (mountpoint), "wb")) if os.path.exists('%s/etc/lxdm/lxdm.conf' % (mountpoint)): configure_lxdm_behavior(mountpoint, distro_rec.lxdm_settings)
def install_kernel_and_mkfs(self): # Technically, this won't install Linux-latest, which wasn't built with makepkg's help anyway. However, it WILL install # 3.4.0-ARCH (built w/ makepkg). Two kernels wait in PKGBUILDs/ore: one in linux-latest, the other in linux-chromebook. logme('ArchlinuxDistro - install_kernel_and_mkfs() - starting') chroot_this( self.mountpoint, r'yes "" 2>/dev/null | pacman -U `find %s | grep -x ".*\.tar\.xz"`' % (self.sources_basedir), title_str=self.title_str, status_lst=self.status_lst) # if self.use_latest_kernel: # chroot_this( self.mountpoint, 'cd %s/linux-latest && make install && make modules_install' % ( self.sources_basedir ), # title_str = self.title_str, status_lst = self.status_lst, # on_fail = "Failed to install the standard ChromeOS kernel and/or modules" ) self.update_status_with_newline('...kernel installed.')
def install_debianspecific_package_manager_tweaks( self, yes_add_ffmpeg_repo = False ): assert( not yes_add_ffmpeg_repo ) logme( 'UbuntuDistro - install_package_manager_tweaks() - starting' ) # f = open('%s/etc/apt/sources.list' % ( self.mountpoint ), 'a') # f.write(''' ''') # f.close() chroot_this( self.mountpoint, '' ) if g_proxy is not None: f = open( '%s/etc/apt/apt.conf' % ( self.mountpoint ), 'a' ) f.write( ''' Acquire::http::Proxy "http://%s/"; Acquire::ftp::Proxy "ftp://%s/"; Acquire::https::Proxy "https://%s/"; ''' % ( g_proxy, g_proxy, g_proxy ) ) f.close() logme( 'UbuntuDistro - install_package_manager_tweaks() - leaving' )
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...' )
def closeEvent( self, event ): if self.more_options and self.use_pw and not self.password: # QtGui.QMessageBox.question( self, "", "Either uncheck the 'password' checkbox\nor enter a good pasword twice.", QtGui.QMessageBox.Ok ) event.ignore() else: event.accept() if not self.use_pw: self.password = None configure_paranoidguestmode_before_calling_lxdm( password = self.password, direct = self.direct, spoof = self.spoof, camouflage = self.camouflage ) d = load_distro_record() logme( 'camouflage=%s; window manager=%s; is this kosher?' % ( str( self.camouflge ), d.lxdm_settings['window manager'] ) ) sys.exit( 0 ) # I assume the program that called me will now call lxdm, which will log in as guest & so on.
def download_package_source(self, package_name, filenames_lst=None): logme('ArchlinuxDistro - download_package_source() - starting') # self.update_status(( [ "Downloading %s package into %s OS" % ( package_name, self.name ) ] ) system_or_die('mkdir -p %s/%s/%s' % (self.mountpoint, self.sources_basedir, package_name)) os.chdir('%s/%s/%s' % (self.mountpoint, self.sources_basedir, package_name)) if os.path.isfile( '%s/%s/%s/PKGBUILD' % (self.mountpoint, self.sources_basedir, package_name)): self.update_status( '' ) # += "." # ..Still working" # No need to download anything. We have PKGBUILD already. elif filenames_lst in (None, []): url = 'aur.archlinux.org/packages/%s/%s/%s.tar.gz' % ( package_name[:2], package_name, package_name) wget(url=url, extract_to_path='%s/%s' % (self.mountpoint, self.sources_basedir), quiet=True, title_str=self.title_str, status_lst=self.status_lst) else: for fname in filenames_lst: file_to_download = '%s/%s/%s/%s' % ( self.mountpoint, self.sources_basedir, package_name, fname) try: os.unlink(file_to_download) except IOError: pass wget( url = 'http://projects.archlinux.org/svntogit/packages.git/plain/trunk/%s?h=packages/%s' \ % ( fname, package_name ), save_as_file = file_to_download, attempts = 20, quiet = True, title_str = self.title_str, status_lst = self.status_lst ) system_or_die('mv PKGBUILD PKGBUILD.ori') system_or_die( r"cat PKGBUILD.ori | sed s/march/phr34k/ | sed s/\'libutil-linux\'// | sed s/\'java-service-wrapper\'// | sed s/arch=\(.*/arch=\(\'%s\'\)/ | sed s/phr34k/march/ > PKGBUILD" % (self.architecture)) chroot_this( self.mountpoint, 'chown -R guest %s/%s' % (self.sources_basedir, package_name)) call_makepkg_or_die( mountpoint = self.mountpoint, \ package_path = '%s/%s' % ( self.sources_basedir, package_name ), \ cmd = 'cd %s/%s && makepkg --skipchecksums --nobuild -f' % ( self.sources_basedir, package_name ), errtxt = 'Failed to download %s' % ( package_name ) ) return 0
def build_package(self, source_pathname): logme('ArchlinuxDistro - build_package() - starting') package_name = os.path.basename(source_pathname) package_path = os.path.dirname(source_pathname) str_to_add = "Kernel & rootfs" if package_name == 'linux-chromebook' else "%s" % ( package_name) self.update_status('...' + str_to_add) chroot_this( self.mountpoint, 'chown -R guest %s/%s' % (self.sources_basedir, package_name)) chroot_this( self.mountpoint, 'cd %s && makepkg --skipchecksums --noextract -f ' % ( source_pathname ), \ "Failed to chroot make %s within %s" % ( package_name, package_path ), title_str = self.title_str, status_lst = self.status_lst , user = '******' ) chroot_this( self.mountpoint, 'chown -R root %s/%s' % (self.sources_basedir, package_name)) self.update_status_with_newline('...Built.')
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 )
def regenerate_pyqt_bindings(): '''Just in case the author recently updated the Qt GUI design files, we'll recompile the PyQt bindings and resource files. ''' # compile Qt Creator UI files into Python bindings # os.system( "rm -f ui_AlarmistGreeter.py ui/ui_AlarmistGreeter.py qrc_resources.py" ) os.system('export PATH=/opt/local/bin:$PATH') logme('ui etc.') for fname in [ f for f in os.listdir("ui") if f[-3:] == ".ui" and f[0] != "." ]: if not os.path.exists('ui/ui_%s.py' % (fname[:-3])): logme('=> %s' % (fname)) os.system("PATH=/opt/local/bin:$PATH pyuic4 -o ui/ui_" + fname[:-3] + ".py ui/" + fname[:-3] + ".ui") print("Processing " + fname) if not os.path.exists('resources_rc.py'): os.system( "PATH=/opt/local/bin:$PATH pyrcc4 -py3 -o resources_rc.py ui/resources.qrc" )
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' )
def closeEvent(self, event): if self.more_options and self.use_pw and not self.password: # QtGui.QMessageBox.question( self, "", "Either uncheck the 'password' checkbox\nor enter a good pasword twice.", QtGui.QMessageBox.Ok ) event.ignore() else: event.accept() if not self.use_pw: self.password = None configure_paranoidguestmode_before_calling_lxdm( password=self.password, direct=self.direct, spoof=self.spoof, camouflage=self.camouflage) d = load_distro_record() logme('camouflage=%s; window manager=%s; is this kosher?' % (str(self.camouflge), d.lxdm_settings['window manager'])) sys.exit( 0 ) # I assume the program that called me will now call lxdm, which will log in as guest & so on.
def configure_paranoidguestmode_before_calling_lxdm(password, direct, spoof, camouflage): ''' Greeter calls me before it calls lxdm. This is my chance to set up the XP look, enable MAC spoofing, etc. ''' # Set password, if appropriate logme( 'configure_para....() - password=%s, direct=%s, spoof=%s, camouflage=%s' % (str(password), str(direct), str(spoof), str(camouflage))) distro = load_distro_record() logme('At present, windo manager = %s' % (distro.lxdm_settings['window manager'])) if password in (None, ''): disable_root_password('/') else: set_user_password('root', password) # Enable MAC spoofing, if appropriate if spoof: # https://wiki.archlinux.org/index.php/MAC_Address_Spoofing write_spoof_script_file( '/etc/NetworkManager/dispatcher.d/99spoofmymac.sh' ) # NetworkManager will run it, automatically, as soon as network goes up/down system_or_die( '''macchanger -r `ifconfig | grep lan0 | cut -d':' -f1 | head -n1`''' ) else: os.system('rm -f /etc/NetworkManager/dispatcher.d/99spoofmymac.sh') if camouflage: distro.lxdm_settings['window manager'] = '/usr/bin/mate-session' else: distro.lxdm_settings['window manager'] = distro.lxdm_settings[ 'default wm'] distro.lxdm_settings['internet directly'] = direct save_distro_record(distro) os.system( 'echo "configure_paranoid... - part E --- BTW, wm is now %s" >> /tmp/log.txt' % (distro.lxdm_settings['window manager'])) assert (camouflage is False or (camouflage is True and 0 == os.system('cat /etc/lxdm/lxdm.conf | fgrep mate-session'))) os.system('cp /etc/lxdm/lxdm.conf /etc/lxdm/lxdm.conf.doin-the-doo') os.system('sync;sync;sync')
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...' )
def install_final_push_of_packages( self ): logme( 'ArchlinuxDistro - install_final_push_of_packages() - starting' ) self.update_status( 'Installed' ) for my_fname in ( 'ssss-0.5-3-armv7h.pkg.tar.xz', 'florence-0.6.2-1-armv7h.pkg.tar.xz' ): try: system_or_die( 'cp /usr/local/bin/Chrubix/blobs/apps/%s /%s/tmp/' % ( my_fname, self.mountpoint ) ) except RuntimeError: wget( url = 'https://dl.dropboxusercontent.com/u/59916027/chrubix/%s' % ( my_fname ), \ save_as_file = '%s/tmp/%s' % ( self.mountpoint, my_fname ), \ status_lst = self.status_lst, \ title_str = self.title_str ) if 0 == chroot_this( self.mountpoint, 'yes "" | pacman -U /tmp/%s' % ( my_fname ) ): self.update_status( ' ' + my_fname.split( '-' )[0] ) # else: # failed( 'Failed to install ' + my_fname.split( '-' )[0]) # perl-cpan-meta-check perl-class-load-xs perl-eval-closure perl-mro-compat perl-package-depreciationmanager perl-sub-name perl-task-weaken \ # perl-test-checkdeps perl-test-without-module perl-moose failed_pkgs = self.install_from_AUR attempts = 0 while failed_pkgs != '' and attempts < 5: self.update_and_upgrade_all() attempts += 1 packages_to_install = failed_pkgs failed_pkgs = '' for pkg_name in packages_to_install.split( ' ' ): if pkg_name in ( None, '', ' ' ): continue try: self.build_and_install_software_from_archlinux_source( pkg_name, quiet = True ) self.update_status( ' %s' % ( pkg_name ) ) except RuntimeError: failed_pkgs += ' %s' % ( pkg_name ) self.update_status( '...OK.' ) if failed_pkgs != '': self.update_status( ['Warning - failed to install%s' % ( failed_pkgs )] ) # self.update_status(' etc. ') # self.update_status(( ['Installing %s' % ( self.final_push_packages.replace( ' ', ' ' ).replace( ' ', ', ' ) )] ) chroot_this( self.mountpoint, 'yes "" 2>/dev/null | pacman -S --needed %s' % ( self.final_push_packages ), title_str = self.title_str, status_lst = self.status_lst, on_fail = 'Failed to install final push of packages', attempts = 20 ) self.update_and_upgrade_all() self.update_status_with_newline( '...complete.' )
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 )
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' )
def wait_until_online( max_delay = 999999 ): logme( 'lxdm_post_login.py --- waiting until %d seconds pass OR we end up online' % ( max_delay ) ) loops = max_delay while not am_i_online() and loops > 0: os.system( 'sleep 1' ) loops -= 1 logme( 'still not online...' ) logme( 'i am online - yay' )
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' )
def install_iceweasel_mozilla_settings(mountpoint, path): logme('install_iceweasel_mozilla_settings(%s,%s) --- entering' % (mountpoint, path)) dirname = os.path.dirname(path) basename = os.path.basename(path) username = os.path.basename(path) if username[0] == '.': username = username[ 1:] # just in case the path is '.guest' => user is 'guest' assert (path.count('/') == 2) assert (os.path.exists('%s/home/guest' % (mountpoint))) system_or_die( 'tar -zxf /usr/local/bin/Chrubix/blobs/settings/iceweasel-moz.tgz -C %s%s' % (mountpoint, path)) # for stub in ( '.gtkrc-2.0', '.config/chromium/Default/Preferences', '.config/chromium/Local State' ): # do_a_sed( '%s/home/%s/%s' % ( mountpoint, user_name, stub ), GUEST_HOMEDIR, '/home/%s' % ( user_name ) ) f = '%s%s/.mozilla/firefox/ygkwzm8s.default/secmod.db' % (mountpoint, path) logme('f = %s' % (f)) assert (os.path.exists(f)) s = r"cat %s | sed s/'\/home\/wharbargl\/'/'\/%s\/%s\/'/ > %s.new" % ( f, dirname.strip('/'), basename.strip('/'), f) logme('calling ==> %s' % (s)) if 0 != os.system( s ): # do_a_sed() does not work. That's why we are using the sed binary instead. logme('WARNING - failed to install iceweasel settings for %s' % (username)) os.system( 'xmessage -buttons OK:0 -default Yes -nearmouse "install_iceweasel_mozilla_settings() is broken" -timeout 30' ) else: system_or_die('mv %s.new %s' % (f, f)) chroot_this(mountpoint, 'chown -R %s %s' % (username, path)) assert (os.path.exists(f)) logme('install_iceweasel_mozilla_settings() --- leaving')
def check_and_if_necessary_fix_password_file( mountpoint, comment ): passwd_file = '%s/etc/passwd' % ( mountpoint ) orig_pwd_file = '%s/etc/passwd.before.someone.mucked.it.up' % ( mountpoint ) if not os.path.isfile( passwd_file ): logme( '%s - The passwd file does not exist at all yet. Never mind. Move along. Nothing to see here...' ) elif os.path.getsize( passwd_file ) == 0: logme( '%s - Someone created a zero-size password file. OK. I shall restore from backup.' % ( comment ) ) system_or_die( 'cp -f %s %s' % ( orig_pwd_file, passwd_file ) ) else: logme( '%s - Checked pw file. It is not non-zero. Good. Backing up...' % ( comment ) ) system_or_die( 'cp -f %s %s' % ( passwd_file, orig_pwd_file ) )
def do_audio_and_network_stuff(): logme( 'ersatz_lxdm.py --- do_audio_and_network_stuff() --- entering' ) for cmd in ( 'systemctl start NetworkManager', 'systemctl enable privoxy', 'amixer sset Speaker unmute', 'amixer sset Speaker 30%', '''for q in `amixer | grep Speaker | cut -d"'" -f2 | tr ' ' '/'`; do g=`echo "$q" | tr '/' ' '`; amixer sset "$g" unmute; done''', 'which alsactl &> /dev/null && alsactl store &> /dev/null' ): if 0 != os.system( cmd ): logme( '%s ==> failed' % ( cmd ) ) logme( 'ersatz_lxdm.py --- do_audio_and_network_stuff() --- leaving' )
def start_a_browser( force_real = False ): website = 'www.duckduckgo.com' binary = None my_distro = load_distro_record( '/' ) if force_real or my_distro.lxdm_settings['internet directly']: if 0 == os.system( 'which iceweasel &> /dev/null' ): binary = 'iceweasel' else: binary = 'chromium' else: logme( 'Running dillo to help user access the Net via Starbucks or whatever' ) binary = 'dillo' cmd = '%s %s &' % ( binary, website ) logme( 'start_a_browser() --- calling %s' % ( cmd ) ) res = os.system( cmd ) logme( '...result=%d' % ( res ) )