From a938137035b73105d09347a91f9fd5e9722b617a Mon Sep 17 00:00:00 2001 From: Paxton Hare Date: Sat, 5 Nov 2022 19:50:30 -0400 Subject: [PATCH] Fixes #24. Adding an example of running a remote script. --- README.md | 7 +++ demo-magic.sh | 1 - samples/remote-exec/README.md | 39 +++++++++++++ samples/remote-exec/docker-compose.yml | 19 +++++++ samples/remote-exec/remote-demo.sh | 45 +++++++++++++++ samples/remote-exec/server-side.sh | 79 ++++++++++++++++++++++++++ 6 files changed, 189 insertions(+), 1 deletion(-) create mode 100644 samples/remote-exec/README.md create mode 100644 samples/remote-exec/docker-compose.yml create mode 100755 samples/remote-exec/remote-demo.sh create mode 100644 samples/remote-exec/server-side.sh diff --git a/README.md b/README.md index 05d0ec0..32e9f34 100644 --- a/README.md +++ b/README.md @@ -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 diff --git a/demo-magic.sh b/demo-magic.sh index 77ab4b2..9120cab 100644 --- a/demo-magic.sh +++ b/demo-magic.sh @@ -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. diff --git a/samples/remote-exec/README.md b/samples/remote-exec/README.md new file mode 100644 index 0000000..f8b48b0 --- /dev/null +++ b/samples/remote-exec/README.md @@ -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` diff --git a/samples/remote-exec/docker-compose.yml b/samples/remote-exec/docker-compose.yml new file mode 100644 index 0000000..6dcde87 --- /dev/null +++ b/samples/remote-exec/docker-compose.yml @@ -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 diff --git a/samples/remote-exec/remote-demo.sh b/samples/remote-exec/remote-demo.sh new file mode 100755 index 0000000..d6500b3 --- /dev/null +++ b/samples/remote-exec/remote-demo.sh @@ -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 diff --git a/samples/remote-exec/server-side.sh b/samples/remote-exec/server-side.sh new file mode 100644 index 0000000..7e578ba --- /dev/null +++ b/samples/remote-exec/server-side.sh @@ -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 ""