Skip to content

Commit

Permalink
Add consolidated build script
Browse files Browse the repository at this point in the history
  • Loading branch information
ryansturmer committed Oct 24, 2017
1 parent 0641610 commit 3bc7e20
Show file tree
Hide file tree
Showing 7 changed files with 230 additions and 0 deletions.
10 changes: 10 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -36,3 +36,13 @@ node_modules
*.tmp
*~
*.swp

scripts/consolidated/tmp
scripts/consolidated/dl
scripts/consolidated/build
scripts/consolidated/*.tar.gz
scripts/consolidated/*.bin
scripts/consolidated/*.json



47 changes: 47 additions & 0 deletions scripts/consolidated/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
build/container.fmp: cleartmp build/consolidated.fmp
cd tmp; \
cp ../files/container.json ./manifest.json; \
cp ../files/server.js ../build/consolidated.fmp ../files/fabmo-temp-updater.service .; \
tar -cvzf updater-stub.tar.gz server.js; \
tar -cvzf consolidated.tar.gz consolidated.fmp; \
tar -cvzf service.tar.gz fabmo-temp-updater.service; \
tar -cvzf ../build/container.fmp updater-stub.tar.gz manifest.json consolidated.tar.gz service.tar.gz

dl/engine.fmp dl/updater.fmp:
mkdir -p dl
node fetch.js

engine.tar.gz: cleartmp dl/engine.fmp
cd tmp; \
tar -xvzf ../dl/engine.fmp; \
mv files.tar.gz ../engine.tar.gz ;\
mv g2.bin ../

updater.tar.gz: cleartmp dl/updater.fmp
cd tmp; \
tar -xvzf ../dl/updater.fmp; \
mv files.tar.gz ../updater.tar.gz

token.tar.gz: cleartmp
cd tmp; \
touch install_token; \
tar -cvzf token.tar.gz install_token; \
mv token.tar.gz ..

build/consolidated.fmp: cleartmp token.tar.gz updater.tar.gz engine.tar.gz g2.bin files/consolidated.json
mkdir -p build
cd tmp; \
cp ../engine.tar.gz .; \
cp ../updater.tar.gz .; \
cp ../token.tar.gz .; \
cp ../g2.bin .; \
cp ../files/consolidated.json ./manifest.json; \
tar -cvzf ../build/consolidated.fmp engine.tar.gz updater.tar.gz g2.bin manifest.json

cleartmp:
mkdir -p tmp
rm -rf tmp/*

clean:
rm -rf tmp dl engine.tar.gz updater.tar.gz token.tar.gz g2.bin build
.PHONY: cleartemp clean
45 changes: 45 additions & 0 deletions scripts/consolidated/fetch.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
var request = require('request')
var fs = require('fs')

var MANIFEST_URL = 'http://fabmo.github.io/manifest/packages-rc.json'
var engineURL = null;
var updaterURL = null;
//var filesDownloaded = 0;

request(MANIFEST_URL, { json: true }, function(err, res, body) {
packages = body['packages']
for(var i=0; i<packages.length; i++) {
if(packages[i]['product'] === 'FabMo-Updater') {
updaterURL = packages[i]['url']
}
if(packages[i]['product'] === 'FabMo-Engine') {
engineURL = packages[i]['url']
}
}

console.log("Downloading engine fmp")
request(updaterURL)
.pipe(fs.createWriteStream('dl/updater.fmp'))
.on('finish', function() {
// filesDownloaded += 1;
console.log("Finished downloading updater.")
// if(filesDownloaded === 2) {
// buildPackage()
// }

});

console.log("Downloading updater fmp")
request(engineURL)
.pipe(fs.createWriteStream('dl/engine.fmp'))
.on('finish', function() {
// filesDownloaded += 1;
console.log("Finished downloading engine.")
// if(filesDownloaded === 2) {
// buildPackage();
// }
});


});

49 changes: 49 additions & 0 deletions scripts/consolidated/files/consolidated.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
{
"product":"FabMo-Updater",
"os":"linux",
"platform":"edison",
"system":"handibot",
"token":"/fabmo/updater/install_token",
"repository":"https://github.com/FabMo/FabMo-Updater",
"updaterNeeded":"v2.0.0",
"services":[
"fabmo",
"fabmo-updater"
],
"operations":[
{
"op":"deleteFiles",
"paths":[
"/fabmo/updater",
"/fabmo/engine"
]
},
{
"op":"expandArchive",
"src":"updater.tar.gz",
"dest":"/fabmo/updater"
},
{
"op":"expandArchive",
"src":"engine.tar.gz",
"dest":"/fabmo/engine"
},
{
"op":"installFirmware",
"src":"g2.bin"
},
{
"op":"deleteFiles",
"paths":[
"/opt/fabmo/approot"
]
},
{
"op":"expandArchive",
"src":"token.tar.gz",
"dest":"/fabmo/engine"
}

],
"version":"v2.3.0-gc851de8-rc"
}
36 changes: 36 additions & 0 deletions scripts/consolidated/files/container.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
{
"product":"FabMo-Engine",
"os":"linux",
"platform":"edison",
"system":"handibot",
"token":"/fabmo/engine/install_token",
"repository":"https://github.com/FabMo/FabMo-Updater",
"updaterNeeded":"v2.0.0",
"services":[
"fabmo"
],
"operations":[
{
"op":"deleteFiles",
"paths":[
"/fabmo/updater/install_token"
]
},
{
"op":"expandArchive",
"src":"updater-stub.tar.gz",
"dest":"/fabmo/engine"
},
{
"op":"expandArchive",
"src":"consolidated.tar.gz",
"dest":"/tmp"
},
{
"op":"expandArchive",
"src":"service.tar.gz",
"dest":"/etc/systemd/system"
}
],
"version":"v2.3.0-gc851de8-rc"
}
10 changes: 10 additions & 0 deletions scripts/consolidated/files/fabmo-temp-updater.service
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
[Unit]
Description=One time updater consolidated update

[Service]
Type=oneshot
ExecStart=/usr/bin/node /tmp/temp-updater/server.js --selfupdate /tmp/consolidated.fmp --task abcd
StandardOutput=journal

[Install]
WantedBy=multi-user.target
33 changes: 33 additions & 0 deletions scripts/consolidated/files/server.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
var fs = require("fs-extra")
var cp = require('child_process')

function exec(command, callback) {
console.log('Executing: ' + command)
cp.exec(command, {shell:true}, function(err, stderr, stdout) {
if (err) {
console.log('Error: ',err)
return callback()
}
console.log('stdout, stderr: ', stdout, stderr)
callback()
});

}

exec('systemctl daemon-reload', function() {
exec('systemctl stop fabmo-updater', function() {
fs.removeSync('/tmp/temp-updater')
fs.copy('/fabmo/updater', '/tmp/temp-updater', function(err) {
if(err) {
console.error(err);
return
}
console.info('Updater cloned, handing update off to clone');
console.info('See you, space cowboy.');

exec('systemctl start fabmo-temp-updater',function() {})
});
})
})

process.stdin.resume();

0 comments on commit 3bc7e20

Please sign in to comment.