diff --git a/get-prebuilt.py b/get-prebuilt.py index 770ccf0..7dd5c23 100755 --- a/get-prebuilt.py +++ b/get-prebuilt.py @@ -10,7 +10,7 @@ if len(sys.argv) < 2: print('usage: ./get-prebuilt.py image[:tag]') - exit(-1) + sys.exit(-1) image, tag, fname, label = parse_image_arg(sys.argv[1], False) @@ -29,11 +29,11 @@ except urllib.error.HTTPError as err: print('%s[!]%s Failed to authorization token: %s' % (Fore.RED, Fore.RESET, err)) - exit(-1) + sys.exit(-1) except KeyError as err: print('%s[!]%s Failed to authorization token: %s' % (Fore.RED, Fore.RESET, err)) - exit(-1) + sys.exit(-1) # get the image manifest @@ -51,11 +51,11 @@ if len(manifest['fsLayers']) == 0: print('%s[!]%s Manifest for image %s%s%s has no layers.' % (Fore.RED, Fore.RESET, Fore.BLUE, image, Fore.RESET)) - exit(-1) + sys.exit(-1) except urllib.error.HTTPError as err: print('%s[!]%s Failed to fetch manifest info for %s%s%s: %s' % (Fore.RED, Fore.RESET, Fore.BLUE, image, Fore.RESET, err)) - exit(-1) + sys.exit(-1) # download the layers @@ -84,11 +84,11 @@ except urllib.error.HTTPError as err: clear_progress() print('%s[!]%s Failed to download layer %s%s%s: %s' % (Fore.RED, Fore.RESET, Fore.BLUE, layer['blobSum'], Fore.RESET, err)) - exit(-1) + sys.exit(-1) except OSError as err: clear_progress() print('%s[!]%s Failed to open file %s%s%s for writing: %s' % (Fore.RED, Fore.RESET, Fore.BLUE, fname, Fore.RESET, err)) - exit(-1) + sys.exit(-1) print('%s[*]%s Rootfs archive for %s%s%s:%s%s%s saved to %s%s%s.' % (Fore.GREEN, Fore.RESET, Fore.YELLOW, image, Fore.RESET, Fore.YELLOW, tag, Fore.RESET, Fore.GREEN, fname, Fore.RESET)) diff --git a/get-source.py b/get-source.py index e390adf..083f7a1 100755 --- a/get-source.py +++ b/get-source.py @@ -8,7 +8,7 @@ if len(sys.argv) < 2: print('usage: ./get-source.py image[:tag]') - exit(-1) + sys.exit(-1) image, tag, fname, label = parse_image_arg(sys.argv[1], False) @@ -104,12 +104,12 @@ if not dfurl: print('%s[!]%s Failed to find tag %s%s%s for image %s%s%s.' % (Fore.RED, Fore.RESET, Fore.BLUE, tag, Fore.RESET, Fore.BLUE, image, Fore.RESET)) - exit(-1) + sys.exit(-1) except urllib.error.HTTPError as err: print('%s[!]%s Failed to fetch official-images info for %s%s%s: %s' % (Fore.RED, Fore.RESET, Fore.BLUE, image, Fore.RESET, err)) print('%s[!]%s If this is not an official image, try getting it with %sget-prebuilt.py %s%s.' % (Fore.RED, Fore.RESET, Fore.GREEN, sys.argv[1].strip(), Fore.RESET)) - exit(-1) + sys.exit(-1) # process Dockerfile @@ -134,11 +134,11 @@ if not tgurl: print('%s[!]%s Failed to find a suitable rootfs specification in Dockerfile.' % (Fore.RED, Fore.RESET)) - exit(-1) + sys.exit(-1) except urllib.error.HTTPError as err: print('%s[!]%s Failed to fetch Dockerfile from %s%s%s: %s' % (Fore.RED, Fore.RESET, Fore.BLUE, dfurl, Fore.RESET, err)) - exit(-1) + sys.exit(-1) # download rootfs archive @@ -151,11 +151,11 @@ except urllib.error.HTTPError as err: clear_progress() print('%s[!]%s Failed to download archive from %s%s%s: %s' % (Fore.RED, Fore.RESET, Fore.BLUE, tgurl, Fore.RESET, err)) - exit(-1) + sys.exit(-1) except OSError as err: clear_progress() print('%s[!]%s Failed to open file %s%s%s for writing: %s' % (Fore.RED, Fore.RESET, Fore.BLUE, fname, Fore.RESET, err)) - exit(-1) + sys.exit(-1) print('%s[*]%s Rootfs archive for %s%s%s:%s%s%s saved to %s%s%s.' % (Fore.GREEN, Fore.RESET, Fore.YELLOW, image, Fore.RESET, Fore.YELLOW, tag, Fore.RESET, Fore.GREEN, fname, Fore.RESET)) diff --git a/install.py b/install.py index 39b4b86..10d290a 100755 --- a/install.py +++ b/install.py @@ -35,7 +35,7 @@ if not imgarg: print('usage: ./install.py [--no-hooks] image[:tag] | tarball | squashfs') print('\noptions:\n --no-hooks Omits running the hook scripts.') - exit(-1) + sys.exit(-1) image, tag, fname, label = parse_image_arg(imgarg, True) @@ -60,7 +60,7 @@ if not os.path.isfile(out): print('%s[!]%s Failed to get home directory of default user in WSL: Output file %s%s%s not present.' % (Fore.RED, Fore.RESET, Fore.BLUE, out, Fore.RESET)) - exit(-1) + sys.exit(-1) with open(out) as f: homedir = f.readline().strip() @@ -68,7 +68,7 @@ if len(homedir) == 0 or not os.path.isdir(homedirw): print('%s[!]%s Failed to get home directory of default user in WSL: Returned path %s%s%s is not valid.' % (Fore.RED, Fore.RESET, Fore.BLUE, homedirw, Fore.RESET)) - exit(-1) + sys.exit(-1) user = f.readline().strip() isroot = user == 'root' @@ -79,7 +79,7 @@ except subprocess.CalledProcessError as err: print('%s[!]%s Failed to get home directory of default user in WSL: %s' % (Fore.RED, Fore.RESET, err)) - exit(-1) + sys.exit(-1) # check squashfs prerequisites @@ -87,7 +87,7 @@ if (fext == '.sfs' or fext == '.squashfs') and not havesquashfs: print('%s[!]%s Module %sPySquashfsImage%s is not available. Install it with %spip3 install PySquashfsImage%s for SquashFS support.' % (Fore.RED, Fore.RESET, Fore.GREEN, Fore.RESET, Fore.GREEN, Fore.RESET)) - exit(-1) + sys.exit(-1) # get /etc/{passwd,shadow,group,gshadow} entries @@ -108,7 +108,7 @@ except OSError as err: print('%s[!]%s Failed to open file %s/etc/passwd%s: %s' % (Fore.RED, Fore.RESET, Fore.BLUE, Fore.RESET, err)) - exit(-1) + sys.exit(-1) try: with open(os.path.join(basedir, 'rootfs', 'etc', 'shadow'), newline='\n') as f: @@ -120,7 +120,7 @@ except OSError as err: print('%s[!]%s Failed to open file %s/etc/shadow%s: %s' % (Fore.RED, Fore.RESET, Fore.BLUE, Fore.RESET, err)) - exit(-1) + sys.exit(-1) if not isroot: try: @@ -131,7 +131,7 @@ except OSError as err: print('%s[!]%s Failed to open file %s/etc/group%s: %s' % (Fore.RED, Fore.RESET, Fore.BLUE, Fore.RESET, err)) - exit(-1) + sys.exit(-1) try: with open(os.path.join(basedir, 'rootfs', 'etc', 'gshadow'), newline='\n') as f: @@ -141,7 +141,7 @@ except OSError as err: print('%s[!]%s Failed to open file %s/etc/gshadow%s: %s' % (Fore.RED, Fore.RESET, Fore.BLUE, Fore.RESET, err)) - exit(-1) + sys.exit(-1) if etcshadowroot: parts = etcshadowroot.split(':') @@ -169,7 +169,7 @@ def retry_rw(operation, name, exc): if os.path.exists(os.path.join(homedirw, 'rootfs-temp')): print('%s[*]%s Failed to remove leftover %srootfs-temp%s.' % (Fore.RED, Fore.RESET, Fore.BLUE, Fore.RESET)) - exit(-1) + sys.exit(-1) # extract archive @@ -258,7 +258,7 @@ def retry_rw(operation, name, exc): if file is None: clear_progress() print('%s[!]%s Failed to extract archive: unable to determine archive type.' % (Fore.RED, Fore.RESET)) - exit(-1) + sys.exit(-1) while file is not None: try: @@ -331,7 +331,7 @@ def retry_rw(operation, name, exc): except Exception as err: clear_progress() print('%s[!]%s Failed to extract archive: %s' % (Fore.RED, Fore.RESET, err)) - exit(-1) + sys.exit(-1) finally: clear_progress() @@ -354,7 +354,7 @@ def retry_rw(operation, name, exc): except subprocess.CalledProcessError as err: print('%s[!]%s Failed to backup current %srootfs%s: %s' % (Fore.RED, Fore.RESET, Fore.BLUE, Fore.RESET, err)) - exit(-1) + sys.exit(-1) print('%s[*]%s Switching to new %srootfs%s...' % (Fore.GREEN, Fore.RESET, Fore.BLUE, Fore.RESET)) @@ -374,7 +374,7 @@ def retry_rw(operation, name, exc): print('%s[!]%s Failed to roll back to old %srootfs%s: %s' % (Fore.RED, Fore.RESET, Fore.BLUE, Fore.RESET, err)) print('%s[!]%s You are now the proud owner of one broken Linux subsystem! To fix it, run %slxrun /uninstall%s and %slxrun /install%s from the command prompt.' % (Fore.RED, Fore.RESET, Fore.GREEN, Fore.RESET, Fore.GREEN, Fore.RESET)) - exit(-1) + sys.exit(-1) # save label @@ -460,7 +460,7 @@ def retry_rw(operation, name, exc): except subprocess.CalledProcessError as err: print('%s[!]%s Failed to switch default user in WSL: %s' % (Fore.RED, Fore.RESET, err)) - exit(-1) + sys.exit(-1) try: subprocess.check_call(['cmd', '/C', lxpath + '\\bash.exe', '-c', @@ -469,7 +469,7 @@ def retry_rw(operation, name, exc): if not os.path.isfile(out): print('%s[!]%s Failed to get home directory of default user in WSL: Output file %s%s%s not present.' % (Fore.RED, Fore.RESET, Fore.BLUE, out, Fore.RESET)) - exit(-1) + sys.exit(-1) with open(out) as f: homedir = f.readline().strip() @@ -477,19 +477,19 @@ def retry_rw(operation, name, exc): if len(homedir) == 0 or not os.path.isdir(homedirw): print('%s[!]%s Failed to get home directory of default user in WSL: Returned path %s%s%s is not valid.' % (Fore.RED, Fore.RESET, Fore.BLUE, homedirw, Fore.RESET)) - exit(-1) + sys.exit(-1) user2 = f.readline().strip() if user2 != 'root': print('%s[!]%s Failed to switch default user to %sroot%s.' % (Fore.RED, Fore.RESET, Fore.YELLOW, Fore.RESET)) - exit(-1) + sys.exit(-1) os.unlink(out) except subprocess.CalledProcessError as err: print('%s[!]%s Failed to get home directory of default user in WSL: %s' % (Fore.RED, Fore.RESET, err)) - exit(-1) + sys.exit(-1) # since we switched to root, switch back to regular user on exit @@ -501,7 +501,7 @@ def switch_user_back(user): except subprocess.CalledProcessError as err: print('%s[!]%s Failed to switch default user in WSL: %s' % (Fore.RED, Fore.RESET, err)) - exit(-1) + sys.exit(-1) atexit.register(switch_user_back, user) diff --git a/switch.py b/switch.py index 6f6e780..8a39a5c 100755 --- a/switch.py +++ b/switch.py @@ -51,7 +51,7 @@ else: print('You do not seem to have the default distribution installed anymore.\nTo reinstall it, run %slxrun /uninstall%s and %slxrun /install%s from the command prompt.' % (Fore.GREEN, Fore.RESET, Fore.GREEN, Fore.RESET)) - exit(-1) + sys.exit(-1) image, tag, fname, label = parse_image_arg(sys.argv[1], False) @@ -71,7 +71,7 @@ if label == clabel: print('%s[!]%s No %s/.switch_label%s found, and the target rootfs is %subuntu%s:%strusty%s. Cannot continue.' % (Fore.RED, Fore.RESET, Fore.BLUE, Fore.RESET, Fore.YELLOW, Fore.RESET, Fore.YELLOW, Fore.RESET)) print('%s[!]%s To fix this, run %secho some_tag > /.switch_label%s (replacing %ssome_tag%s with something like %sdebian_sid%s) from the current Bash terminal.' % (Fore.RED, Fore.RESET, Fore.GREEN, Fore.RESET, Fore.GREEN, Fore.RESET, Fore.GREEN, Fore.RESET)) - exit(-1) + sys.exit(-1) else: print('%s[!]%s No %s/.switch_label%s found, assuming current rootfs is %subuntu%s:%strusty%s.' % (Fore.RED, Fore.RESET, Fore.BLUE, Fore.RESET, Fore.YELLOW, Fore.RESET, Fore.YELLOW, Fore.RESET)) @@ -79,11 +79,11 @@ if clabel == label: print('%s[!]%s The %s%s%s:%s%s%s rootfs is the current installation.' % (Fore.YELLOW, Fore.RESET, Fore.YELLOW, image, Fore.RESET, Fore.YELLOW, tag, Fore.RESET)) - exit(-1) + sys.exit(-1) if not os.path.isdir(os.path.join(basedir, 'rootfs_' + label)): print('%s[!]%s The %s%s%s:%s%s%s rootfs is not installed.' % (Fore.RED, Fore.RESET, Fore.YELLOW, image, Fore.RESET, Fore.YELLOW, tag, Fore.RESET)) - exit(-1) + sys.exit(-1) # do the switch @@ -94,7 +94,7 @@ except subprocess.CalledProcessError as err: print('%s[!]%s Failed to backup current %srootfs%s: %s' % (Fore.RED, Fore.RESET, Fore.BLUE, Fore.RESET, err)) - exit(-1) + sys.exit(-1) print('%s[*]%s Moving desired %srootfs_%s%s to %srootfs%s...' % (Fore.GREEN, Fore.RESET, Fore.BLUE, label, Fore.RESET, Fore.BLUE, Fore.RESET)) @@ -112,4 +112,4 @@ print('%s[!]%s Failed to roll back to old %srootfs%s: %s' % (Fore.RED, Fore.RESET, Fore.BLUE, Fore.RESET, err)) print('%s[!]%s You are now the proud owner of one broken Linux subsystem! To fix it, run %slxrun /uninstall%s and %slxrun /install%s from the command prompt.' % (Fore.RED, Fore.RESET, Fore.GREEN, Fore.RESET, Fore.GREEN, Fore.RESET)) - exit(-1) + sys.exit(-1) diff --git a/utils.py b/utils.py index d8b0797..5f8022a 100755 --- a/utils.py +++ b/utils.py @@ -80,7 +80,7 @@ def parse_image_arg(argv, can_be_file = False): fname = names[0] else: print('%s[!]%s No files found matching %s%s%s.' % (Fore.RED, Fore.RESET, Fore.BLUE, fname, Fore.RESET)) - exit(-1) + sys.exit(-1) else: fname = 'rootfs_%s_%s' % (image.replace('/', '_'), tag) @@ -95,7 +95,7 @@ def parse_image_arg(argv, can_be_file = False): if not os.path.isfile(fname): print('%s[!]%s %s%s%s is not an existing file.' % (Fore.RED, Fore.RESET, Fore.BLUE, fname, Fore.RESET)) - exit(-1) + sys.exit(-1) idx = -1 @@ -134,14 +134,14 @@ def probe_wsl(silent = False): return None, None print('%s[!]%s The Linux subsystem is not installed. Please go through the standard installation procedure first.' % (Fore.RED, Fore.RESET)) - exit(-1) + sys.exit(-1) if os.path.exists(os.path.join(basedir, 'temp')): if silent: return None, None print('%s[!]%s The Linux subsystem is currently running. Please kill all instances before continuing.' % (Fore.RED, Fore.RESET)) - exit(-1) + sys.exit(-1) lxpath = '' lxpaths = [os.path.join(os.getenv('SystemRoot'), 'sysnative'), os.path.join(os.getenv('SystemRoot'), 'System32')] @@ -153,7 +153,7 @@ def probe_wsl(silent = False): if not lxpath and not silent: print('%s[!]%s Unable to find %slxrun.exe%s in the expected locations.' % (Fore.RED, Fore.RESET, Fore.BLUE, Fore.RESET)) - exit(-1) + sys.exit(-1) return basedir, lxpath