Skip to content

Latest commit

 

History

History
102 lines (80 loc) · 3.81 KB

README.md

File metadata and controls

102 lines (80 loc) · 3.81 KB

patterns-shell/templates

patterns-shell/templates - Code generators for shell patterns

These scripts output function definitions. These may be output to a file and sourced in your .*rc, or directly sourced with process substitution:

source <(example.sh arg1 arg2 ... argn)

Some of these scripts define template-* functions that generate the function definitions. These functions take arguments and generate shell scripts based off templates. You can save this output, analyze it, and source it, or you can source it directly with process substitution:

source <(template-* arg1 arg2 ... argn)

All generated functions are self documenting. You can view this documentation with

funcname -h

deploy

template-deploy-client

Usage: template-deploy-client [server] [FUNCNAME] [REMOTEFUNC]
Output code for two functions named [FUNCNAME] (default deploy) and [FUNCNAME]-full
to find the name of a makefile project (via make name) and
create a tarball of the project (via make tar) and copy to [server]
(via [server]-push) and then call [REMOTEFUNC] (default [FUNCNAME])
or [REMOTEFUNC]-full for [FUNCNAME]-full.
NOTE: The server should be one defined by template-remote

template-deploy-server

Usage: template-deploy-server [stagedir] [livedir] [scpdir] [FUNCNAME]
Output code for two functions named [FUNCNAME] (default deploy)
and [FUNCNAME]-full.
[FUNCNAME] deploys a program tarball located in [scpdir] (default ~/scp)
to [stagedir], overwriting any previous deployment. It then builds
and links a stable name to deployed program.
[FUNCNAME]-full calls [FUNCNAME], then copies the deployment from
[stagedir] to [livedir].

pgdb

Generates functions to connect to a PostgreSQL database.

Source the output of pgdb.sh in your .*rc file, passing the following arguments.

  • $1 database
  • $2 user
  • [$3] function name; default [database]

Usage: pgdb.sh database user [funcname]

This template generates the following function

  • dbfuncname [OPTION] [queryfile]
    If a file is given as an argument, execute the queries in the file,
    otherwise start a psql session connected to database.
    • -h show help

pgdb-backup

Generates functions to backup a PostgreSQL database.

Source the output of pgdb.sh in your .*rc file, passing the following arguments.

  • $1 database name
  • $2 database superuser
  • $3 backup directory (absolute path, no trailing slash)
  • [$4] generated function name (default ${1}backup)

Usage: pgdb-backup name superuser backupdir [funcname]

This template generates one function

  • dbbackupfunc [OPTION] [file]
    Backup or restore $MYDB.
    If no arguments given, make dated backup in $3
    otherwise, execute according the options below.
    • -b backup database to file
    • -r restore datase from file

remote

Generates functions to connect to a server via SSH, manage key generation and setup, setup a SOCKS proxy using the connection, and transfer files via SCP.

Source the output of remote.sh in your .*rc file, passing the following arguments.

  • $1 connection name
  • $2 [user@]hostname

Usage: remote.sh name [user@]hostname

There are four functions generated by this template

  • [connection] [SSH_OPTION] [COMMAND]
    If COMMAND given, execute it remotely, otherwise start an SSH session
  • [connection]-keygen
    Check/setup public/private key authentication for this connection
  • [connection]-proxy [PORT]
    Start a SOCKS proxy using this connection on localhost:PORT (default 9999)
  • [connection]-scp [SCP_OPTION] FILES... DESTINATION Transfer FILES to DESTINATION via SCP; includes remote file tab completion

sourcedir

template-sourcedir

Usage: template-sourcedir dir
Generate statements to source all files in a directory

  • $1 directory to source