diff --git a/scripts/rename-partitions.py b/scripts/rename-partitions.py deleted file mode 100755 index 560ade2..0000000 --- a/scripts/rename-partitions.py +++ /dev/null @@ -1,91 +0,0 @@ -#! /usr/bin/env nix-shell -#! nix-shell -i python3 -p python3 parted - -import subprocess -import sys -from time import sleep - - -def _run_command(command, user_input=""): - if user_input: - result = subprocess.run( - command, capture_output=True, text=True, check=True, input=user_input - ) - else: - result = subprocess.run(command, capture_output=True, text=True, check=True) - return result - - -def _y_n(question): - answer = input("{} (Y/N): ".format(question)) - if answer.lower() == "y": - return True - if answer.lower() == "n": - return False - print("Please only answer with Y or N!") - sys.exit(1) - - -def rename_boot_partition(): - print("Rename boot partition.") - _run_command(["fatlabel", "/dev/disk/by-label/BOOTTOFRMT", "BOOT"]) - - -def _rename_ext4(): - print("Rename ext4 partition.") - _run_command(["e2label", "/dev/MainGroup/roottoformat", "root"]) - - -def _rename_f2fs(): - print("Rename f2fs partition.") - _run_command(["f2fslabel", "/dev/disk/by-label/ROOTTOFRMT", "root"]) - - -def _rename_swap(): - print("Rename swap partition.") - _run_command(["swaplabel", "-L", "swap", "/dev/GroupToFormat/swaptoformat"]) - - -def _rename_lvm(): - print("Rename LVM") - _run_command(["lvrename", "GroupToFormat", "roottoformat", "root"]) - _run_command(["vgrename", "GroupToFormat", "MainGroup"]) - - -def unmount_partitions(): - print("Unmounting partitions.") - _run_command(["umount", "/mnt/nixos/boot"]) - _run_command(["umount", "/mnt/nixos"]) - sleep(3) - - -def close_luks(): - _run_command(["cryptsetup", "close", "crypttoformat"]) - - -def rename_pc(swap): - if swap: - _rename_swap() - _rename_ext4() - _rename_lvm() - - -def rename_raspi(): - _rename_f2fs() - - -def main(): - raspi = _y_n("Do we rename a Raspberry Pi?") - unmount_partitions() - sleep(5) - rename_boot_partition() - if raspi: - rename_raspi() - else: - swap = _y_n("Do you have swap?") - rename_pc(swap) - close_luks() - - -if __name__ == "__main__": - main() diff --git a/scripts/rename-partitions.sh b/scripts/rename-partitions.sh new file mode 100644 index 0000000..64c8da9 --- /dev/null +++ b/scripts/rename-partitions.sh @@ -0,0 +1,56 @@ +#! /usr/bin/env nix-shell +#! nix-shell -i bash -p parted + +rename_boot_partition() { + echo "Rename boot partition." + fatlabel /dev/disk/by-label/BOOTTOFRMT BOOT +} + +rename_ext4() { + echo "Rename ext4 partition." + e2label /dev/MainGroup/roottoformat root +} + +rename_f2fs() { + echo "Rename f2fs partition." + f2fslabel /dev/disk/by-label/ROOTTOFRMT root +} + +rename_swap() { + echo "Rename swap partition." + swaplabel -L swap /dev/GroupToFormat/swaptoformat +} + +rename_lvm() { + echo "Rename LVM" + lvrename GroupToFormat roottoformat root + vgrename GroupToFormat MainGroup +} + +unmount_partitions() { + echo "Unmounting partitions." + umount /mnt/nixos/boot + umount /mnt/nixos + sleep 3 +} + +close_luks() { + cryptsetup close crypttoformat +} + +rename_pc() { + rename_ext4 + rename_lvm + rename_swap +} + +rename_raspi() { + rename_f2fs +} + +unmount_partitions +sleep 5 +rename_boot_partition +rename_raspi +# rename_pc +close_luks