LoginSignup
0
0

More than 5 years have passed since last update.

爆速でSlack用のHubot作成からHerokuにデプロイするシェルスクリプト

Posted at

Herokuにボットをいっぱい作りたいので、自動化スクリプトをつくってみました

  1. Slack用のHubot作成
  2. Herokuにデプロイ

必要なもの

  • Herokuアカウント
  • SlackのHUBOT_SLACK_TOKEN

スクリプト

make_hubot.sh
function install(){
    if ! which $1 > /dev/null 2>&1 ; then  brew install -g $1 ; fi
    if ! which $1 > /dev/null 2>&1 ; then  npm  install -g $1 ; fi
}

function yo_hubot(){
    expect -c "
set timeout -1
spawn yo hubot
expect \"Owner\";        send \"${HUBOT_NAME}\n\"
expect \"Bot name\";     send \"${HUBOT_NAME}\n\"
expect \"Description\";  send \"${HUBOT_NAME}\n\"
expect \"Bot adapter\";  send \"slack\n\"
expect \"Everything looks all right!\";    exit 0
"
}

HUBOT_NAME=my_hubot
HUBOT_SLACK_TEAM=my_team
export HUBOT_SLACK_TOKEN=xoxb-xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx

declare -a apps=("node" "npm" "hubot" "yo" "generator-hubot" "coffee-script" "redis" "expect")
for app in ${apps[@]}; do
    echo $app
    install $app
done

bot_dir=`pwd`/hubot-${HUBOT_NAME}
script_path=`pwd`/${HUBOT_NAME}.coffee
rm -rf $bot_dir
mkdir  $bot_dir
cd     $bot_dir

yo_hubot
rm hubot-scripts.json
# カレントディレクトリに`${HUBOT_NAME}.coffee`があれば設置
cp $script_path $bot_dir/scripts/${HUBOT_NAME}.coffee

redis-cli shutdown
redis-server &
ln -sfv /usr/local/opt/redis/*.plist ~/Library/LaunchAgents
launchctl load -w ~/Library/LaunchAgents/homebrew.mxcl.redis.plist

./bin/hubot --adapter slack

git init
git add .
git commit -m "init ${HUBOT_NAME}"

heroku login
heroku create $HUBOT_NAME
heroku config:set \
HUBOT_SLACK_TOKEN=$HUBOT_SLACK_TOKEN \
HUBOT_SLACK_TEAM=$HUBOT_SLACK_TEAM \
HUBOT_SLACK_BOTNAME=$HUBOT_NAME \
HUBOT_HEROKU_KEEPALIVE_URL=$(heroku apps:info -s  | grep web_url | cut -d= -f2)
git push heroku master
heroku logs -t

実行

vi make_hubot.sh # ボット名やトークンを編集します
sh make_hubot.sh
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0