Skip to content
Closed
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
51 changes: 41 additions & 10 deletions vet
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ usage() {
vet ${VERSION} - A safer way to run remote scripts.

USAGE:
vet [OPTIONS] <URL> [SCRIPT_ARGUMENTS...]
vet [OPTIONS] <URL|FILE_PATH> [SCRIPT_ARGUMENTS...]

OPTIONS:
-f, --force Skip all interactive prompts and execute immediately.
Expand All @@ -54,11 +54,26 @@ check_dependencies() {
elif command -v wget &>/dev/null; then
DOWNLOAD_CMD=(wget -qO)
else
log_error "This tool requires either 'curl' or 'wget'."
log_error "This tool requires either 'curl' or 'wget' for remote URLs."
exit 1
fi
}

# Check if the input is a local file path
is_local_file() {
local input="$1"
# Check if it's an absolute path, relative path, or doesn't contain URL schemes
if [[ "$input" =~ ^(https?|ftp|ftps):\/\/ ]]; then
return 1 # It's a URL
elif [[ -f "$input" ]]; then
return 0 # It's an existing local file
elif [[ "$input" =~ ^[.\/~] ]] || [[ "$input" =~ \/ ]] && [[ ! "$input" =~ :\/\/ ]]; then
return 0 # It looks like a file path (even if file doesn't exist yet)
else
return 1 # Assume it's a URL
fi
}

trap cleanup EXIT INT TERM

FORCE_MODE=0
Expand Down Expand Up @@ -91,28 +106,44 @@ done
URL="${1-}"

if [ -z "$URL" ]; then
log_error "No URL provided."
log_error "No URL or file path provided."
usage
exit 1
fi
shift

SCRIPT_ARGS=("$@")

check_dependencies

mkdir -p "$CACHE_DIR"
TMPFILE=$(mktemp) || { log_error "Failed to create temporary file."; exit 1; }
TMPFILE_DIFF=$(mktemp) || { log_error "Failed to create temporary diff file."; exit 1; }

log_info "Downloading script from: $URL"
if ! "${DOWNLOAD_CMD[@]}" "$TMPFILE" "$URL"; then
log_error "Download failed. Check URL and network connection."
exit 1
# Check if input is a local file or remote URL
if is_local_file "$URL"; then
# Handle local file
if [[ ! -f "$URL" ]]; then
log_error "Local file does not exist: $URL"
exit 1
fi

log_info "Using local script file: $URL"
if ! cp "$URL" "$TMPFILE"; then
log_error "Failed to copy local file."
exit 1
fi
else
# Handle remote URL
check_dependencies

log_info "Downloading script from: $URL"
if ! "${DOWNLOAD_CMD[@]}" "$TMPFILE" "$URL"; then
log_error "Download failed. Check URL and network connection."
exit 1
fi
fi

if [ ! -s "$TMPFILE" ]; then
log_error "Downloaded file is empty. The URL may be incorrect."
log_error "Script file is empty. The URL or file path may be incorrect."
exit 1
fi

Expand Down
Loading