-
Notifications
You must be signed in to change notification settings - Fork 20
/
Setting.sh
93 lines (87 loc) · 2.36 KB
/
Setting.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
#!/bin/bash
# Program:
# This program will setting environment variable for ros namespace.
# History:
# 2019/3/19 NEET First Edit
# 2019/5/10 NEET Add Camera serial setting
# 2019/7/3 NEET Add Robot number setting
SCRIPT_PATH=`cd "$( dirname ${BASH_SOURCE[0]})" && pwd`
if [ "${BASH_SOURCE[0]}" -ef "$0" ]
then
echo "Hey, you should source this script, not execute it!"
exit 1
fi
function Check() {
if grep -q "source $SCRIPT_PATH/.robot_setting" "$HOME/.bashrc";
then
echo "OK"
else
echo "source $SCRIPT_PATH/.robot_setting >> ~/.bashrc"
echo "source $SCRIPT_PATH/.robot_setting" >> ~/.bashrc
fi
}
function Change() {
echo $1
if [ $1 == "CHANGE_ROBOT_NUMBER" ]
then
echo "Select the NUMBER below: "
select ns in "/robot1" "/robot2" "/robot3" "other"; do
case $ns in
/robot1) export ROBOT_NS=$ns;export ROBOT_NUM=1;break;;
/robot2) export ROBOT_NS=$ns;export ROBOT_NUM=2;break;;
/robot3) export ROBOT_NS=$ns;export ROBOT_NUM=3;break;;
other) read -p "Enter the NAMESPACE below:" ns
export ROBOT_NS=$ns;export ROBOT_NUM=${ns: -1};break;;
esac
done
echo "\$ROBOT_NS was already setting by '$ROBOT_NS', and NUMBER is '$ROBOT_NUM'"
Check
elif [ $1 == "CHANGE_CAMERA_SERIAL" ]
then
read -p "Enter the Serial Number: " sn
export CAMERA_SERIAL=$sn
echo "\$CAMERA_SERIAL was already setting by '$CAMERA_SERIAL'"
Check
fi
echo -e "export ROBOT_NS=$ROBOT_NS\nexport CAMERA_SERIAL=$CAMERA_SERIAL" > $SCRIPT_PATH/.robot_setting
}
if [ -z "$ROBOT_NS" ]
then
echo "\$ROBOT_NS is empty."
Change "CHANGE_ROBOT_NUMBER"
else
echo "\$ROBOT_NS is '$ROBOT_NS' now."
read -t 10 -p "Do you want to change? (y/n)" response
case $response in
[yY][eE][sS] | [yY])
Change "CHANGE_ROBOT_NUMBER"
;;
[nN][oO] | [nN])
Check
echo "See you, bye."
;;
*)
echo "Error. Please try again."
exit 1
esac
fi
if [ -z "$CAMERA_SERIAL" ]
then
echo "\$CAMERA_SERIAL is empty."
Change "CHANGE_CAMERA_SERIAL"
else
echo "\$CAMERA_SERIAL is '$CAMERA_SERIAL' now."
read -t 10 -p "Do you want to change? (y/n)" response
case $response in
[yY][eE][sS] | [yY])
Change "CHANGE_CAMERA_SERIAL"
;;
[nN][oO] | [nN])
Check
echo "See you, bye."
;;
*)
echo "Error. Please try again."
exit 1
esac
fi