diff options
author | Martin -nexus- Mlynář | 2015-07-21 23:50:13 +0200 |
---|---|---|
committer | Martin -nexus- Mlynář | 2015-07-22 00:22:26 +0200 |
commit | 71d4153881ea0520d9e5d52806d6fe69975f35c9 (patch) | |
tree | 5e01f5e18b86b551227e834fc0ad1d99b56544f8 | |
download | aur-71d4153881ea0520d9e5d52806d6fe69975f35c9.tar.gz |
initial package
-rw-r--r-- | .SRCINFO | 22 | ||||
-rw-r--r-- | .gitignore | 16 | ||||
-rw-r--r-- | PKGBUILD | 55 | ||||
-rw-r--r-- | dokku.install | 33 | ||||
-rw-r--r-- | pluginhook.go | 93 | ||||
-rw-r--r-- | sshcommand | 67 |
6 files changed, 286 insertions, 0 deletions
diff --git a/.SRCINFO b/.SRCINFO new file mode 100644 index 000000000000..7f9b05e62eb4 --- /dev/null +++ b/.SRCINFO @@ -0,0 +1,22 @@ +pkgbase = dokku + pkgdesc = Docker powered mini-Heroku in around 100 lines of Bash. + pkgver = 0.3.21 + pkgrel = 1 + url = https://github.com/progrium/dokku + install = dokku.install + arch = i686 + arch = x86_64 + license = MIT + makedepends = go + depends = docker + source = git+https://github.com/progrium/dokku.git#tag=v0.3.21 + source = dokku.install + source = pluginhook.go + source = sshcommand + sha256sums = SKIP + sha256sums = d59d82c65583b571b0f9645425a10f7fcb888aedd6aecd0e39d2a3fdb6c1fe8d + sha256sums = a8be92d37d9e99e2f5d0b44aed2451dc590daa7e5366b5cb2ba3197fb0ae65b0 + sha256sums = 610eb140386de622ea46e6144be9f6f0a130887f94005319a395aed081d95879 + +pkgname = dokku + diff --git a/.gitignore b/.gitignore new file mode 100644 index 000000000000..aed68513f742 --- /dev/null +++ b/.gitignore @@ -0,0 +1,16 @@ +*.sw[po] +*.tar +*.tar.* +*.zip +*.tgz +*.log +*.log.* +*.sig + +# AUR metadata +.AURINFO +#.SRCINFO + +pkg/ +src/ +dokku/ diff --git a/PKGBUILD b/PKGBUILD new file mode 100644 index 000000000000..ca58a04f192a --- /dev/null +++ b/PKGBUILD @@ -0,0 +1,55 @@ +# Maintainer: Martin Mlynář <nexus+arch@smoula.net> +pkgname=dokku +pkgver=0.3.21 +pkgrel=1 +pkgdesc="Docker powered mini-Heroku in around 100 lines of Bash." +arch=(i686 x86_64) +url="https://github.com/progrium/dokku" +license=(MIT) +depends=( + 'docker' +) +makedepends=( + 'go' +) + +#https://raw.githubusercontent.com/progrium/pluginhook/master/pluginhook.go +#https://raw.githubusercontent.com/progrium/sshcommand/master/sshcommand +source=( + "git+https://github.com/progrium/dokku.git#tag=v0.3.21" + "${pkgname}.install" + "pluginhook.go" + "sshcommand" +) +sha256sums=( + 'SKIP' + 'd59d82c65583b571b0f9645425a10f7fcb888aedd6aecd0e39d2a3fdb6c1fe8d' + 'a8be92d37d9e99e2f5d0b44aed2451dc590daa7e5366b5cb2ba3197fb0ae65b0' + '610eb140386de622ea46e6144be9f6f0a130887f94005319a395aed081d95879' +) +install=${pkgname}.install + +build() { + cd "${srcdir}/" + export GOPATH="${srcdir}/" + go get "golang.org/x/crypto/ssh/terminal" + GOOS=linux go build -o pluginhook.linux +} + +package() { + cd "${srcdir}/" + + install -Dm755 sshcommand "${pkgdir}"/usr/bin/sshcommand + install -Dm755 pluginhook.linux "${pkgdir}"/usr/bin/pluginhook + + cd "$pkgname" + PLUGINS_PATH="${pkgdir}/var/lib/dokku/plugins/" + install -Dm755 dokku "${pkgdir}/usr/bin/dokku" + mkdir -p ${PLUGINS_PATH} + find plugins/ -mindepth 1 -maxdepth 1 -type d -printf '%f\n' | while read plugin; do \ + rm -Rf ${PLUGINS_PATH}/$plugin && \ + cp -R plugins/$plugin ${PLUGINS_PATH} && \ + touch ${PLUGINS_PATH}/$plugin/.core; \ + done +} + diff --git a/dokku.install b/dokku.install new file mode 100644 index 000000000000..3fa008e9d726 --- /dev/null +++ b/dokku.install @@ -0,0 +1,33 @@ +#!/bin/sh +post_install() { + getent group dokku >/dev/null || + groupadd --system dokku + + getent passwd dokku >/dev/null || + useradd --system \ + --gid dokku \ + --shell /usr/bin/dokku \ + --home-dir /var/dokku/ \ + -m \ + dokku + + chown dokku:dokku /var/dokku/ + mkdir /var/dokku/.ssh/ + chown dokku:dokku /var/dokku/.ssh/ + gpasswd -a dokku docker + + if [ ! -f "/var/dokku/HOSTNAME" ]; then + hostname -f > "/var/dokku/HOSTNAME" + chown dokku:dokku "/var/dokku/HOSTNAME" + fi + + echo " + Please add your ssh pubkey like: + $ cat ~/.ssh/id_rsa.pub | sudo sshcommand acl-add dokku comment +" +} + +pre_remove() { + userdel dokku &>/dev/null || true + groupdel dokku &>/dev/null || true +} diff --git a/pluginhook.go b/pluginhook.go new file mode 100644 index 000000000000..5ee57a0b44f8 --- /dev/null +++ b/pluginhook.go @@ -0,0 +1,93 @@ +package main + +import ( + "os" + "fmt" + "os/exec" + "syscall" + "path/filepath" + "log" + "flag" + "bytes" + "strings" + "golang.org/x/crypto/ssh/terminal" +) + +func main() { + var parallel = flag.Bool("p", false, "Run hooks in parallel") + var trace = flag.Bool("x", false, "Trace mode") + flag.Parse() + + if len(os.Getenv("PLUGINHOOK_TRACE")) > 0 { + *trace = true + } + + pluginPath := os.Getenv("PLUGIN_PATH") + if pluginPath == "" { + log.Fatal("[ERROR] Unable to locate plugins: set $PLUGIN_PATH\n") + os.Exit(1) + } + if flag.NArg() < 1 { + log.Fatal("[ERROR] Hook name argument is required\n") + os.Exit(1) + } + cmds := make([]exec.Cmd, 0) + var matches, _ = filepath.Glob(fmt.Sprintf("%s/*/%s", pluginPath, flag.Arg(0))) + for _, hook := range matches { + cmd := exec.Command(hook, flag.Args()[1:]...) + cmds = append(cmds, *cmd) + } + for i := len(cmds)-1; i >= 0; i-- { + cmds[i].Stderr = os.Stderr + + if i == len(cmds)-1 { + cmds[i].Stdout = os.Stdout + } + if i > 0 { + if *parallel { + stdout, err := cmds[i-1].StdoutPipe() + if err != nil { + log.Fatal(err) + } + cmds[i].Stdin = stdout + } else { + var buf bytes.Buffer + cmds[i-1].Stdout = &buf + cmds[i].Stdin = &buf + } + } + if i == 0 && !terminal.IsTerminal(syscall.Stdin) { + cmds[i].Stdin = os.Stdin + } + } + + if *parallel { + done := make(chan bool, len(cmds)) + + for i := 0; i < len(cmds); i++ { + go func(cmd exec.Cmd, i int) { + if *trace { + fmt.Fprintln(os.Stderr, "+", strings.Join(cmds[i].Args, " ")) + } + err := cmd.Run() + if msg, ok := err.(*exec.ExitError); ok { // there is error code + os.Exit(msg.Sys().(syscall.WaitStatus).ExitStatus()) + } + done <- true + }(cmds[i], i) + } + for i := 0; i < len(cmds); i++ { + <-done + } + } else { + for i := 0; i < len(cmds); i++ { + if *trace { + fmt.Fprintln(os.Stderr, "+", strings.Join(cmds[i].Args, " ")) + } + err := cmds[i].Run() + if msg, ok := err.(*exec.ExitError); ok { // there is error code + os.Exit(msg.Sys().(syscall.WaitStatus).ExitStatus()) + } + } + } +} diff --git a/sshcommand b/sshcommand new file mode 100644 index 000000000000..e106f3a72d6b --- /dev/null +++ b/sshcommand @@ -0,0 +1,67 @@ +#!/bin/bash +set -e + +shopt -s nocasematch #For case insensitive string matching, for the first parameter + +SELF=`which $0` + +case "$1" in + create) # sshcommand create <user> <command> + if [[ $# -ne 3 ]]; then + echo "Usage : sshcommand create user command" + exit -1 + fi + USER="$2"; COMMAND="$3" + + if id -u $USER >/dev/null 2>&1; then + echo "User '$USER' already exists" + else + adduser --disabled-password --gecos "" $USER + fi + + USERHOME=$(sh -c "echo ~$USER") + mkdir -p "$USERHOME/.ssh" + touch $USERHOME/.ssh/authorized_keys + echo "$COMMAND" > "$USERHOME/.sshcommand" + chown -R $USER $USERHOME + ;; + + acl-add) # sshcommand acl-add <user> <identifier> + if [[ $# -ne 3 ]]; then + echo "Usage : sshcommand acl-add user identifier" + exit -1 + fi + USER="$2"; NAME="$3" + + getent passwd $USER > /dev/null || false + USERHOME=$(sh -c "echo ~$USER") + + KEY=$(cat) + FINGERPRINT=$(ssh-keygen -lf /dev/stdin <<< $(echo $KEY) | awk '{print $2}') + KEY_PREFIX="command=\"FINGERPRINT=$FINGERPRINT NAME=$NAME \`cat $USERHOME/.sshcommand\` \$SSH_ORIGINAL_COMMAND\",no-agent-forwarding,no-user-rc,no-X11-forwarding,no-port-forwarding" + echo "$KEY_PREFIX $KEY" >> "$USERHOME/.ssh/authorized_keys" + echo $FINGERPRINT + ;; + + acl-remove) # sshcommand acl-remove <user> <identifier> + if [[ $# -ne 3 ]]; then + echo "Usage : sshcommand acl-remove user identifier" + exit -1 + fi + USER="$2"; NAME="$3" + + getent passwd $USER > /dev/null || false + USERHOME=$(sh -c "echo ~$USER") + + sed --in-place "/ NAME=$NAME /d" "$USERHOME/.ssh/authorized_keys" + ;; + + help|*) # sshcommand help + echo "Usage : sshcommand create user command" + echo " sshcommand acl-add user identifier" + echo " sshcommand acl-remove user identifier" + echo " sshcommand help # shows this usage message" + ;; + +esac + |