Skip to content

Instantly share code, notes, and snippets.

@AKRFranko
Created March 20, 2016 11:46
Show Gist options
  • Save AKRFranko/fc3d353352ff0a40c359 to your computer and use it in GitHub Desktop.
Save AKRFranko/fc3d353352ff0a40c359 to your computer and use it in GitHub Desktop.
Install lets-chat, create two rooms, and a hubot that joins both of the rooms.
#!/bin/bash
# Install lets-chat, create two rooms, and a hubot that joins
# both of the rooms. Tested on an AWS EC2 instance using the Linux AMI.
# Pete Thomas <pete.thomas@gmail.com>, @peterthomas
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
# This software consists of voluntary contributions made by many individuals
# and is licensed under the MIT license. For more information, see
# <http://www.doctrine-project.org>.
# Start config
BOT_NAME=myhubot
BOT_LC_PWD=12345678
BOT_EMAIL='myhubot%40mailinator.com'
BOT_OWNER='My Hubot <myhubot@mailinator.com>'
ROOM_1='{"slug":"room1","name":"Room 1","description":"Room #1"}'
ROOM_2='{"slug":"room2","name":"Room 2","description":"Room #2"}'
# End config
HOST=127.0.0.1
PORT=5000
URL="http://$HOST:$PORT"
GET="curl -s -b cookies.txt -c cookies.txt"
POST="curl -s -b cookies.txt -c cookies.txt -X POST"
JSON_H='Content-Type: application/json'
REGEX_R='s/.*"id":"\([a-z0-9]*\).*/\1/p'
REGEX_T='s/.*"token":"\([a-zA-Z0-9=]*\).*/\1/p'
LC_LOGIN='username='$BOT_NAME'&password='$BOT_LC_PWD
LC_REGISTER=(
'username='$BOT_NAME
'email='$BOT_EMAIL
'display-name='$BOT_NAME
'first-name='$BOT_NAME
'last-name=Bot'
'password='$BOT_LC_PWD
'password-confirm='$BOT_LC_PWD
)
LC_REGISTER=$( IFS=$'&'; echo "${LC_REGISTER[*]}" )
sudo yum update -y
sudo yum install -y git docker; sudo service docker start
sudo docker pull mongo
sudo docker run -d --name db mongo --smallfiles
git clone https://github.com/sdelements/lets-chat.git
cd ./lets-chat/docker
sudo docker build -t lets-chat .
sudo docker run -d \
--name=lets-chat \
-p $PORT:$PORT \
-p 8080:8080 \
--link db:db lets-chat
sleep 5;
cd ~/
mkdir hubot
cd hubot
$POST --data $LC_REGISTER $URL/account/register >/dev/null
$POST --data $LC_LOGIN $URL/account/login >/dev/null
HUBOT_LCB_TOKEN=`$POST $URL/account/token/generate | sed -n "$REGEX_T"`
HUBOT_ROOM_1_ID=`$POST -H "$JSON_H" -d "$ROOM_1" $URL/rooms | sed -n "$REGEX_R"`
HUBOT_ROOM_2_ID=`$POST -H "$JSON_H" -d "$ROOM_2" $URL/rooms | sed -n "$REGEX_R"`
$GET $URL/logout >/dev/null
echo '{"name" : "stub","version" : "0.0.0"}' > package.json
cat << EOF > Dockerfile
FROM node:0.10-onbuild
MAINTAINER $BOT_OWNER
RUN npm install -g yo coffee-script generator-hubot
ENV HUBOT_LCB_TOKEN $HUBOT_LCB_TOKEN
ENV HUBOT_LCB_ROOMS $HUBOT_ROOM_1_ID,$HUBOT_ROOM_2_ID
ENV HUBOT_LCB_PROTOCOL http
ENV HUBOT_LCB_HOSTNAME localhost
ENV HUBOT_LCB_PORT $PORT
RUN useradd -d /$BOT_NAME -m -s /bin/bash -U $BOT_NAME
USER $BOT_NAME
WORKDIR /$BOT_NAME
RUN yo hubot --owner="$BOT_OWNER" \
--name="$BOT_NAME" \
--description="Hubot is a way of life." \
--adapter=lets-chat
RUN npm install
EXPOSE 8080
CMD ["./bin/hubot", "-a", "lets-chat"]
EOF
sudo docker build -t ${BOT_NAME}-bot .
sudo docker run -d \
--name=${BOT_NAME}-bot \
--net=container:lets-chat ${BOT_NAME}-bot
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment