@@ -6,21 +6,39 @@ umask 077
66
77usage () {
88 cat << 'EOF '
9- Usage: cscs-run-tutorial --user USER --account ACCOUNT [OPTIONS]
9+ Usage: cscs-run-tutorial.bash [OPTIONS]
1010
1111Run this script on the workstation with the web browser. It opens one
12- authenticated SSH control connection to Daint, invokes cscs-launch-tutorial
13- there, waits for the services, and then invokes cscs-connect-tutorial locally.
12+ authenticated SSH control connection to Daint, invokes cscs-launch-tutorial.bash
13+ there, waits for the services, and then invokes cscs-connect-tutorial.bash locally.
1414
1515Workstation options:
16- --user USER CSCS username (or set CSCS_USER)
16+ --user USER Override the username read from the SSH certificate
1717 --key PATH CSCS private key (default: ~/.ssh/cscs-key)
1818
19- Other options are passed to cscs-launch-tutorial, including --repo, --branch,
20- --state, --partition, --time, and --start-timeout.
19+ Other options are passed to cscs-launch-tutorial.bash , including --repo, --branch,
20+ --account, -- state, --partition, --time, and --start-timeout.
2121EOF
2222}
2323
24+ discover_cscs_user () {
25+ local certificate=" ${1} -cert.pub"
26+ [ -f " ${certificate} " ] || return 1
27+ local details
28+ details=$( ssh-keygen -L -f " ${certificate} " 2> /dev/null) || return 1
29+ awk '
30+ $1 == "Principals:" { principals = 1; next }
31+ principals && $1 == "Critical" && $2 == "Options:" { exit }
32+ principals {
33+ line = $0
34+ sub(/^[[:space:]]+/, "", line)
35+ sub(/[[:space:]]+$/, "", line)
36+ if (line != "") { count++; value = line }
37+ }
38+ END { if (count == 1) print value; else exit 1 }
39+ ' <<< " ${details}"
40+ }
41+
2442if [ " ${1:- } " = -h ] || [ " ${1:- } " = --help ]; then
2543 usage
2644 exit 0
@@ -48,7 +66,7 @@ bootstrap_workstation_checkout() {
4866 git -C " ${checkout} " pull --ff-only origin " ${branch} "
4967 fi
5068
51- local runner=" ${checkout} /tutorials/pyhpc/brev/cscs-run-tutorial"
69+ local runner=" ${checkout} /tutorials/pyhpc/brev/cscs-run-tutorial.bash "
5270 if [ ! -x " ${runner} " ]; then
5371 echo " Error: ${checkout} does not contain the ${branch} web helper." >&2
5472 exit 1
@@ -65,8 +83,8 @@ if [ -z "${BASH_SOURCE[0]:-}" ]; then
6583fi
6684
6785script_dir=$( cd " $( dirname " ${BASH_SOURCE[0]} " ) " ; pwd -P)
68- launch_script=" ${script_dir} /cscs-launch-tutorial"
69- connect_script=" ${script_dir} /cscs-connect-tutorial"
86+ launch_script=" ${script_dir} /cscs-launch-tutorial.bash "
87+ connect_script=" ${script_dir} /cscs-connect-tutorial.bash "
7088for script in " ${launch_script} " " ${connect_script} " ; do
7189 if [ ! -x " ${script} " ]; then
7290 echo " Error: missing executable sibling script: ${script} " >&2
@@ -86,9 +104,6 @@ while [ "$#" -gt 0 ]; do
86104 * ) launch_args+=(" $1 " ); shift ;;
87105 esac
88106done
89- case " ${user} " in
90- ' ' |-* |* [!A-Za-z0-9._-]* ) echo " Error: provide --user or set CSCS_USER." >&2 ; exit 2 ;;
91- esac
92107for host in " ${ela_host} " " ${daint_host} " ; do
93108 case " ${host} " in
94109 ' ' |-* |* [!A-Za-z0-9._-]* ) echo " Error: invalid CSCS hostname: ${host} " >&2 ; exit 2 ;;
@@ -101,6 +116,16 @@ if [ ! -f "${ssh_key}" ]; then
101116 echo " Error: CSCS private key not found: ${ssh_key} " >&2
102117 exit 2
103118fi
119+ if [ -z " ${user} " ]; then
120+ user=$( discover_cscs_user " ${ssh_key} " || true)
121+ fi
122+ case " ${user} " in
123+ ' ' |-* |* [!A-Za-z0-9._-]* )
124+ echo " Error: could not read one CSCS username from ${ssh_key} -cert.pub." >&2
125+ echo " Run 'cscs-key sign --file ${ssh_key} ' or use --user." >&2
126+ exit 2
127+ ;;
128+ esac
104129
105130control_dir=$( mktemp -d " ${TMPDIR:-/ tmp} /ach-cscs-ssh.XXXXXX" )
106131control_path=" ${control_dir} /master"
@@ -163,10 +188,10 @@ if ! open_master; then
163188 fi
164189fi
165190
166- upload_command=" umask 077; mkdir -p \"\$ HOME/.local/share/accelerated-computing-hub\" ; cat > \"\$ HOME/.local/share/accelerated-computing-hub/cscs-launch-tutorial\" ; chmod 700 \"\$ HOME/.local/share/accelerated-computing-hub/cscs-launch-tutorial\" "
191+ upload_command=" umask 077; mkdir -p \"\$ HOME/.local/share/accelerated-computing-hub\" ; cat > \"\$ HOME/.local/share/accelerated-computing-hub/cscs-launch-tutorial.bash \" ; chmod 700 \"\$ HOME/.local/share/accelerated-computing-hub/cscs-launch-tutorial.bash \" "
167192ssh -F " ${ssh_config} " -S " ${control_path} " ach-daint " ${upload_command} " < " ${launch_script} "
168193
169- remote_command=" \"\$ HOME/.local/share/accelerated-computing-hub/cscs-launch-tutorial\" "
194+ remote_command=" \"\$ HOME/.local/share/accelerated-computing-hub/cscs-launch-tutorial.bash \" "
170195for arg in " ${launch_args[@]} " ; do
171196 printf -v quoted_arg ' %q' " ${arg} "
172197 remote_command+=" ${quoted_arg} "
0 commit comments