Skip to content

Commit

Permalink
Add barebones install and config via env variable
Browse files Browse the repository at this point in the history
  • Loading branch information
rockymadden committed Jul 14, 2016
1 parent 9ec1320 commit 1cc2dfe
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 9 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
/build
/src/.slack
8 changes: 4 additions & 4 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
19 changes: 14 additions & 5 deletions src/slack
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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:=.}" ;;
Expand Down

0 comments on commit 1cc2dfe

Please sign in to comment.