Skip to content

Commit

Permalink
Script para gerar versão compatível com electron
Browse files Browse the repository at this point in the history
  • Loading branch information
atilacamurca committed Feb 26, 2017
1 parent 55e95ab commit 4c6bc50
Show file tree
Hide file tree
Showing 3 changed files with 136 additions and 1 deletion.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,4 @@ test/e2e/reports
selenium-debug.log
credentials.json
build/
electron/
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"description": "Remote PAD MQTT Broker",
"main": "src/index.js",
"author": "Átila Camurça <camurca.home@gmail.com>",
"license": "GPLv3",
"license": "GPL-3.0",
"dependencies": {
"mosca": "^2.2.0",
"pino": "^3.0.5",
Expand Down
134 changes: 134 additions & 0 deletions scripts/build4electron.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,134 @@
#!/usr/bin/env bash
#
# Generates a version for use with remote-pad-gui (electron)
#

set -o nounset
set -o errexit
set -o pipefail

DEFAULT_IFS="${IFS}"
SAFER_IFS=$'\n\t'
IFS="${SAFER_IFS}"

_ME=$(basename "${0}")

_print_help() {
cat <<HEREDOC
Remote Pad Server - compile to electron
Usage:
${_ME} [<arguments>]
${_ME} -h | --help
Options:
-h --help Show this screen.
HEREDOC
}

_install() {
_init
_install_dependencies
_setup_production_server
_end
}

_init() {
arch=$(uname -m)
if [ "$arch" != 'x86_64' ]
then
printf "Only supports x86_64. Your system is %s" $arch
exit 1
else
printf "Architecture supported.\n"
fi

if [[ -d electron ]]; then
echo "Removing previous build for electron..."
rm -r electron
fi
git archive --prefix=electron/ -o electron.zip HEAD
unzip electron.zip
rm electron.zip
cd electron
}

_install_dependencies() {
printf "Installing all dependencies.\n"
printf "It needs to install new software.\n"
sudo apt-get --quiet update
sudo apt-get --quiet -y install \
curl \
build-essential \
libxtst-dev \
libpng++-dev \
libssl-dev
if _command_exists node ; then
printf "Node js found %s\n" $(node --version)
else
curl -sL https://deb.nodesource.com/setup_6.x | sudo -E bash -
sudo apt-get install -y nodejs
printf "Node js %s installed\n" $(node --version)
fi

if _command_exists node-gyp ; then
printf "node-gyp found %s\n" $(node-gyp --version)
else
printf "Installing node-gyp\n"
sudo npm install --global node-gyp
fi

if _command_exists yarn ; then
printf "Yarn found %s\n" $(yarn --version)
else
curl -sS https://dl.yarnpkg.com/debian/pubkey.gpg | sudo apt-key add -
echo "deb https://dl.yarnpkg.com/debian/ stable main" | sudo tee /etc/apt/sources.list.d/yarn.list
sudo apt-get update
sudo apt-get install yarn
printf "Yarn %s installed\n" $(yarn --version)
fi
}

_setup_production_server() {
yarn install --ignore-optional
npm rebuild --runtime=electron \
--target=1.4.15 \
--disturl=https://atom.io/download/atom-shell \
--abi=48

declare -a arr=("alice" "bob" "carol" "david")
for player in "${arr[@]}"
do
./node_modules/.bin/mosca adduser "$player" "$player" \
--credentials ./credentials.json \
--authorize-publish "*/$player" \
--authorize-subscribe "*/$player"
done

./node_modules/.bin/mosca adduser "gui" "gui" \
--credentials ./credentials.json \
--authorize-publish "gui/*" \
--authorize-subscribe "gui/*"
}

_command_exists() {
type "$1" &> /dev/null ;
}

_end() {
# go back
cd -
printf "Remote Pad Server compiled to electron!\n"
}

_main() {
# Avoid complex option parsing when only one program option is expected.
if [[ "${1:-}" =~ ^-h|--help$ ]]
then
_print_help
else
_install "${@}"
fi
}

# Call `_main` after everything has been defined.
_main "${@:-}"

0 comments on commit 4c6bc50

Please sign in to comment.