summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorIsmael Luceno2020-05-15 21:20:44 +0200
committerIsmael Luceno2020-05-15 21:23:12 +0200
commit716b074a93ef600ce0a91fbf4d7ee1a0639d858b (patch)
tree1f27395dc7e267311dddcb92b747bec7c37cb0e1
parent05f34766ed2b2c7ddba0702ec62c18458388042f (diff)
libdetails: Unify and simplify URL sanitization
-rw-r--r--var/lib/quill/modules/libdetails34
1 files changed, 20 insertions, 14 deletions
diff --git a/var/lib/quill/modules/libdetails b/var/lib/quill/modules/libdetails
index 08be920..57e3954 100644
--- a/var/lib/quill/modules/libdetails
+++ b/var/lib/quill/modules/libdetails
@@ -22,6 +22,24 @@ function query_spell_name(){
fi
}
+
+#---
+## Sanitize a SOURCE_URL
+#---
+sanitize_source_url() {
+ awk '
+ {
+ sub(/[?#].*/, "")
+ for (i in R) sub(i, R[i])
+ print
+ }
+ BEGIN {
+ R["^https?://prdownloads.sourceforge.net/"]="$SOURCEFORGE_URL/"
+ R["^https?://downloads.sourceforge.net/"]="$SOURCEFORGE_URL/"
+ }
+ '
+}
+
#---
##
## @Globals SPELL_SRC_URL
@@ -32,24 +50,12 @@ function query_spell_source_url(){
# I tested this with various URLs and it seems to work quite well
# if any other are found should be included
# possibly split the code into a separate function???
- SPELL_SRC_URL=$(sed -e "s,http://prdownloads.sourceforge.net,$SOURCEFORGE_URL," \
- -e "s,http://downloads.sourceforge.net/\(.*\)?.*,$SOURCEFORGE_URL/\1," \
- -e "s,http://downloads.sourceforge.net/\(.*\),$SOURCEFORGE_URL/\1," \
- -e "s,http://prdownload.berlios.de/\(.*\),http://download.berlios.de/\1," \
- -e "s,http://sourceforge.net/project/showfiles.php.*,," \
- -e "s,^\(.*\)/\(.*\)?.*,\1/\2," \
- <<< $SPELL_SRC_URL)
+ SPELL_SRC_URL=$(sanitize_source_url <<< "$SPELL_SRC_URL")
if ! [[ $SPELL_SRC_URL ]] ||
! query "Is $SPELL_SRC_URL the proper source url?" y; then
query_msg "Please enter the url of the source:"
read "SPELL_SRC_URL"
- SPELL_SRC_URL=$(sed -e "s,http://prdownloads.sourceforge.net,$SOURCEFORGE_URL," \
- -e "s,http://downloads.sourceforge.net/\(.*\)?.*,$SOURCEFORGE_URL/\1," \
- -e "s,http://downloads.sourceforge.net/\(.*\),$SOURCEFORGE_URL/\1," \
- -e "s,http://prdownload.berlios.de/\(.*\),http://download.berlios.de/\1," \
- -e "s,http://sourceforge.net/project/showfiles.php.*,," \
- -e "s,^\(.*\)/\(.*\)?.*,\1/\2," \
- <<< $SPELL_SRC_URL)
+ SPELL_SRC_URL=$(sanitize_source_url <<< "$SPELL_SRC_URL")
fi
}