RE: Downloading files from Redmine (using Linux console app) ยป download_redmine.sh
1 |
#!/bin/bash
|
---|---|
2 |
|
3 |
#set -x
|
4 |
|
5 |
CURL_CONFIGS="--silent --show-error --fail --insecure --location -b cookies.txt -c cookies.txt" |
6 |
#CURL_CONFIGS="--insecure --location -b cookies.txt -c cookies.txt"
|
7 |
CURL_CONFIGS2="--show-error --fail --insecure --location -b cookies.txt -c cookies.txt" |
8 |
|
9 |
DOWNLOAD_FILE=https://support.criticallink.com/redmine/attachments/download/8271/MitySOM-335X_Dev_SD_512MB_NAND.zip |
10 |
USER=user |
11 |
PASS=pass |
12 |
|
13 |
cleanup()
|
14 |
{
|
15 |
rm -f cookies.txt |
16 |
}
|
17 |
|
18 |
# Initial cleanup
|
19 |
cleanup |
20 |
|
21 |
# Fetch CSRF authenticity token
|
22 |
CSRF1=$(curl $CURL_CONFIGS https://support.criticallink.com/redmine/login | grep "name=\"authenticity_token" | sed 's/.*value="\(.*\)".*/\1/') |
23 |
|
24 |
if [[ $? -ne 0 ]] |
25 |
then
|
26 |
echo "Error getting csrf token" |
27 |
echo $CSRF1 |
28 |
cleanup |
29 |
exit 1
|
30 |
fi
|
31 |
|
32 |
#echo $CSRF1
|
33 |
|
34 |
# Login
|
35 |
HTML=$(curl $CURL_CONFIGS -d "login=Login&username=${USER}&password=${PASS}&authenticity_token=${CSRF1}" https://support.criticallink.com/redmine/login) |
36 |
|
37 |
#echo $HTML
|
38 |
|
39 |
if [[ $? -ne 0 ]] |
40 |
then
|
41 |
echo "Error logging in" |
42 |
cleanup |
43 |
exit 1
|
44 |
fi
|
45 |
|
46 |
# Download file
|
47 |
curl $CURL_CONFIGS2 $DOWNLOAD_FILE --remote-name |
48 |
|
49 |
if [[ $? -ne 0 ]] |
50 |
then
|
51 |
echo "Error downloading backup file" | tee -a ${LOGFILE} |
52 |
cleanup |
53 |
exit 1
|
54 |
fi
|
55 |
|
56 |
cleanup |