summaryrefslogtreecommitdiff
path: root/local/bin/usbumount
blob: ffe68bc1f249b8c641279acdbd93d5921d20166c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
#!/usr/bin/env python3

import os
import subprocess
import sys

RED = "\033[0;31m"
RESET = "\033[0m"

def run(cmd, fail_msg):
    try:
        subprocess.run(cmd, check=True)
    except subprocess.CalledProcessError:
        print(f"{RED}[!] {fail_msg}{RESET}")
        sys.exit(1)

def main():
    if os.geteuid() != 0:
        print(f"{RED}[!] Superuser access is required{RESET}")
        sys.exit(1)

    print(f"{RED}[*] Unmounting /mnt/usb...{RESET}")
    run(["umount", "/mnt/usb"], "Failed to unmount /mnt/usb")

    print(f"{RED}[*] Closing encrypted device...{RESET}")
    run(["cryptsetup", "close", "sda1_crypt"], "Failed to close mapper device")

    print(f"{RED}[*] Unmounted and closed successfully!{RESET}")

if __name__ == "__main__":
    main()