def main(argv): parser = setup_parser() args = parser.parse_args(argv[1:]) config = dict(default_config, **parse_config(args.config)) print json.dumps(config, indent=2) image = download(config['download']) config[config['download']['result']] = image if config.get('expand', None): expand.expand(config['expand'], image) for m in config.get('mounts', []): mount.mount(m, image) for entry in config.get('operations', []): if entry['operation'] == 'append': append.append(entry) elif entry['operation'] == 'hostname': hostname.hostname(entry) elif entry['operation'] == 'chroot': chroot.chroot(entry) for m in config.get('mounts', [])[::-1]: mount.unmount(m)
def main(argv): parser = setup_parser() args = parser.parse_args(argv[1:]) config = dict(default_config, **parse_config(args.config)) for m in config['mounts'][::-1]: mount.unmount(m, False)
def _delete_window(): if mounted: if not messagebox.askokcancel("Quit", "Closing this window will result in S3Drive to unmount.\nAre you sure you want to exit?"): return else: mount_command() try: if mountobj: mount.unmount(mount_obj) except Exception as e: pass root.destroy() sys.exit(0)
def mount_command(): global mounted global mount_obj if buckets_loaded == False: messagebox.showinfo("AWS Keys needed" , "Please enter your AWS keys and select bucket to mount to proceed!") return if mounted == False: mount_button_text.set("Mounting...Wait up to 1 min.") root.config(cursor="wait") root.update() try: mount_obj = mount.mount(key_var.get() , secret_var.get() , bucket_var.get() , drive_var.get()) check_interval = 3 max_time_wait = 30 time_waited = 0 while 1: if mount.mount_alive(mount_obj): #TODO: disable all inputs mount_button_text.set("Unmount") mounted = True show_message("Mount Success" , "Bucket {0} mounted to drive {1}".format(bucket_var.get() , drive_var.get())); break else: time.sleep(check_interval) time_waited += check_interval if time_waited > max_time_wait: messagebox.showwarning("Failed to mount!" , "Failed to mount!\nPlease check {0}\\fs.log for more info".format(os.getcwd())) break except Exception as e: error.show_exception("Failed to mount!" , e) if not mounted: mount_button_text.set("Mount") else: #TODO: windows-only subprocess.Popen(r'explorer /select,"'+drive_var.get()+'"') root.config(cursor="") root.update() else: root.config(cursor="wait") root.update() mount.unmount(mount_obj) time.sleep(8) if not mount.mount_alive(mount_obj): #TODO: enable all inputs mount_button_text.set("Mount") mounted = False else: #TODO: more descriptive errors messagebox.showwarning("Failed to unmount!" , "Please check fs.log for more info") root.config(cursor="") root.update()
def notify_callback(block, device): # type: (str, Device) -> None """This callback is called when a new partition was added.""" print_verbose('New block added: {0}'.format(block)) should_unmount = True if waitForAutoMount is not None: time.sleep(waitForAutoMount) # Wait some time for auto mounting to occur mount_result = get_block_mount_point(block) mount_point = mount_result[0] should_unmount = not mount_result[1] else: mount_point = mount_block(block) print_verbose('Mounted on {0}'.format(mount_point)) nonce_path = os.path.join(mount_point, 'nonce') nonce_signature_path = os.path.join(mount_point, 'nonce.sig') if not os.path.isfile(nonce_path) or not os.path.isfile(nonce_signature_path): print('USB device does not contain a nonce nor signature.') play_sound('sound/denied.mp3') else: with open(nonce_path, 'r') as nonce_file: nonce_data = nonce_file.read() with open(nonce_signature_path, 'r') as signature_file: signature_data = signature_file.read() r = requests.post('http://access-control.dev', data={ "nonce": nonce_data, "signature": signature_data }) response = r.json() if 'data' in response: open_and_close.open_and_close(engineControl, args.time, args.delay) else: play_sound('sound/denied.mp3') if should_unmount: print_verbose('Unmounting {0}'.format(mount_point)) unmount(mount_point) print_verbose('Unmounted {0}'.format(mount_point))
def unmount(self): device, mountpoint = self.pv.get_sel_values() unmount(self, device, mountpoint)
if mount.is_mounted(device): files = [] for filename in os.listdir(mount.get_media_path(device)): path = os.path.join(mount.get_media_path(device), filename) if os.path.isfile(path): files.append(filename) tala.popup("Copying...", "Copying log file...") logger.info("Copying file from " + LOG_FILENAME + " to " + os.path.join(mount.get_media_path(device), LOG_NAME) + "...") shutil.copy(LOG_FILENAME, os.path.join(mount.get_media_path(device), LOG_NAME)) logger.info("Copy complete!") tala.popup("Copyied", "Copy complete!") time.sleep(2) mount.unmount(device) elif choice == "Update Tala": time.sleep(0.5) result = tala.yn("Are you sure you'd like to update") if result is None: pass elif result: tala.message("Information", "Tala will update even if there's no new version. On the next screen select a way to update.") choice = tala.menu(["Via Internet", "Via USB"]) if choice == "Via Internet": tala.popup("Updating...", "Checking internet connection...") # Check for connection connection = False try: urllib.request.urlopen("http://216.58.192.142", timeout=1) connection = True
import mount import crypt import os if __name__ == "__main__": with open('/home/osboxes/algebra/Disks/.mount_point', "r") as outfile: VHD_MOUNT_POINT = outfile.read() print(VHD_MOUNT_POINT) mount.unmount(VHD_MOUNT_POINT) user = mount.getuser() key = crypt.hash((os.environ['TOKEN']).encode()) crypt.encrypt_file(key, "/home/osboxes/algebra/Disks/{}.img".format(user)) os.remove("/home/osboxes/algebra/Disks/{}.img".format(user)) os.remove("/home/osboxes/algebra/Disks/.mount_point") # os.system("shutdown now")
def start_iso(self): # Collect information. label = self.get_label() device_id = self.get_device_id() partition_table = self.get_table() filesystem = self.get_filesystem() device = usb_info.get_block_device_name(device_id) badblocks_passes = self.get_badblocks_passes() badblocks_file = '/tmp/usbmaker' + str(os.getpid()) + '-badblocks.txt' clustersize = self.get_cluster_size() target = self.get_target() iso_mountpoint = '/tmp/usbmaker' + str(os.getpid()) + '-iso' mount.mount_iso(self.filename, iso_mountpoint) bootloader = [ iso.get_uefi_bootloader_name(iso_mountpoint), iso.get_bios_bootloader_name(iso_mountpoint) ] # Check if a UEFI bootloader is present. if os.path.isfile(iso_mountpoint + '/boot/efi/bootx64.efi') or \ os.path.isfile(iso_mountpoint + '/boot/efi/bootia32.efi'): uefi_bootloader_installed = True else: uefi_bootloader_installed = False mount.unmount(iso_mountpoint) # Ask user whether to replace the bootloader or use the included one. if uefi_bootloader_installed: if QtWidgets.QMessageBox.question( self.main_window, 'Replace UEFI bootloader?', 'This ISO image already contains a UEFI bootloader.\n' + 'Do you want to replace the UEFI bootloader?', QtWidgets.QMessageBox.Yes | QtWidgets.QMessageBox.No, QtWidgets.QMessageBox.No) == QtWidgets.QMessageBox.Yes: replace_uefi_bootloader = True else: replace_uefi_bootloader = False else: replace_uefi_bootloader = True # Change the target variable to preserve the UEFI bootloader. if not replace_uefi_bootloader: if target == 'uefi': target = 'none' else: target = 'bios' if not self.dependencies['badblocks']: badblocks_passes = 0 # missing_deps is a string containing the list of missing dependencies. missing_deps = '' mkfs_found = False bootloader_found = False if filesystem == 'fat32' or filesystem == 'fat16': if self.dependencies['mkfs.fat']: mkfs_found = True else: missing_deps += '\nmkfs.fat' elif filesystem == 'exfat': if self.dependencies['mkfs.exfat']: mkfs_found = True else: missing_deps += '\nmkfs.exfat' elif filesystem == 'ntfs': if self.dependencies['mkfs.ntfs']: mkfs_found = True else: missing_deps += '\nmkfs.ntfs' elif filesystem == 'udf': if self.dependencies['mkfs.udf']: mkfs_found = True else: missing_deps += '\nmkfs.udf' elif filesystem == 'ext4': if self.dependencies['mkfs.ext4']: mkfs_found = True else: missing_deps += '\nmkfs.ext4' elif filesystem == 'btrfs': if self.dependencies['mkfs.btrfs']: mkfs_found = True else: missing_deps += '\nmkfs.btrfs' else: missing_deps += '\nUnknown filesystem: "' + filesystem + '"' if target == 'none': bootloader_found = True elif target == 'uefi': if bootloader[0] == 'syslinux': if self.dependencies['syslinux']: bootloader_found = True else: missing_deps += '\nsyslinux' elif bootloader[0] == 'grub2': if self.dependencies['grub2']: bootloader_found = True else: missing_deps += '\ngrub2' elif bootloader[0] == 'systemd-boot': if self.dependencies['systemd-boot']: bootloader_found = True else: missing_deps += '\nsystemd-boot' else: missing_deps += '\nUnknown bootloader (UEFI)' elif target == 'bios': if bootloader[1] == 'syslinux': if self.dependencies['syslinux']: bootloader_found = True else: missing_deps += '\nsyslinux' elif bootloader[1] == 'grub4dos': if self.dependencies['grub4dos']: bootloader_found = True else: missing_deps += '\ngrub4dos' else: missing_deps += '\nUnknown bootloader (BIOS)' elif target == 'both': if bootloader[0] == 'syslinux' and bootloader[1] == 'syslinux': if self.dependencies['syslinux']: bootloader_found = True else: missing_deps += '\nsyslinux' else: uefi_bootloader_found = False bios_bootloader_found = False if bootloader[0] == 'syslinux': if self.dependencies['syslinux']: uefi_bootloader_found = True else: missing_deps += '\nsyslinux' elif bootloader[0] == 'grub2': if self.dependencies['grub2']: uefi_bootloader_found = True else: missing_deps += '\ngrub2' elif bootloader[0] == 'systemd-boot': if self.dependencies['systemd-boot']: uefi_bootloader_found = True else: missing_deps += '\nsystemd-boot' else: missing_deps += '\nUnknown bootloader (UEFI)' if bootloader[1] == 'syslinux': if self.dependencies['syslinux']: bios_bootloader_found = True else: missing_deps += '\nsyslinux' elif bootloader[1] == 'grub4dos': if self.dependencies['grub4dos']: bios_bootloader_found = True else: missing_deps += '\ngrub4dos' else: missing_deps += '\nUnknown bootloader (BIOS)' if uefi_bootloader_found and bios_bootloader_found: bootloader_found = True if not self.dependencies['parted']: missing_deps += '\nparted' if not mkfs_found or not bootloader_found or not self.dependencies[ 'parted']: QtWidgets.QMessageBox.warning( self, 'USBMaker', 'Could not find the software required to perform this ' + 'action. The dependencies that need to be installed are:\n' + missing_deps) else: # Send a signal to the worker object to start the make_bootable_iso() function. self.signal_iso.emit(device, self.filename, filesystem, partition_table, target, bootloader, label, clustersize, badblocks_passes, badblocks_file, self.syslinux, self.syslinux_modules, self.grldr)
def make_bootable_iso(self, device, filename, filesystem, partition_table, target, bootloader, label, clustersize, badblocks_passes, badblocks_file, syslinux, syslinux_modules, grldr): # Requires: parted, mkfs.*, bootloader(grub2, syslinux, grub4dos, systemd-boot) self.signal_set_enabled.emit(False) self.signal_set_progress.emit(0) # Unmount partitions before continuing. mount.unmount_all_partitions(device) self.signal_set_status.emit('Creating the partition table...') # Partition the usb drive. partitioning.create_partition_table(device, partition_table) self.signal_set_status.emit('Creating the partition...') self.signal_set_progress.emit(5) partitioning.create_partition_wrapper(device, filesystem) if partition_table == 'gpt': partitioning.change_partition_name(device, label) if badblocks_passes > 0: self.signal_set_status.emit('Checking for bad blocks...') if clustersize == -1: formatting.check_badblocks(device, str(badblocks_passes), badblocks_file) else: formatting.check_badblocks(device, str(badblocks_passes), badblocks_file, str(clustersize)) # Show message box informing the user of the badblocks check. self.signal_show_badblocks_messagebox.emit(badblocks_file) self.signal_set_status.emit('Creating the filesystem...') self.signal_set_progress.emit(10) # Create the filesystem. if badblocks_passes > 0: formatting.create_filesystem(device, '1', filesystem, str(clustersize), label, badblocks_file) else: formatting.create_filesystem(device, '1', filesystem, str(clustersize), label) self.signal_set_status.emit('Copying files...') self.signal_set_progress.emit(25) # Mount the usb and the iso file. usb_mountpoint = '/tmp/usbmaker' + str(os.getpid()) + '-usb' iso_mountpoint = '/tmp/usbmaker' + str(os.getpid()) + '-iso' mount.mount(device + '1', usb_mountpoint) mount.mount_iso(filename, iso_mountpoint) # Copy the iso contents to the usb drive. iso.copy_iso_contents(iso_mountpoint, usb_mountpoint) # Unmount the iso file. mount.unmount(iso_mountpoint) self.signal_set_status.emit('Installing the bootloader...') self.signal_set_progress.emit(80) # Make the usb bootable. iso.create_bootable_usb(device, usb_mountpoint, bootloader, target, partition_table, syslinux, syslinux_modules, grldr) # Unmount the usb drive. mount.unmount(usb_mountpoint) if target == 'both': partitioning.mark_bootable(device, partition_table) self.signal_set_status.emit('Completed.') self.signal_set_progress.emit(100) self.signal_set_enabled.emit(True)