Вы можете написать функцию оболочки, чтобы поместить оболочку вокруг curl
и параметризовать свои вызовы, что-то вроде:
fetch_via_curl() {
# $1 is URL to fetch
# $2 is referrer string
# $3 is cookie string
# $4 is output file name
curl_fmt="$(cat << 'EOF'
curl '%s' \
-H 'sec-fetch-mode: no-cors' -H 'accept-encoding: gzip, deflate, br' \
-H 'accept-language: en-US' \
-H 'user-agent: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) discord/0.0.90 Chrome/76.0.3809.94 Electron/6.0.0 Safari/537.36' \
-H 'accept: image/webp,image/apng,image/*,*/*;q=0.8' \
-H 'referer: %s' \
-H 'authority: cdn.discordapp.com' \
-H 'cookie: %s' \
-H 'sec-fetch-site: same-site' \
--compressed \
--output '%s' ;
EOF
)"
file_num=
while [ -f "$4${file_num:+.${file_num}}" ]
do
file_num=$(($file_num+1))
done
curl_cmd="$(printf $curl_fmt "$1" "$2" "$3" "$4${file_num:+.${file_num}}")"
sh -c "$curl_cmd"
}
Затем извлеките файлы с синтаксисом вроде:
fetch_via_curl \
"https://cdn.discordapp.com/emojis/585807750991183872.png?v=1" \
"https://canary.discordapp.com/channels/584291323893383169/607165146476969984" \
"__cfduid=d36533327b001d6036b90a8c278c91d491562662533" \
"emoji.png"
Если emoji.png
не существует, файл будет сохранен в emoji.png
. Если он существует, файл будет сохранен в emoji.png.N
, где N — наименьшее положительное целое число, приводящее к несуществующему имени файла.
sudo не сохраняет переменные окружения, попробуйте вариант -E
. См.man 8 sudo
-E' The -E (preserve environment) option indicates to the security policy that the user wishes to preserve their existing environment variables. The security policy may return an error if the -E option is specified and the user does not have permission to preserve the environment.