Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 22 additions & 16 deletions contrib/cryptpass.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/usr/bin/python
#!/usr/bin/python3
# Copyright (c) TurnKey GNU/Linux - https://www.turnkeylinux.org
#
# This file is part of Fab
Expand All @@ -13,48 +13,54 @@

Example usage:
./cryptpass.py > crypthash # prompts for password
echo password | ./cryptpass.py
echo password | ./cryptpass.py

"""
import os
import sys

import crypt
import getpass
import os
import random

import sys
from typing import NoReturn

SALTCHARS = './abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789';
SALTCHARS = "./abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789"


def random_salt() -> str:
return "".join([SALTCHARS[random.randint(0, len(SALTCHARS) - 1)] for i in range(2)])
return "".join(
[SALTCHARS[random.randint(0, len(SALTCHARS) - 1)] for i in range(2)]
)


def fatal(s: Any) -> NoReturn:
print("error: " + str(s), file=sys.stderr)
def fatal(message: str) -> NoReturn:
print(f"Error: {message}", file=sys.stderr)
sys.exit(1)


def usage() -> NoReturn:
print("Syntax: %s" % sys.argv[0])
print(f"Syntax: {sys.argv[0]}")
print(__doc__.strip())

sys.exit(1)

def main():
if '-h' in sys.argv:

def main() -> None:
if "-h" in sys.argv:
usage()

if os.isatty(sys.stdin.fileno()):
password = getpass.getpass("Password: ")
if not password:
fatal("empty password")

if getpass.getpass("Confirm: ") != password:
fatal("passwords don't match")
else:
password = sys.stdin.readline().rstrip("\n")

print(crypt.crypt(password, random_salt()))



if __name__ == "__main__":
main()

68 changes: 37 additions & 31 deletions contrib/iso2usb.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/usr/bin/env python
#!/usr/bin/python3
# Copyright (c) 2013 Alon Swartz <[email protected]>
#
# This file is part of Fab
Expand All @@ -25,36 +25,41 @@
This will alter the image, you might want to make a copy before hand.
"""

import getopt
import os
import sys
import stat
import getopt
import subprocess
import sys
from typing import NoReturn


class Error(Exception):
pass


def fatal(e: Any) -> NoReturn:
print('Error: ' + str(e), file=sys.stderr)
def fatal(message: str | Error | getopt.GetoptError) -> NoReturn:
print(f"Error: {message}", file=sys.stderr)
sys.exit(1)

def usage(e: Any=None) -> NoReturn:
if e:
print('Error: ' + str(e), file=sys.stderr)

def usage(message: str | getopt.GetoptError | None = None) -> NoReturn:
if message:
print(f"Error: {message}", file=sys.stderr)

cmd = os.path.basename(sys.argv[0])
print('Syntax: %s iso_path usb_device' % cmd, file=sys.stderr)
print(f"Syntax: {cmd} iso_path usb_device", file=sys.stderr)
print(__doc__.strip(), file=sys.stderr)

sys.exit(1)

class Error(Exception):
pass

class Iso:
def __init__(self, path: str):
def __init__(self, path: str) -> None:
self.path = os.path.realpath(path)
self.name = os.path.basename(self.path)

if not os.path.exists(self.path):
raise Error("iso path does not exist: %s" % self.path)
raise Error(f"iso path does not exist: {self.path}")

def make_hybrid(self) -> None:
subprocess.run(["isohybrid", self.path])
Expand All @@ -65,8 +70,7 @@ def make_hybrid(self) -> None:
@property
def is_hybrid(self) -> bool:
output = subprocess.run(
["fdisk", "-l", self.path],
capture_output=True, text=True
["fdisk", "-l", self.path], capture_output=True, text=True
).stdout

if "Hidden HPFS/NTFS" in output:
Expand All @@ -82,20 +86,22 @@ def is_hybrid(self) -> bool:


class Usb:
def __init__(self, path: str):
def __init__(self, path: str) -> None:
self.path = path

if not os.path.exists(self.path):
raise Error("usb path does not exist: %s" % self.path)
raise Error(f"usb path does not exist: {self.path}")

if not self.is_block_device:
raise Error("usb path is not a block device: %s" % self.path)
raise Error(f"usb path is not a block device: {self.path}")

if self.is_partition:
raise Error("usb path seems to be a partition: %s" % self.path)
raise Error(f"usb path seems to be a partition: {self.path}")

if not self.is_usb_device:
raise Error("usb path is not verifiable as a usb device: %s" % self.path)
raise Error(
f"usb path is not verifiable as a usb device: {self.path}"
)

@property
def is_block_device(self) -> bool:
Expand All @@ -122,18 +128,19 @@ def name(self) -> str:
output = subprocess.run(cmd, text=True).stdout
return output.split(" ")[0]

def write_iso(self, iso_path: str):
cmd = ["dd", "if=%s" % iso_path, "of=%s" % self.path]
def write_iso(self, iso_path: str) -> None:
cmd = ["dd", f"if={iso_path}", f"of={self.path}"]
subprocess.run(cmd)

def main():

def main() -> None:
try:
opts, args = getopt.gnu_getopt(sys.argv[1:], 'h', ['help'])
opts, args = getopt.gnu_getopt(sys.argv[1:], "h", ["help"])
except getopt.GetoptError as e:
usage(e)

for opt, val in opts:
if opt in ('-h', '--help'):
for opt, _val in opts:
if opt in ("-h", "--help"):
usage()

if not len(args) == 2:
Expand All @@ -149,8 +156,8 @@ def main():
fatal(e)

print("*" * 78)
print("iso: %s (hybrid: %s)" % (iso.name, iso.is_hybrid))
print("usb: %s (%s)" % (usb.name, usb.path))
print(f"iso: {iso.name} (hybrid: {iso.is_hybrid})")
print(f"usb: {usb.name} ({usb.path})")
print("*" * 78)

cont = input("Is the above correct? (y/N): ").strip()
Expand All @@ -165,6 +172,5 @@ def main():
usb.write_iso(iso.path)


if __name__ == '__main__':
main()

if __name__ == "__main__":
main()
Loading