forked from Adlink-ROS/ros_menu
-
Notifications
You must be signed in to change notification settings - Fork 0
/
ros_bashrc
131 lines (118 loc) · 3.99 KB
/
ros_bashrc
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
# # # # # # # # # # # # # # # # # # # # #
# Start of Neuron Startup Menu Settings #
# # # # # # # # # # # # # # # # # # # # #
# clear ROS env var for resolving warning #
unset ros_option
unset ROS_DISTRO
unset ROS_HOSTNAME
shell=`echo $SHELL | awk -F '/' '{print $NF}'`
ros_menu_path="${HOME}/.ros_menu"
plugins_path="${ros_menu_path}/plugins_bashrc"
function source_plugin()
{
plugin=$1
if [[ "$plugin" != /* ]]; then
plugin="$plugins_path/$plugin"
fi
if [ -f $(echo $plugin | cut -d' ' -f 1) ]; then
echo "source $plugin ${@:2}"
eval "source $plugin ${@:2}"
else
echo "Error! No such file: $plugin"
fi
}
function ros_menu_version()
{
menu_tag=`git -C ${ros_menu_path} tag -l --contains HEAD`
menu_commit=`git -C ${ros_menu_path} rev-parse HEAD`
echo "$menu_tag $menu_commit"
}
function ros_menu_upgrade()
{
echo -n "Current version: "
ros_menu_version
git -C ${ros_menu_path} fetch > /dev/null
git -C ${ros_menu_path} checkout $1 > /dev/null
echo -n "Updated version: "
ros_menu_version
}
function ros_menu_uninstall()
{
echo -n "Do you want to remove Neuron Startup Menu? (y/N): "
read remove_menu
if [ "$remove_menu" '==' "y" ] || [ "$remove_menu" '==' "Y" ];
then
rm -rf ~/ros_menu ~/.ros_menu
fi
}
function ros_menu_env()
{
if [[ $ROS_VERSION == "1" ]]; then
echo "* ROS_DISTRO=$ROS_DISTRO"
echo "* ROS_IP=$ROS_IP"
echo "* ROS_MASTER_URI=$ROS_MASTER_URI"
else
echo "* ROS_DISTRO=$ROS_DISTRO"
echo "* ROS_DOMAIN_ID=$ROS_DOMAIN_ID"
echo "* RMW_IMPLEMENTATION=$RMW_IMPLEMENTATION"
echo "* CYCLONEDDS_URI=$CYCLONEDDS_URI"
echo "* Workspace Layer:"
echo " - $AMENT_PREFIX_PATH" | sed 's/:/\n - /g'
fi
}
function ros_menu_disable()
{
sed -i '/menu_enable/s/true/false/g' ~/ros_menu/config.yaml
echo "To enable ros_menu please use ro_menu_enable"
}
function ros_menu_enable()
{
sed -i '/menu_enable/s/false/true/g' ~/ros_menu/config.yaml
}
function ros_menu_clean_docker()
{
if [ ! -f ./dockerenv ]; then
container_id=$(docker ps --filter="name=rosmenu*" -q)
if [[ $container_id ]]; then
echo "Remove the rosmenu container..."
docker rm -f $container_id
fi
image_id=$(docker images --filter=reference="adlinkrmt/rosmenu*" -q)
if [[ $image_id ]]; then
echo "Remove the rosmenu image..."
docker rmi $image_id
fi
echo "The rosmenu container and image have already been removed successfully."
else
echo "The command is only available in host, not in container."
fi
}
function ros_menu_help()
{
echo -e "To load ROS env to be automatically, please assign ros_option in ros_menu/config.yaml"
echo "Usage: (Run the following function in the command line.)"
echo -e "\tros_menu_help -> usage details"
echo -e "\tros_menu_version -> show the version of ros_menu you are using"
echo -e "\tros_menu_upgrade [version] -> upgrade the ros_menu"
echo -e "\tros_menu_uninstall -> uninstall the ros_menu"
echo -e "\tros_menu_env -> show the environment details of ROS"
echo -e "\tros_menu_disable -> disable the ros_menu"
echo -e "\tros_menu_enable -> enable the ros_menu"
echo -e "\tros_menu_clean_docker -> remove image and container"
echo "For more using details please refer to file ros_menu/README.md."
}
if [ ! -f /.dockerenv ]; then
rm -rf /tmp/host_sourcefile.txt
python3 ~/ros_menu/ros_menu.py ~/ros_menu/config.yaml
if [ -f /tmp/host_sourcefile.txt ]; then
source /tmp/host_sourcefile.txt
fi
else
# Each docker container should has the following file
if [ -f /container_sourcefile_$ROS_OPTION.txt ]; then
source /container_sourcefile_$ROS_OPTION.txt
fi
fi
# # # # # # # # # # # # # # # # # # # #
# END of Neuron Startup Menu Settings #
# # # # # # # # # # # # # # # # # # # #