Skip to content

Commit

Permalink
Fixes #24. Adding an example of running a remote script.
Browse files Browse the repository at this point in the history
  • Loading branch information
paxtonhare committed Nov 5, 2022
1 parent 3c81ee0 commit a938137
Show file tree
Hide file tree
Showing 6 changed files with 189 additions and 1 deletion.
7 changes: 7 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,13 @@ clear

Then use the handy functions to run through your demo.

## Handy Starting Points
There are a few samples in the `samples/` folder to show you how easy it is to get up and running.

The `demo-template.sh` is a bit of a showcase of some of the features.

The `remote-exec` folder is there to show you how to run demo-magic locally and on a remote server via ssh. This was created in response to [Issue #24](https://github.com/paxtonhare/demo-magic/issues/24)

## Command line usage
demo-magic.sh exposes some options to your script.
- `-d` - disable simulated typing. Useful for debugging
Expand Down
1 change: 0 additions & 1 deletion demo-magic.sh
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,6 @@ while getopts ":dhncw:" opt; do
esac
done

echo "type speed: $TYPE_SPEED"
##
# Do not check for pv. This trusts the user to not set TYPE_SPEED later in the
# demo in which case an error will occur if pv is not installed.
Expand Down
39 changes: 39 additions & 0 deletions samples/remote-exec/README.md
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`
19 changes: 19 additions & 0 deletions samples/remote-exec/docker-compose.yml
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
45 changes: 45 additions & 0 deletions samples/remote-exec/remote-demo.sh
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
79 changes: 79 additions & 0 deletions samples/remote-exec/server-side.sh
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 ""

0 comments on commit a938137

Please sign in to comment.