-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathjnr_setup_remote.sh
95 lines (83 loc) · 2.32 KB
/
jnr_setup_remote.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
#!/bin/bash
# -----------------------------
# BE CAREFUL EDITING THIS FILE:
# this script will be sourced, which means you can set env variables just once.
# Further modifications won't have effect
# -----------------------------
usage () {
echo "Usage"
echo "Standard usage:"
echo " source setup_remote.sh"
echo "Specify alias different from jnr, jlr: "
echo " source setup_local.sh -n <jupyter notebook alias> -l <jupyter lab alias>"
echo
}
# parse arguments
while getopts ":hn:l:" opt; do
case $opt in
n) jnr_alias="$OPTARG"
;;
l) jlr_alias="$OPTARG"
;;
h) usage
return 0
;;
\?) echo "Invalid option -$OPTARG" >&2
return 1
;;
esac
done
# set default aliases if not provided
if [[ -z "$jnr_alias" ]]; then
jnr_alias="jnr"
fi
if [[ -z "$jlr_alias" ]]; then
jlr_alias="jlr"
fi
# check if given alias already exists
if command -v "$jnr_alias" &> /dev/null ; then
echo "command $jnr_alias is already in use"
echo "Please specify another alias for remote jupyter notebook by running"
echo " source setup_local.sh -n <alias>"
return 1
fi
if command -v "$jlr_alias" &> /dev/null ; then
echo "command $jlr_alias is already in use"
echo "Please specify another alias for remote jupyter lab by running"
echo " source setup_local.sh -l <alias>"
return 1
fi
# identify the type of shell
case $SHELL in
*/zsh)
rc_file="$HOME/.zshrc"
;;
*/bash)
rc_file="$HOME/.bashrc"
;;
*)
echo "Fatal: Unable to recognize shell type"
return 1
esac
# make a copy of the original rc file
cp "$rc_file" "$rc_file.pre_jnr"
# create aliases in rc file
echo >> "$rc_file"
echo "# >> RemoteJupyter" >> "$rc_file"
echo "alias $jnr_alias='jupyter notebook --no-browser --port'" >> "$rc_file"
echo "alias $jlr_alias='jupyter lab --no-browser --port'" >> "$rc_file"
echo "# << RemoteJupyter" >> "$rc_file"
echo >> "$rc_file"
# Tell the user how to proceed
echo
echo "RemoteJupyter successfully setup"
echo "Restart the terminal or run"
echo " source $rc_file"
echo "to start using."
echo
echo "To start a remote jupyter notebook, just type"
echo " $jnr_alias <port>"
echo "To start a remote jupyter lab, just type"
echo " $jlr_alias <port>"
echo "Where <port> must be the same you used on the local machine"
return 0