From b391f4952c57ab8ef581f7b59c8b6b5a72d277ac Mon Sep 17 00:00:00 2001 From: Silvan Calarco Date: Mon, 15 Apr 2024 12:17:36 +0200 Subject: [PATCH] libapse.lib: support for user-agent in curl request --- Makefile | 1 - ...nf => 05-system-external-commands.conf.in} | 4 +++- lib/libapse.lib.in | 20 ++++++++++--------- 3 files changed, 14 insertions(+), 11 deletions(-) rename conf/{05-system-external-commands.conf => 05-system-external-commands.conf.in} (93%) diff --git a/Makefile b/Makefile index f45f312..7f103f7 100644 --- a/Makefile +++ b/Makefile @@ -192,4 +192,3 @@ mostlyclean: $(MAKE) clean -C po/$$loc || exit 1;\ done @rm -f po/*.pot - diff --git a/conf/05-system-external-commands.conf b/conf/05-system-external-commands.conf.in similarity index 93% rename from conf/05-system-external-commands.conf rename to conf/05-system-external-commands.conf.in index 025a7a2..8c39fd0 100644 --- a/conf/05-system-external-commands.conf +++ b/conf/05-system-external-commands.conf.in @@ -7,10 +7,12 @@ curl_opts_netlink="--connect-timeout 15 --retry 3" # (default: "-L --remote-name --fail --progress-bar $curl_opts_netlink") curl_options="-R -L --remote-name --fail --progress-bar $curl_opts_netlink" -# Sintax for 'proxy': "proxyhost:port" +# Syntax for 'proxy': "proxyhost:port" proxy="" # Sintax for 'proxy_user': "user:password" proxy_user="" +# curl user agent +curl_user_agent="autospec/@version@ (Linux; openmamba; reports@openmamba.org)" # Commands to run when a rpm package must be automatically installed # (NOTE: it could be necessary to manually configure sudo diff --git a/lib/libapse.lib.in b/lib/libapse.lib.in index 6a53967..3098a1f 100644 --- a/lib/libapse.lib.in +++ b/lib/libapse.lib.in @@ -1,7 +1,7 @@ #!/bin/bash # libapse.lib -- Autospec Package Search Engine library # Copyright (C) 2007,2012 Stefano Cotta Ramusino -# Copyright (C) 2008-2021 Silvan Calarco +# Copyright (C) 2008-2024 Silvan Calarco [ "$libapse_is_loaded" = 1 ] || { libapse_is_loaded=1 @@ -321,6 +321,8 @@ proxy:,proxy-user:,autoupdate-off: \ local curr_curl_url pck_file new_version last_version local curr_curl_proxy_opts="\ ${proxy:+ --proxy $proxy}${proxy_user:+ --proxy-user $proxy_user}" + local curr_curl_user_agent_opts="\ +${curl_user_agent:+ --user-agent \"$curl_user_agent\"}" for i in `seq 1 ${#autoupdate_off[*]}`; do apse_enabled[${autoupdate_off[$i-1]}]="0" @@ -343,9 +345,9 @@ ${proxy:+ --proxy $proxy}${proxy_user:+ --proxy-user $proxy_user}" <${NOTE}$curr_curl_url${NORM}> (\`${NOTE}source0${NORM}')..." notify.debug "\ -running: curl \$curr_curl_proxy_opts -s -L \"$curr_curl_url\"" +running: curl $curr_curl_proxy_opts $curr_curl_user_agent_opts -s -L \"$curr_curl_url\"" curl $curl_opts_netlink \ - $curr_curl_proxy_opts -s -L "$curr_curl_url" \ + $curr_curl_proxy_opts $curr_curl_user_agent_opts -s -L "$curr_curl_url" \ > $fcurlout let "retval = $?" @@ -446,8 +448,8 @@ sort -t. -n -r -k1 -k2 -k3 -k4 -k5 -k6 -k7 -k8 -k9 -k10 )) curr_curl_url="http://sourceforge.net/projects/$src_name/files/latest/download" notify.debug \ - "running: curl \$curr_curl_proxy_opts -s -L \"$curr_curl_url\"" - curl $curr_curl_proxy_opts -I -A Linux -s -L "$curr_curl_url" \ + "running: curl $curr_curl_proxy_opts $curr_curl_user_agent_opts -s -L \"$curr_curl_url\"" + curl $curr_curl_proxy_opts $curr_curl_user_agent_opts -I -A Linux -s -L "$curr_curl_url" \ > $fcurlout let "retval = $?" @@ -503,15 +505,15 @@ $"looking at"" ${NOTE}(#$i)${NORM} <${NOTE}${apse_site_name[$i]}${NORM}>..." } if [ "${apse_put_fields[$i]}" ]; then notify.debug "\ -running: curl \$curr_curl_proxy_opts -s -L -d \ +running: curl $curr_curl_proxy_opts $curr_curl_user_agent_opts -s -L -d \ \"${apse_put_fields[$i]}${search_name}\" \"$curr_curl_url\"" - curl $curr_curl_proxy_opts -s -L -d \ + curl $curr_curl_proxy_opts $curr_curl_user_agent_opts -s -L -d \ "${apse_put_fields[$i]}${search_name}" "$curr_curl_url" \ > $fcurlout else notify.debug "\ -running: curl \$curr_curl_proxy_opts -s -L \"$curr_curl_url\"" - curl $curr_curl_proxy_opts -s -L "$curr_curl_url" > $fcurlout +running: curl $curr_curl_proxy_opts $curr_curl_user_agent_opts -s -L \"$curr_curl_url\"" + curl $curr_curl_proxy_opts $curr_curl_user_agent_opts -s -L "$curr_curl_url" > $fcurlout fi let "retval = $?"