-
Notifications
You must be signed in to change notification settings - Fork 217
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fixes #24. Adding an example of running a remote script.
- Loading branch information
1 parent
3c81ee0
commit a938137
Showing
6 changed files
with
189 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
# Continuing your demo on a remote server | ||
|
||
If you need to demo ssh'ing into another computer and continuing the demo there, this script is for you. | ||
|
||
It works by copying the necessary files to the remote server and running them via ssh. | ||
|
||
## A note about simulated typing | ||
Note that this script disables simulated typing by passing the `-d` option to demo-magic.sh. If you want simulated typing you need to install the [pv utitity](https://www.ivarch.com/programs/pv.shtml) on both your local and remote machines. Once pv is installed remember to remove the `-d` option to enable simulated typing. | ||
|
||
## Running the SSH Server | ||
In order for this to work you'll need a server to ssh into with ssh keys (not username/password). | ||
|
||
### Handy Dandy Docker ssh server (optional) | ||
This example conveniently includes a docker-compose for running an ssh server. If you use your own server don't forget to change the hostname in the ssh command. | ||
|
||
To run the docker-compose demo, you need to do a few things. | ||
|
||
1. Create a ./keys dir | ||
1. Put your public ssh key into the ./keys/ directory | ||
1. Replace `REPLACE_WITH_YOUR_KEY_FILE` with the actual file name in ./keys/ | ||
1. Replace `REPLACE_WITH_YOUR_USERNAME` with the username associated with the public key | ||
|
||
Alternatively you can just go RTFM over at the [Docker Hub page for the ssh-server](https://hub.docker.com/r/linuxserver/openssh-server) | ||
|
||
Now run: | ||
|
||
`docker-compose up -d` | ||
|
||
The docker ssh server is running on port 2222 by default. | ||
|
||
After launching the ssh server, verify that you can actually log into it: | ||
|
||
`ssh -p 2222 localhost` | ||
|
||
## Running the demo | ||
|
||
Once that works then you can run the demo. | ||
|
||
`./remote-demo.sh` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
--- | ||
version: "2.1" | ||
services: | ||
openssh-server: | ||
image: lscr.io/linuxserver/openssh-server:latest | ||
container_name: openssh-server | ||
hostname: openssh-server #optional | ||
environment: | ||
- PUID=1000 | ||
- PGID=1000 | ||
- TZ=Europe/London | ||
- PUBLIC_KEY_FILE=/keys/REPLACE_WITH_YOUR_KEY_FILE | ||
- USER_NAME=REPLACE_WITH_YOUR_USERNAME | ||
volumes: | ||
- ./keys:/keys | ||
- ./config:/config | ||
ports: | ||
- 2222:2222 | ||
restart: unless-stopped |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
#!/usr/bin/env bash | ||
|
||
################################# | ||
# include the -=magic=- | ||
# you can pass command line args | ||
# | ||
# example: | ||
# to disable simulated typing | ||
# . ../demo-magic.sh -d | ||
# | ||
# pass -h to see all options | ||
################################# | ||
|
||
# note that -d is passed to disable simulated typing | ||
# install pv https://www.ivarch.com/programs/pv.shtml onto your local machine | ||
# if you want simulated typing | ||
. ../../demo-magic.sh -d | ||
|
||
|
||
######################## | ||
# Configure the options | ||
######################## | ||
|
||
# | ||
# speed at which to simulate typing. bigger num = faster | ||
# | ||
# TYPE_SPEED=20 | ||
|
||
# | ||
# custom prompt | ||
# | ||
# see http://www.tldp.org/HOWTO/Bash-Prompt-HOWTO/bash-prompt-escape-sequences.html for escape sequences | ||
# | ||
DEMO_PROMPT="${GREEN}➜ ${CYAN}\W ${COLOR_RESET}" | ||
|
||
# text color | ||
# DEMO_CMD_COLOR=$BLACK | ||
|
||
# hide the evidence | ||
clear | ||
|
||
scp -P 2222 ../demo-magic.sh localhost:/config/demo-magic.sh > /dev/null 2>&1 | ||
scp -P 2222 ./server-side.sh localhost:/config/server-side.sh > /dev/null 2>&1 | ||
p "ssh localhost" | ||
ssh -t -p 2222 localhost ./server-side.sh |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
#!/usr/bin/env bash | ||
|
||
################################# | ||
# include the -=magic=- | ||
# you can pass command line args | ||
# | ||
# example: | ||
# to disable simulated typing | ||
# . ../demo-magic.sh -d | ||
# | ||
# pass -h to see all options | ||
################################# | ||
|
||
# note that -d is passed to disable simulated typing | ||
# install pv https://www.ivarch.com/programs/pv.shtml onto your remote server | ||
# if you want simulated typing | ||
. ./demo-magic.sh -d | ||
|
||
|
||
######################## | ||
# Configure the options | ||
######################## | ||
|
||
# | ||
# speed at which to simulate typing. bigger num = faster | ||
# | ||
# TYPE_SPEED=20 | ||
|
||
# | ||
# custom prompt | ||
# | ||
# see http://www.tldp.org/HOWTO/Bash-Prompt-HOWTO/bash-prompt-escape-sequences.html for escape sequences | ||
# | ||
DEMO_PROMPT="${GREEN}(my fancy server)➜ ${CYAN}\W ${COLOR_RESET}" | ||
|
||
# text color | ||
# DEMO_CMD_COLOR=$BLACK | ||
|
||
# hide the evidence | ||
clear | ||
|
||
# put your demo awesomeness here | ||
if [ ! -d "stuff" ]; then | ||
pe "mkdir stuff" | ||
fi | ||
|
||
# print and execute: cd stuff | ||
pe "cd stuff" | ||
|
||
# ctl + c support: ctl + c to stop long-running process and continue demo | ||
pe "ping www.google.com" | ||
|
||
# print and execute: echo 'hello world' > file.txt | ||
pe "echo 'hello world' > file.txt" | ||
|
||
# wait max 3 seconds until user presses | ||
PROMPT_TIMEOUT=3 | ||
wait | ||
|
||
# print and execute immediately: ls -l | ||
pei "ls -l" | ||
# print and execute immediately: cat file.txt | ||
pei "cat file.txt" | ||
|
||
# and reset it to manual mode to wait until user presses enter | ||
PROMPT_TIMEOUT=0 | ||
|
||
# print only | ||
p "cat \"something you want to pretend to run\"" | ||
|
||
# run command behind | ||
cd .. && rm -rf stuff | ||
|
||
# enters interactive mode and allows newly typed command to be executed | ||
cmd | ||
|
||
# show a prompt so as not to reveal our true nature after | ||
# the demo has concluded | ||
p "" |