forked from lookfirst/strava-auto-upload
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathupload.sh
executable file
·59 lines (46 loc) · 1.24 KB
/
upload.sh
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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
#!/bin/bash
set -e
SETTINGS="$HOME/.strava-auto-upload"
TO="upload@strava.com"
source "$SETTINGS/config"
log() {
DATE=`date +"%D %T: "`
echo $DATE $1
echo $DATE $1 >> "$SETTINGS/strava-auto-upload.log"
}
if [ ! -d "$SETTINGS" ]; then
mkdir -p $SETTINGS
fi
log "Started upload.sh script..."
if [ ! -d "$ACTIVITIES" ]; then
log "Could not find your garmin folder: $ACTIVITIES"
exit
fi
if [ -e "$SETTINGS/last_file" ]; then
LAST_FILE=`cat $SETTINGS/last_file`
log "Looking for files after... $LAST_FILE"
fi
cd $ACTIVITIES
if [ ! -z "$LAST_FILE" ]; then
FOUND=`find . -name "*.fit" -mnewer $LAST_FILE`
else
FOUND=`find . -name "*.fit"`
fi
if [ -z "$FOUND" ]; then
log "No new files to upload."
else
log "Found: $FOUND"
for i in $FOUND
do
log "Emailing: $i"
HEAD="MIME-Version: 1.0\nFrom: $FROM\nTo: $TO\nContent-Type: multipart/mixed; boundary=STRAVA\n\n--STRAVA\nContent-Type: application/octet-stream; name=\"$i\"\n"
HEAD2="Content-Disposition: attachment; filename=\"$i\"\nContent-Transfer-Encoding: base64\n\n"
DATA=`base64 -b 76 $i`
printf "%b%b%s" "$HEAD" "$HEAD2" "$DATA" | sendmail -t
done
if [ ! -z $i ]; then
log "Setting last_file to: $i"
echo -n $i > "$SETTINGS/last_file"
fi
fi
log "Finished upload.sh script."