-
Notifications
You must be signed in to change notification settings - Fork 23
/
Copy pathforusb.sh
153 lines (127 loc) · 3.23 KB
/
forusb.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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
#!/bin/sh -e
echo
if [ ! -f forusb.sh ]
then
echo "Not in the right folder, be in same folder as script and run: sh forusb.sh"
exit
fi
echo
echo "This script will attempt to download and install the parakeet wixel firmware"
echo "in USB mode to a wixel attached to the USB port of this Raspberry Pi"
echo
echo "There is an option to set the python script to auto-start and it will try to launch"
echo "the script after installation"
echo
echo "You will need internet access and know your dexcom G4 transmitter number"
echo
read -p "Do you want to proceed? y/n : " z
if [ "$z" = "Y" ] || [ "$z" = "y" ]
then
echo
else
echo "Not proceeding.."
echo
exit
fi
if [ ! -f /usr/bin/sdcc ]
then
echo
echo "Installing recommended packages"
echo
sudo apt-get update && sudo apt-get -y install git screen python python-pycurl wget sdcc
echo
echo
fi
pw=`pwd`
if [ ! -s python-usb-wixel.py ]
then
echo "We do not appear to be in a folder containing python-usb-wixel.py"
echo
echo "Do you need to do: git clone https://github.com/jamorham/python-usb-wixel-xdrip.git "
echo
exit
fi
if [ ! -d wixel-xDrip ]
then
echo "Downloading wixel firmware"
git clone https://github.com/jamorham/wixel-xDrip
echo
fi
if [ ! -d wixel_linux ]
then
echo "Downloading wixel linux tools"
rm -f wixel-arm-linux-gnueabihf-150527.tar.gz
wget https://www.pololu.com/file/0J872/wixel-arm-linux-gnueabihf-150527.tar.gz
tar -xzvf wixel-arm-linux-gnueabihf-150527.tar.gz
fi
cd wixel-xDrip
echo "Configuring source code for USB use"
echo
read -p "Please enter your dexcom transmitter number, eg: ABCDE: " x
if [ ${#x} != 5 ]
then
echo "Transmitter ID wasn't 5 characters long, this looks wrong - exiting"
exit
fi
echo
echo "Reconfiguring..."
echo
if [ ! -f apps/dexdrip/dexdrip.orig ]
then
echo "Making backup to dexdrip.orig"
cat apps/dexdrip/dexdrip.c >apps/dexdrip/dexdrip.orig
else
echo "Restoring original from dexdrip.orig"
cat apps/dexdrip/dexdrip.orig >apps/dexdrip/dexdrip.c
fi
cat apps/dexdrip/dexdrip.c >apps/dexdrip/dexdrip.tmp
sed <apps/dexdrip/dexdrip.tmp >apps/dexdrip/dexdrip.c -e "s/ = \"ABCDE\";/ = \"${x}\";/g" -e "s/BIT use_gsm = 1;/BIT use_gsm = 0;/g"
echo
echo "Compiling wixel firmware: PLEASE WAIT"
echo
make
if [ -s apps/dexdrip/dexdrip.wxl ]
then
echo
echo "Firmware ready"
read -p "Install to USB attached wixel now? y/n : " y
if [ "$y" = "Y" ] || [ "$y" = "y" ]
then
sudo ../wixel_linux/wixelcmd list
sudo ../wixel_linux/wixelcmd write apps/dexdrip/dexdrip.wxl
echo
read -p "Make python script auto-start on Pi bootup? y/n : " y
if [ "$y" = "Y" ] || [ "$y" = "y" ]
then
if [ "`grep 'wixel python' /etc/rc.local`" = "" ]
then
echo
echo "Setting autostart in rc.local"
if [ ! -f rc.local.backup ]
then
sudo cat /etc/rc.local >rc.local.backup
echo "backup made rc.local.backup in local folder"
echo
fi
sudo grep -v '^exit 0' /etc/rc.local >/tmp/rc.local
sudo echo -e "\n/usr/bin/screen -dmS wixel python \"$pw/python-usb-wixel.py\"\nexit 0" >>/tmp/rc.local
sudo cp /tmp/rc.local /etc/rc.local
sudo chmod a+rx /etc/rc.local
else
echo "Appears to already be enabled in rc.local"
fi
fi
echo
sleep 3
echo "Trying to start process.."
/usr/bin/screen -dmS wixel python "$pw/python-usb-wixel.py"
echo
screen -r wixel
else
echo "Not installing.."
exit
fi
else
echo "Firmware failed to build :("
exit
fi