@@ -20,23 +20,27 @@ init_global_variables() {
2020
2121 CHE_LAUNCHER_CONTAINER_NAME=" che-launcher"
2222 CHE_LAUNCHER_IMAGE_NAME=" codenvy/che-launcher"
23+ CHE_SERVER_IMAGE_NAME=" codenvy/che-server"
24+
25+ CHE_MOUNT_FOLDER=${CHE_MOUNT_FOLDER: +$(get_clean_path ${CHE_MOUNT_FOLDER} )}
2326
2427 # User configurable variables
25- DEFAULT_CHE_VERSION=" nightly "
28+ DEFAULT_CHE_VERSION=" latest "
2629 DEFAULT_CHE_CLI_ACTION=" help"
2730
2831 CHE_VERSION=${CHE_VERSION:- ${DEFAULT_CHE_VERSION} }
2932 CHE_CLI_ACTION=${CHE_CLI_ACTION:- ${DEFAULT_CHE_CLI_ACTION} }
3033
3134 USAGE="
3235Usage: che [COMMAND]
33- start Starts Che server
34- stop Stops Che server
35- restart Restart Che server
36- update Pull latest version of ${CHE_LAUNCHER_IMAGE_NAME}
37- info Print some debugging information
38- init Initialize directory with Che configuration
39- up Create workspace from source in current directory
36+ start Starts Che server
37+ stop Stops Che server
38+ restart Restart Che server
39+ update Pull latest version of ${CHE_LAUNCHER_IMAGE_NAME}
40+ info Print some debugging information
41+ mount <local-path> <ws-ssh-port> Synchronize workspace to a local directory
42+ init Initialize directory with Che configuration
43+ up Create workspace from source in current directory
4044"
4145}
4246
@@ -65,6 +69,34 @@ error_exit() {
6569 exit 1
6670}
6771
72+ get_full_path () {
73+ echo $( realpath $1 )
74+ }
75+
76+ convert_windows_to_posix () {
77+ echo " /" $( echo " $1 " | sed ' s/\\/\//g' | sed ' s/://' )
78+ }
79+
80+ get_clean_path () {
81+ INPUT_PATH=$1
82+ # \some\path => /some/path
83+ OUTPUT_PATH=$( echo ${INPUT_PATH} | tr ' \\' ' /' )
84+ # /somepath/ => /somepath
85+ OUTPUT_PATH=${OUTPUT_PATH%/ }
86+ # /some//path => /some/path
87+ OUTPUT_PATH=$( echo ${OUTPUT_PATH} | tr -s ' /' )
88+ # "/some/path" => /some/path
89+ OUTPUT_PATH=${OUTPUT_PATH// \" }
90+ echo ${OUTPUT_PATH}
91+ }
92+
93+ get_mount_path () {
94+ FULL_PATH=$( get_full_path $1 )
95+ POSIX_PATH=$( convert_windows_to_posix $FULL_PATH )
96+ echo $( get_clean_path $POSIX_PATH )
97+ }
98+
99+
68100docker-exec () {
69101 if is_boot2docker || is_docker_for_windows; then
70102 MSYS_NO_PATHCONV=1 docker.exe " $@ "
@@ -82,17 +114,19 @@ check_docker() {
82114}
83115
84116parse_command_line () {
85- for command_line_option in " $@ " ; do
86- case ${command_line_option} in
87- start|stop|restart|update|info|init|up|help|-h|--help)
88- CHE_CLI_ACTION=${command_line_option}
117+ if [ $# -eq 0 ]; then
118+ CHE_CLI_ACTION=" help"
119+ else
120+ case $1 in
121+ start|stop|restart|update|info|init|up|mount|help|-h|--help)
122+ CHE_CLI_ACTION=$1
89123 ;;
90124 * )
91125 # unknown option
92126 error_exit " You passed an unknown command line option."
93127 ;;
94128 esac
95- done
129+ fi
96130}
97131
98132is_boot2docker () {
@@ -169,15 +203,23 @@ get_list_of_variables() {
169203 VALUE=' -e ' ${SINGLE_VARIABLE} ' '
170204 RETURN=" ${RETURN} " " ${VALUE} "
171205 done
172- echo " ${ RETURN} "
206+ echo $ RETURN
173207}
174208
175209execute_che_launcher () {
176- update_che_launcher
210+
211+ CURRENT_IMAGE=$( docker images -q " ${CHE_LAUNCHER_IMAGE_NAME} " :" ${CHE_VERSION} " )
212+
213+ if [ " ${CURRENT_IMAGE} " != " " ]; then
214+ info " ECLIPSE CHE: FOUND IMAGE ${CHE_LAUNCHER_IMAGE_NAME} :${CHE_VERSION} "
215+ else
216+ update_che_image ${CHE_LAUNCHER_IMAGE_NAME}
217+ fi
218+
177219 info " ECLIPSE CHE: LAUNCHING LAUNCHER"
178220 docker-exec run -t --name " ${CHE_LAUNCHER_CONTAINER_NAME} " \
179221 -v /var/run/docker.sock:/var/run/docker.sock \
180- $( get_list_of_variables) \
222+ -e $( get_list_of_variables) \
181223 " ${CHE_LAUNCHER_IMAGE_NAME} " :" ${CHE_VERSION} " " ${CHE_CLI_ACTION} " \
182224 # > /dev/null 2>&1
183225}
@@ -223,20 +265,39 @@ execute_command_with_progress() {
223265 printf " \n"
224266}
225267
226- update_che_launcher () {
268+ update_che_image () {
227269 if [ -z " ${CHE_VERSION} " ]; then
228270 CHE_VERSION=${DEFAULT_CHE_VERSION}
229271 fi
230272
231- CURRENT_IMAGE=$( docker images -q ${CHE_LAUNCHER_IMAGE_NAME} :${CHE_VERSION} )
273+ info " ECLIPSE CHE: PULLING IMAGE $1 :${CHE_VERSION} "
274+ execute_command_with_progress extended docker pull $1 :${CHE_VERSION}
275+ info " ECLIPSE CHE: IMAGE $1 :${CHE_VERSION} INSTALLED"
276+ }
232277
233- if [ " ${CURRENT_IMAGE} " != " " ]; then
234- info " ECLIPSE CHE: ALREADY HAVE IMAGE ${CHE_LAUNCHER_IMAGE_NAME} :${CHE_VERSION} "
235- else
236- info " ECLIPSE CHE: PULLING IMAGE ${CHE_LAUNCHER_IMAGE_NAME} :${CHE_VERSION} "
237- execute_command_with_progress extended docker pull ${CHE_LAUNCHER_IMAGE_NAME} :${CHE_VERSION}
238- info " ECLIPSE CHE: IMAGE ${CHE_LAUNCHER_IMAGE_NAME} :${CHE_VERSION} INSTALLED"
278+ mount_local_directory () {
279+ if [ ! $# -eq 3 ]; then
280+ error " che mount: Wrong number of arguments provided."
281+ return
239282 fi
283+
284+ MOUNT_PATH=$( get_mount_path $2 )
285+
286+ if [ ! -e " ${MOUNT_PATH} " ]; then
287+ error " che mount: Path provided does not exist."
288+ return
289+ fi
290+
291+ if [ ! -d " ${MOUNT_PATH} " ]; then
292+ error " che mount: Path provided is not a valid directory."
293+ return
294+ fi
295+
296+ docker-exec run --rm -it --cap-add SYS_ADMIN \
297+ --device /dev/fuse \
298+ --name che-mount \
299+ -v " ${MOUNT_PATH} " :/mnthost \
300+ codenvy/che-mount $( get_docker_host_ip) $3
240301}
241302
242303# See: https://sipb.mit.edu/doc/safe-shell/
@@ -256,10 +317,14 @@ case ${CHE_CLI_ACTION} in
256317 execute_che_file
257318 ;;
258319 update)
259- update_che_launcher
320+ update_che_image ${CHE_LAUNCHER_IMAGE_NAME}
321+ update_che_image ${CHE_SERVER_IMAGE_NAME}
322+ ;;
323+ mount)
324+ mount_local_directory " $@ "
260325 ;;
261326 help)
262- get_list_of_variables
327+ # get_list_of_variables
263328 usage
264329 ;;
265330esac
0 commit comments