Compare commits
2 Commits
2019-03-13
...
2019-03-16
Author | SHA1 | Date | |
---|---|---|---|
e165d6768f | |||
5660ef32ad |
13
ddusb.py
13
ddusb.py
@ -2,6 +2,7 @@
|
|||||||
"""Wrapper script for using dd to write to a USB drive."""
|
"""Wrapper script for using dd to write to a USB drive."""
|
||||||
|
|
||||||
import argparse
|
import argparse
|
||||||
|
import os
|
||||||
import pathlib
|
import pathlib
|
||||||
import re
|
import re
|
||||||
import subprocess
|
import subprocess
|
||||||
@ -10,6 +11,10 @@ import subprocess
|
|||||||
COMMENT_PATTERN = "^[#;]"
|
COMMENT_PATTERN = "^[#;]"
|
||||||
EXCLUDE_FILE = "/etc/helper-scripts/ddusb-exclude.conf"
|
EXCLUDE_FILE = "/etc/helper-scripts/ddusb-exclude.conf"
|
||||||
|
|
||||||
|
E_BLOCKDEVICE_ERROR = 1
|
||||||
|
E_EXCLUDE_ERROR = 2
|
||||||
|
E_DD_ERROR = 3
|
||||||
|
|
||||||
|
|
||||||
# ========== Functions ==========
|
# ========== Functions ==========
|
||||||
def read_exclude_file(exclude_file):
|
def read_exclude_file(exclude_file):
|
||||||
@ -46,7 +51,7 @@ block_path = args.output_file
|
|||||||
# Ensure that block_path is really a block device
|
# Ensure that block_path is really a block device
|
||||||
if not pathlib.Path(block_path).is_block_device():
|
if not pathlib.Path(block_path).is_block_device():
|
||||||
print(f'Error: "{block_path}" is not a block device')
|
print(f'Error: "{block_path}" is not a block device')
|
||||||
exit(1)
|
exit(E_BLOCKDEVICE_ERROR)
|
||||||
|
|
||||||
# Check if block_path is excluded
|
# Check if block_path is excluded
|
||||||
exclude_patterns = read_exclude_file(EXCLUDE_FILE)
|
exclude_patterns = read_exclude_file(EXCLUDE_FILE)
|
||||||
@ -54,7 +59,7 @@ exclude_patterns = read_exclude_file(EXCLUDE_FILE)
|
|||||||
for pattern in exclude_patterns:
|
for pattern in exclude_patterns:
|
||||||
if re.fullmatch(pattern, block_path):
|
if re.fullmatch(pattern, block_path):
|
||||||
print(f'Error: "{block_path}" is blacklisted from running dd')
|
print(f'Error: "{block_path}" is blacklisted from running dd')
|
||||||
exit(2)
|
exit(E_EXCLUDE_ERROR)
|
||||||
|
|
||||||
print(f"Input file: {input_file}")
|
print(f"Input file: {input_file}")
|
||||||
print(f"Block device: {block_path}")
|
print(f"Block device: {block_path}")
|
||||||
@ -72,6 +77,6 @@ try:
|
|||||||
check=True,
|
check=True,
|
||||||
)
|
)
|
||||||
except subprocess.CalledProcessError:
|
except subprocess.CalledProcessError:
|
||||||
exit(3)
|
exit(E_DD_ERROR)
|
||||||
else:
|
else:
|
||||||
subprocess.run("sync")
|
os.sync()
|
||||||
|
@ -1,7 +1,6 @@
|
|||||||
#compdef ddusb
|
#compdef ddusb
|
||||||
|
|
||||||
# zsh completions for 'ddusb'
|
# zsh completions for 'ddusb'
|
||||||
# automatically generated with http://github.com/RobSis/zsh-completion-generator
|
|
||||||
local arguments
|
local arguments
|
||||||
|
|
||||||
arguments=(
|
arguments=(
|
||||||
|
@ -2,7 +2,6 @@
|
|||||||
local arguments
|
local arguments
|
||||||
|
|
||||||
arguments=(
|
arguments=(
|
||||||
$argument_list
|
|
||||||
{-h,--help}'[show this help message and exit]'
|
{-h,--help}'[show this help message and exit]'
|
||||||
{-b,--boot}'[edit a file in /boot]'
|
{-b,--boot}'[edit a file in /boot]'
|
||||||
{-d,--dir}'[edit a file in a given directory]'
|
{-d,--dir}'[edit a file in a given directory]'
|
||||||
|
Reference in New Issue
Block a user