ups/scripts/apply.sh
ngn ab580d6a18
Some checks failed
format / build (push) Failing after 6s
initial commit
Signed-off-by: ngn <ngn@ngn.tf>
2025-05-02 18:20:24 +03:00

74 lines
1.4 KiB
Bash

#!/bin/bash
BLUE="\e[34m"
YELLOW="\e[33m"
RED="\e[31m"
BOLD="\e[1m"
GREEN="\e[32m"
RESET="\e[0m"
if [ $# -ne 1 ]; then
echo "please specify a patch file"
exit 1
fi
if [ ! -f "${1}" ]; then
echo "specified patch file does not exist"
exit 1
fi
from="$(grep "From: " "${1}" | sed 's/From: //g')"
title="$(grep "Subject: \[PATCH\] " "${1}" | sed 's/Subject: \[PATCH\] //g')"
applied=0
code=0
echo
echo -e "${BOLD}${GREEN}From ${RESET}${BOLD}:${RESET} ${from}"
echo -e "${BOLD}${GREEN}Title${RESET}${BOLD}:${RESET} ${title}"
echo
while true; do
echo -en "${BOLD}(${BLUE}E${RESET}${BOLD})dit "
echo -en "${BOLD}(${BLUE}A${RESET}${BOLD})pply "
[ $applied -eq 1 ] && echo -en "${BOLD}(${BLUE}U${RESET}${BOLD})ndo "
echo -en "${BOLD}(${BLUE}S${RESET}${BOLD})kip "
echo -en "${BOLD}(${BLUE}C${RESET}${BOLD})ancel "
read -s -n1 answer
echo -en "\r \r"
case "${answer,,}" in
"e")
$EDITOR "${1}"
;;
"a")
#git apply --reject --whitespace=fix "${1}" && break
git am --reject --whitespace=fix "${1}" && break
applied=1
;;
"u")
git am --abort
;;
"s")
break
;;
"c")
code=1
break
;;
*)
if [ ! -z "${answer}" ]; then
echo -e "${BOLD}Please enter a valid answer${RESET}"
fi
;;
esac
done
exit $code