-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfetch.sh
More file actions
executable file
·38 lines (27 loc) · 929 Bytes
/
fetch.sh
File metadata and controls
executable file
·38 lines (27 loc) · 929 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
#!/bin/bash
set -e
if [[ -z "${USERNAME}" ]]; then
echo "FTP Username is not set, exiting!"
exit 2
fi
if [[ -z "${PASSWORD}" ]]; then
echo "FTP Password is not set, exiting!"
exit 2
fi
mkdir -p /tmp/build
curl --list-only ftp://195.255.176.166/karttainfopoiminta/ --user ${USERNAME}:${PASSWORD} > /tmp/allfiles.txt
grep -E '^.*\.zip$' /tmp/allfiles.txt > /tmp/latestfile.txt
export LATEST_FILE=`tail -1 /tmp/latestfile.txt`
rm /tmp/allfiles.txt
rm /tmp/latestfile.txt
echo "Latest file is ${LATEST_FILE}"
if [ -f "/tmp/build/$LATEST_FILE" ]
then
echo "Latest build was already found, won't run it again"
echo "Exiting!" 1>&2
exit 64
fi
rm -rf /tmp/build/*
curl ftp://195.255.176.166/karttainfopoiminta/${LATEST_FILE} --user ${USERNAME}:${PASSWORD} --output /tmp/build/${LATEST_FILE}
ln -s /tmp/build/${LATEST_FILE} /tmp/build/latest.zip
echo "Latest build can be accessed as /tmp/build/latest.zip"