Created
October 4, 2017 22:15
-
-
Save dogi/3a82a35b7f4adacac46e3eac08e6d9c0 to your computer and use it in GitHub Desktop.
latest
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 | |
name='ole-vi' | |
port='5984' | |
version='0.13.19' | |
# rename hostname of image to name | |
pirateship rename $name | |
pirateship docker | |
# create couchdb docker container | |
docker run -d -p $port:5984 --name $name -v /srv/data/$name:/usr/local/var/lib/couchdb -v /srv/log/$name:/usr/local/var/log/couchdb dogi/rpi-couchdb | |
# download BeLL-Apps | |
mkdir -p /root/ole/$version | |
cd /root/ole/$version | |
wget https://github.com/open-learning-exchange/BeLL-Apps/archive/$version.zip | |
unzip *.zip | |
sync | |
sync | |
sync | |
ln -s BeLL-Apps-* BeLL-Apps | |
cd BeLL-Apps | |
chmod +x node_modules/.bin/couchapp | |
cd app | |
python minify_html.py | |
mv MyApp/index.html MyApp/index1.html | |
mv MyApp/index2.html MyApp/index.html | |
mv nation/index.html nation/index1.html | |
mv nation/index2.html nation/index.html | |
cd .. | |
sync | |
sync | |
sync | |
# install community | |
# 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:$port/${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:$port/${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:$port/languages; | |
done | |
curl -d @init_docs/ConfigurationsDoc-Community.txt -H "Content-Type: application/json" -X POST http://127.0.0.1:$port/configurations | |
#curl -d @init_docs/admin.txt -H "Content-Type: application/json" -X POST http://127.0.0.1:$port/members | |
# favicon.ico | |
wget https://open-learning-exchange.github.io/favicon.ico | |
mv favicon.ico /srv/data/$name/. | |
curl -X PUT 'http://127.0.0.1:'$port'/_config/httpd_global_handlers/favicon.ico' -d '"{couch_httpd_misc_handlers, handle_favicon_req, \"/usr/local/var/lib/couchdb\"}"' | |
# write '/boot/autrun.sh' | |
echo '#!/bin/sh' > /boot/autorun.sh | |
echo '' >> /boot/autorun.sh | |
echo 'sleep 1' >> /boot/autorun.sh | |
echo 'docker start '$name >> /boot/autorun.sh | |
# expand filesystem | |
cd /usr/local/lib/ | |
npm update | |
pirateship expandfs | |
# redirect to bell | |
mkdir -p /root/ole | |
echo '#!/usr/bin/env node' > /root/ole/server.js | |
echo '' >> /root/ole/server.js | |
echo "var express = require('express')" >> /root/ole/server.js | |
echo 'var PortJack = express()' >> /root/ole/server.js | |
echo 'PortJack.get(/^(.+)$/, function(req, res) {' >> /root/ole/server.js | |
echo 'var options = {' >> /root/ole/server.js | |
echo '"'$name'.local": "http://'$name'.local:5984/apps/_design/bell/MyApp/index.html",' >> /root/ole/server.js | |
echo '"192.168.0.99": "http://192.168.0.99:5984/apps/_design/bell/MyApp/index.html",' >> /root/ole/server.js | |
echo '"192.168.1.99": "http://192.168.1.99:5984/apps/_design/bell/MyApp/index.html",' >> /root/ole/server.js | |
echo '"192.168.2.99": "http://192.168.2.99:5984/apps/_design/bell/MyApp/index.html",' >> /root/ole/server.js | |
echo '"192.168.3.99": "http://192.168.3.99:5984/apps/_design/bell/MyApp/index.html",' >> /root/ole/server.js | |
echo '"192.168.4.99": "http://192.168.4.99:5984/apps/_design/bell/MyApp/index.html"' >> /root/ole/server.js | |
echo '}' >> /root/ole/server.js | |
echo 'if (options.hasOwnProperty(req.hostname)) {' >> /root/ole/server.js | |
echo "res.setHeader('Location', options[req.hostname])" >> /root/ole/server.js | |
echo '}' >> /root/ole/server.js | |
echo 'else {' >> /root/ole/server.js | |
echo "res.setHeader('Location', 'http://ole.org')" >> /root/ole/server.js | |
echo '}' >> /root/ole/server.js | |
echo 'res.statusCode = 302' >> /root/ole/server.js | |
echo 'res.end()' >> /root/ole/server.js | |
echo '})' >> /root/ole/server.js | |
echo 'PortJack.listen(80)' >> /root/ole/server.js | |
chmod +x /root/ole/server.js | |
cd /root/ole | |
npm install express | |
# add to '/boot/autorun.sh' | |
echo '' >> /boot/autorun.sh | |
echo 'node /root/ole/server.js' >> /boot/autorun.sh | |
pirateship hotspot treehouse | |
sync | |
sync | |
sync | |
#reboot |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment