forked from daverobertson63/RoboticsChallenge
-
Notifications
You must be signed in to change notification settings - Fork 2
/
brc.sh
executable file
·136 lines (110 loc) · 3.61 KB
/
brc.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
#!/bin/bash
# Updated to v2 for new (slimmed down) repository
# This is the main start download script for the Barclays Robotics Challenge build
# Can be used on any Ubuntu based build - with Arduino and Processing already installed
# Processing must be configured to use sketchbook and Arduino to use sketches in /home/roboteer or
# the user thats been used to run the config
#
MASTER_LOCATION="https://github.com/simonwilmot/RoboticsChallenge.git"
confirmLocal () {
# call with a prompt string or use a default
if [ -z `which zenity` ]; then
# zenity is not installed - fall back to text mode
read -r -p "${1:-Are you sure? [y/N]} " response
case $response in
[lL])
true
;;
*)
false
;;
esac
else
# Prompt graphically
response=`zenity --list --title "${1:-Local or Remote Refresh}" \
--column="Type" --column="Description" \
local "Does not need Internet connectivity" \
remote "Pulls from online repository" \
2>/dev/null `
case $response in
local)
true
;;
remote)
false
;;
*)
notify-send "Unknown response: '$response': exiting."
exit -1
;;
esac
fi
}
(set -o igncr) 2>/dev/null && set -o igncr; # this comment is needed
# Make sure we are in the home directory of the robot user, before we start
cd ~
case $1 in
local)
localRefresh=true
;;
remote)
localRefresh=false
;;
*)
if confirmLocal "Local or Remote refresh ?" ; then
localRefresh=true
else
localRefresh=false
fi
;;
esac
if [ $localRefresh == false ]; then
echo "You must be connected to the Internet to refresh the sketches folder"
echo "Checking to see if you are...."
command -v git >/dev/null 2>&1 || { sudo apt-get -y install git; }
echo "Platform type: " $(uname)
if [ "$(uname)" == "Darwin" ]; then
echo "Mac"
elif [ "$(expr substr $(uname -s) 1 5)" == "Linux" ]; then
ping_cmd='ping -q -c'
#echo "Linux"
elif [ "$(expr substr $(uname -s) 1 13)" == "CYGWIN_NT-6.2" ]; then
ping_cmd="$SYSTEMROOT/system32/ping -n"
#echo "Cygwin"
else
ping_cmd="$SYSTEMROOT/system32/ping -n"
fi
net_check_target="github.com"
connected=`$ping_cmd 1 $net_check_target &> /dev/null && echo 1 || echo 0`
if [ $connected == 0 ]; then
echo "Not connected, cannot refresh"
exit -1
else
echo "Yes, you are connected. Refreshing..."
fi
# Remove all old files; do a brand new clone and deal with it
rm -rf RoboticsChallenge
git clone $MASTER_LOCATION
else
echo "This will be a local refresh - all sketches will be deleted"
cd ~/RoboticsChallenge
# Remove all files (apart from perhaps .git, and anything similar that
# someone has been clever enough to create!)
rm -rf *
# Reset to latest GIT
git reset --hard
fi
# Empty the trash, if there are any files here
rm -rf ~/.local/share/Trash/*
# Reset Arduino Preferences
cp -p ~/RoboticsChallenge/preferences.txt ~/.arduino15/
# Copy the latest script down to replace this one running
# (Could symlink it, but the symlink's icon is not aesthetically pleasing :) )
cp -p ~/RoboticsChallenge/BRC\ Refresh.desktop ~/Desktop
# Replace the previous version of brc.sh
# (The desktop shortcut points at a copy *outside* the git directory, in case
# there is an issue refreshing from remote, and we lose the local copy and then
# can't run it again)
cp -p ~/RoboticsChallenge/brc.sh ~
#notify-send "Robot Refresh" "Completed refresh"
zenity --info --text="Refresh completed"