From 1cc2dfeff36493c789e278caca0ef7849750c7b6 Mon Sep 17 00:00:00 2001 From: Rocky Madden Date: Wed, 13 Jul 2016 21:47:53 -0600 Subject: [PATCH] Add barebones install and config via env variable --- .gitignore | 1 + Makefile | 8 ++++---- src/slack | 19 ++++++++++++++----- 3 files changed, 19 insertions(+), 9 deletions(-) diff --git a/.gitignore b/.gitignore index 796b96d..f04e953 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,2 @@ /build +/src/.slack diff --git a/Makefile b/Makefile index 32be557..ffdf7f9 100644 --- a/Makefile +++ b/Makefile @@ -10,13 +10,13 @@ install: | stub ifeq (${uname}, Darwin) @$(eval _bindir := $(shell greadlink -f ${bindir})) @$(eval _etcdir := $(shell greadlink -f ${etcdir})) - @sed -i '' "s|bindir=|bindir=${_bindir}|g" ${bindir}/slack - @sed -i '' "s|etcdir=|etcdir=${_etcdir}|g" ${bindir}/slack + @sed -i '' "s|bindir=.*|bindir=${_bindir}|g" ${bindir}/slack + @sed -i '' "s|etcdir=.*|etcdir=${_etcdir}|g" ${bindir}/slack else ifeq (${uname}, Linux) @$(eval _bindir := $(shell readlink -f ${bindir})) @$(eval _etcdir := $(shell readlink -f ${etcdir})) - @sed -i "s|bindir=|bindir=${_bindir}|g" ${bindir}/slack - @sed -i "s|etcdir=|etcdir=${_etcdir}|g" ${bindir}/slack + @sed -i "s|bindir=.*|bindir=${_bindir}|g" ${bindir}/slack + @sed -i "s|etcdir=.*|etcdir=${_etcdir}|g" ${bindir}/slack endif stub: diff --git a/src/slack b/src/slack index 8be010c..3b9156a 100755 --- a/src/slack +++ b/src/slack @@ -1,8 +1,13 @@ #!/usr/bin/env bash -bindir= -etcdir= -token=$([ -f "${etcdir}/slack" ] && sed -n '1p' < "${etcdir}/slack") +bindir="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" +etcdir="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" + +if [ -f "${etcdir}/.slack" ]; then + token=$(sed -n '1p' < "${etcdir}/.slack") +else + token="${SLACK_CLI_TOKEN}" +fi # COMMAND PARSING ################################################################################# cmd="${1}" ; shift @@ -143,7 +148,11 @@ case "${cmd}${sub}" in [ -z "${channels}" ] && read -e -p 'Enter channels (e.g. #general,C1234567890): ' channels ;; init) - _token=$([ -f "${etcdir}/slack" ] && sed -n '1p' < "${etcdir}/slack") + if [ -f "${etcdir}/.slack" ]; then + _token=$(sed -n '1p' < "${etcdir}/.slack") + else + _token="${SLACK_CLI_TOKEN}" + fi if [ -z "${token}" ] || [ "${token}" == "${_token}" ]; then read -e -p 'Enter Slack API token: ' token @@ -408,7 +417,7 @@ function fileupload() { } function init() { - echo "${token}" > "${etcdir}/slack" + echo "${token}" > "${etcdir}/.slack" case "${?}" in 0) echo '{"ok": true}' | jq -r ${compact} ${monochrome} "${filter:=.}" ;;