-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathsrmwinget.sh
49 lines (40 loc) · 1.11 KB
/
srmwinget.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
#!/bin/sh
#
# Copyright (c) 2008 Rainer Clasen
#
# This program is free software; you can redistribute it and/or modify
# it under the terms described in the file LICENSE included in this
# distribution.
#
# Example script to retrieve files into a srmwin compatible directory tree
# Note: this is mostly untested.
set -e
: ${srmbase:="$HOME/.wine/drive_c/Program Files/SRM Training System/_data.srm"}
: ${srmdev:="/dev/ttyUSB1"}
# get file
tmp=`mktemp -p "$srmbase" --suffix ".srm" `
srmcmd $srmopt -g -w "$tmp" "$srmdev"
# build filename
athlete=`srmcmd -n -r "$tmp" | sed -e 's/[ ]*//g'`
: ${athlete:="YYY"}
initial=`echo "$athlete" | sed -e 's/^\(.\).*/\1/'`
time=`srmcmd -d -r "$tmp"`
dir="$srmbase/_$athlete.SRM/`date -d"@$time" +"%Y_%m"`.SRM"
[ -d "$dir" ] || mkdir -p "$dir"
# note: somehow depends on the selected time format:
fname="$initial`date -d"@$time" +"%d%m%y"`"
path=""
for x in A B C D E F G H I J; do
path="$dir/$fname$x.srm"
if [ -r "$path" ]; then
path=""
else
break;
fi
done
if [ -z "$path" ]; then
echo "cannot find unused filename for >$dir/$fname<">&2
exit 1
fi
# move
mv "$tmp" "$path"