generated from stubbfel/nix-project-template
draft
This commit is contained in:
76
src/patch-manjaro-sway-mirror-for-arm.sh
Executable file
76
src/patch-manjaro-sway-mirror-for-arm.sh
Executable file
@@ -0,0 +1,76 @@
|
||||
#!/bin/env sh
|
||||
|
||||
usage() {
|
||||
echo "Usage: patch-manjaro-sway-mirror-for-arm.sh [OPTIONS]"
|
||||
echo "Options:"
|
||||
echo " -t, --target-file Path to the target file (default: /usr/bin/manjaro-sway-mirrors)"
|
||||
echo " -s, --search-pattern Search pattern to replace (default: $(pacman-mirrors -G)"
|
||||
echo " -r, --replace-pattern Replace pattern (default: \$(pacman-mirrors -G \| sed 's/^arm-//'))"
|
||||
echo " --dry-run Run the sed command without modifying the file"
|
||||
echo " --help Display this help message"
|
||||
exit 0
|
||||
}
|
||||
|
||||
# Default values
|
||||
dry_run=false
|
||||
|
||||
# Parse command-line options
|
||||
while [ $# -gt 0 ]; do
|
||||
case "$1" in
|
||||
-t | --target-file)
|
||||
shift
|
||||
target_file="$1"
|
||||
;;
|
||||
-s | --search-pattern)
|
||||
shift
|
||||
search_pattern="$1"
|
||||
;;
|
||||
-r | --replace-pattern)
|
||||
shift
|
||||
replace_pattern="$1"
|
||||
;;
|
||||
--dry-run)
|
||||
dry_run=true
|
||||
;;
|
||||
--help)
|
||||
usage
|
||||
;;
|
||||
*)
|
||||
# Check if positional arguments are provided
|
||||
if [ -z "$target_file" ]; then
|
||||
target_file="$1"
|
||||
elif [ -z "$search_pattern" ]; then
|
||||
search_pattern="$1"
|
||||
elif [ -z "$replace_pattern" ]; then
|
||||
replace_pattern="$1"
|
||||
else
|
||||
echo "Invalid argument: $1"
|
||||
usage
|
||||
fi
|
||||
;;
|
||||
esac
|
||||
shift
|
||||
done
|
||||
|
||||
if [ -z "$target_file" ]; then
|
||||
target_file="${MSMAP_TARGET_ROOT}/usr/bin/manjaro-sway-mirrors"
|
||||
fi
|
||||
|
||||
if [ -z "$search_pattern" ]; then
|
||||
# shellcheck disable=SC2016
|
||||
search_pattern='\$(pacman-mirrors -G)'
|
||||
fi
|
||||
|
||||
if [ -z "$replace_pattern" ]; then
|
||||
# shellcheck disable=SC2016
|
||||
replace_pattern='\$(pacman-mirrors -G \| sed \"s/^arm-//\")'
|
||||
fi
|
||||
|
||||
sed_command="sed -i \"s|${search_pattern}|${replace_pattern}|g\" \"${target_file}\""
|
||||
# Perform the sed command
|
||||
if $dry_run; then
|
||||
echo "$sed_command"
|
||||
sed "s|${search_pattern}|${replace_pattern}|g" "${target_file}"
|
||||
else
|
||||
eval "${sed_command}"
|
||||
fi
|
||||
Reference in New Issue
Block a user