Last active
January 27, 2018 05:44
-
-
Save xyb994/079e0f214f2c3855fc3e24e7b3d75118 to your computer and use it in GitHub Desktop.
BellApps installation script for Ubuntu
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
cd /root || exit 1 | |
# install docker | |
# https://docs.docker.com/install/linux/docker-ce/ubuntu/ | |
apt-get remove docker docker-engine docker.io | |
apt-get update | |
apt-get install -y \ | |
apt-transport-https \ | |
ca-certificates \ | |
curl \ | |
software-properties-common | |
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add - | |
add-apt-repository \ | |
"deb [arch=amd64] https://download.docker.com/linux/ubuntu \ | |
$(lsb_release -cs) \ | |
stable" | |
apt-get update | |
apt-get install -y docker-ce | |
# https://github.com/dogi/ole--vagrant-vi/blob/master/Vagrantfile | |
docker run -d -p 5984:5984 --name bell -v /srv/data/bell:/usr/local/var/lib/couchdb -v /srv/log/bell:/usr/local/var/log/couchdb klaemo/couchdb | |
# use crontab to start couchdb on boot | |
sudo crontab -l | sudo tee -a mycron | |
echo "@reboot sudo docker start bell" | sudo tee -a mycron | |
echo "@reboot sudo node /root/server.js" | sudo tee -a mycron | |
sudo crontab mycron | |
sudo rm mycron | |
apt install -y nodejs npm | |
wget https://github.com/open-learning-exchange/BeLL-Apps/archive/0.13.19.zip | |
unzip 0.13.19.zip | |
ln -s BeLL-Apps-* BeLL-Apps ## won't work in windows | |
cd BeLL-Apps || exit 1 | |
chmod +x node_modules/.bin/couchapp | |
## check if docker is running | |
while ! curl -X GET http://127.0.0.1:5984/_all_dbs ; do | |
sleep 1 | |
done | |
## create databases & push design docs into them | |
for database in databases/*.js; do | |
curl -X PUT "http://127.0.0.1:5984/${database:10:-3}" | |
## do in all except communities languages configurations | |
case ${database:10:-3} in | |
"communities" | "languages" | "configurations" ) ;; | |
* ) node_modules/.bin/couchapp push "$database" "http://127.0.0.1:5984/${database:10:-3}" ;; | |
esac | |
done | |
## add bare minimal required data to couchdb for launching bell-apps smoothly | |
for filename in init_docs/languages/*.txt; do | |
curl -d "@$filename" -H "Content-Type: application/json" -X POST http://127.0.0.1:5984/languages; | |
done | |
curl -d @init_docs/ConfigurationsDoc-Community.txt -H "Content-Type: application/json" -X POST http://127.0.0.1:5984/configurations | |
#curl -d @init_docs/admin.txt -H "Content-Type: application/json" -X POST http://127.0.0.1:5984/members | |
## fix of log file | |
curl -X PUT 'http://127.0.0.1:5984/_config/log/file' -d '"/usr/local/var/log/couchdb/couch.log"' | |
## favicon.ico | |
wget https://open-learning-exchange.github.io/favicon.ico | |
mv favicon.ico /srv/data/bell/. | |
#curl -X PUT 'http://127.0.0.1:5984/_config/httpd_global_handlers/favicon.ico' -d '"{couch_httpd_misc_handlers, handle_favicon_req, \"/usr/local/var/lib/couchdb\"}"' | |
curl -X PUT 'http://127.0.0.1:5984/_config/httpd_global_handlers/favicon.ico' -d '"{couch_httpd_misc_handlers, handle_favicon_req, \\"/usr/local/var/lib/couchdb\\"}"' | |
# add redirect on port 8080 | |
npm install express | |
{ | |
echo '#!/usr/bin/env node' | |
echo '' | |
echo "var express = require('express')" | |
echo 'var PortJack = express()' | |
echo 'PortJack.get(/^(.+)$/, function(req, res) {' | |
echo 'var options = {' | |
echo '"127.0.0.1": "http://127.0.0.1:5985/apps/_design/bell/MyApp/index.html",' | |
echo '"localhost": "http://localhost:5985/apps/_design/bell/MyApp/index.html"' | |
echo '}' | |
echo 'if (options.hasOwnProperty(req.hostname)) {' | |
echo "res.setHeader('Location', options[req.hostname])" | |
echo '}' | |
echo 'else {' | |
echo "res.setHeader('Location', 'http://ole.org')" | |
echo '}' | |
echo 'res.statusCode = 302' | |
echo 'res.end()' | |
echo '})' | |
echo 'PortJack.listen(8080)' | |
} > /root/server.js | |
chmod +x /root/server.js | |
node /root/server.js & |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment