Project

General

Profile

download_redmine.sh

Jonathan Cormier, 03/29/2017 10:13 PM

Download (1.18 KB)

 
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
Add picture from clipboard (Maximum size: 600 MB)