-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #7 from riptidewave93/go-convert
Move rfled-server to GoLang
- Loading branch information
Showing
9 changed files
with
399 additions
and
108 deletions.
There are no files selected for viewing
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
bin/* | ||
pkg | ||
releases | ||
src/github.com |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,23 +1,23 @@ | ||
RFLED-Server | ||
============ | ||
========== | ||
|
||
Python Scripts to run UDP servers to emulate a LimitlessLED WiFi Bridge 4.0 unit. | ||
Golang binary to emulate a LimitlessLED WiFi Bridge 4.0 unit. | ||
|
||
Install | ||
======= | ||
---- | ||
1. Download the latest release from the [Releases](https://github.com/riptidewave93/RFLED-Server/releases) | ||
page for your architecture. | ||
2. Copy the contents of ./rfled-server/* to / on your disk as root | ||
3. Configure your settings in /etc/default/rfled-server as needed | ||
4. Enable the init.d script `systemctl enable rfled-server` | ||
5. Start the service `service rfled-server start` | ||
6. ??? | ||
7. Profit! | ||
|
||
* Change the variables in both scripts to meet your needs | ||
* Start the scripts and they will start the UDP listeners | ||
|
||
Startup Script | ||
============== | ||
|
||
* Place script into /etc/init.d/ | ||
* a) Ensure scripts are in /usr/local/bin/ or | ||
* b) Adjust path in rfled-server script to path of the scripts | ||
* Run update-rc.d rfled-server defaults to set up | ||
|
||
Running | ||
======= | ||
|
||
* Run "/etc/init.d/rfled-server start" to start scripts without a restart | ||
Build from Source | ||
---- | ||
1. Setup a go build environment, and run `./build.sh` | ||
2. Once ran, you can run `./build.sh package` as root to generate a release .tar.gz | ||
3. Follow the above Install steps with the tar.gz in ./releases for your architecture. | ||
4. ????? | ||
5. Profit! |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
#!/bin/bash | ||
|
||
# Set env vars for building | ||
export GOPATH=$PWD | ||
export GOBIN=$PWD/bin | ||
|
||
# Do we even have go installed? | ||
command -v go >/dev/null 2>&1 || { echo >&2 "I require go but it's not installed. Aborting."; exit 1; } | ||
|
||
# Are we building or cleaning house? | ||
if [[ "$1" == "clean" ]]; then | ||
rm $PWD/bin/* 2>/dev/null | ||
rm -r $PWD/pkg 2>/dev/null | ||
rm -fr $PWD/src/github.com 2>/dev/null | ||
rm -r $PWD/releases 2>/dev/null | ||
else | ||
# Download dependencies | ||
if [ ! -d "$GOPATH/src/github.com/tarm/serial" ]; then | ||
git clone https://github.com/tarm/serial.git $GOPATH/src/github.com/tarm/serial | ||
fi | ||
|
||
# Make required dir if needed | ||
if [ ! -d "$GOBIN" ]; then | ||
mkdir $GOBIN | ||
fi | ||
|
||
# build the things! | ||
echo "Building amd64..." | ||
env GOOS=linux GOARCH=amd64 go build -o $GOBIN/rfled-server-amd64 $PWD/src/rfled-server.go | ||
echo "Building armv6..." | ||
env GOOS=linux GOARCH=arm GOARM=6 go build -o $GOBIN/rfled-server-armv6 $PWD/src/rfled-server.go | ||
echo "Building armv7..." | ||
env GOOS=linux GOARCH=arm GOARM=7 go build -o $GOBIN/rfled-server-armv7 $PWD/src/rfled-server.go | ||
|
||
# We finished! | ||
if [ $? -eq 0 ]; then | ||
echo "Build Complete! Binary is in $GOBIN" | ||
fi | ||
|
||
# Are we building shippable releases? | ||
if [[ "$1" == "package" ]]; then | ||
if [[ $EUID -ne 0 ]]; then | ||
echo "Error, package mode must be ran as root" 1>&2 | ||
exit 1 | ||
fi | ||
echo "Building Releases..." | ||
for arch in amd64 armv6 armv7; | ||
do | ||
echo "Packaging $arch" | ||
if [ ! -d "$GOPATH/releases/tmp/$arch/rfled-server/usr/sbin" ]; then | ||
mkdir -p $GOPATH/releases/tmp/$arch/rfled-server/usr/sbin | ||
fi | ||
cp $GOBIN/rfled-server-$arch $GOPATH/releases/tmp/$arch/rfled-server/usr/sbin/rfled-server | ||
chmod +x $GOPATH/releases/tmp/$arch/rfled-server/usr/sbin/rfled-server | ||
cp -r $GOPATH/src/etc $GOPATH/releases/tmp/$arch/rfled-server/ | ||
chmod +x $GOPATH/releases/tmp/$arch/rfled-server/etc/init.d/rfled-server | ||
chown -R root:root $GOPATH/releases/tmp/$arch/rfled-server | ||
tar -pczf $GOPATH/releases/rfled-server-$arch-$(date +"%F-%H%M%S").tar.gz -C $GOPATH/releases/tmp/$arch ./rfled-server | ||
done | ||
rm -rf $GOPATH/releases/tmp/ | ||
echo "Done! :)" | ||
fi | ||
fi |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
# Default settings for rfled-server. This file is sourced by /bin/sh from | ||
# /etc/init.d/rfled-server. | ||
|
||
# Define any options you want to be used when running. You can run rfled-server -h | ||
# to get the list of available flags for this service. | ||
RFLED_OPTS= |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,114 @@ | ||
#! /bin/sh | ||
|
||
### BEGIN INIT INFO | ||
# Provides: rfled-server | ||
# Required-Start: $remote_fs $syslog | ||
# Required-Stop: $remote_fs $syslog | ||
# Default-Start: 2 3 4 5 | ||
# Default-Stop: | ||
# Short-Description: RFLED-Server for Milight LEDs | ||
### END INIT INFO | ||
|
||
set -e | ||
|
||
# /etc/init.d/rfled-server: start and stop the rfled-server service | ||
|
||
test -x /usr/sbin/rfled-server || exit 0 | ||
( /usr/sbin/rfled-server -h 2>&1 | grep -q Usage ) 2>/dev/null || exit 0 | ||
|
||
umask 022 | ||
|
||
if test -f /etc/default/rfled-server; then | ||
. /etc/default/rfled-server | ||
fi | ||
|
||
. /lib/lsb/init-functions | ||
|
||
if [ -n "$2" ]; then | ||
RFLED_OPTS="$RFLED_OPTS $2" | ||
fi | ||
|
||
# Are we running from init? | ||
run_by_init() { | ||
([ "$previous" ] && [ "$runlevel" ]) || [ "$runlevel" = S ] | ||
} | ||
|
||
check_for_upstart() { | ||
if init_is_upstart; then | ||
exit $1 | ||
fi | ||
} | ||
|
||
export PATH="${PATH:+$PATH:}/usr/sbin:/sbin" | ||
|
||
case "$1" in | ||
start) | ||
check_for_upstart 1 | ||
log_daemon_msg "Starting rfled-server" "rfled-server" || true | ||
if start-stop-daemon --start --quiet --oknodo --background --pidfile /var/run/rfled-server.pid --make-pidfile --exec /usr/sbin/rfled-server -- $RFLED_OPTS; then | ||
log_end_msg 0 || true | ||
else | ||
log_end_msg 1 || true | ||
fi | ||
;; | ||
stop) | ||
check_for_upstart 0 | ||
log_daemon_msg "Stopping rfled-server" "rfled-server" || true | ||
if start-stop-daemon --stop --quiet --oknodo --pidfile /var/run/rfled-server.pid; then | ||
log_end_msg 0 || true | ||
else | ||
log_end_msg 1 || true | ||
fi | ||
;; | ||
|
||
restart) | ||
check_for_upstart 1 | ||
log_daemon_msg "Restarting rfled-server" "rfled-server" || true | ||
start-stop-daemon --stop --quiet --oknodo --retry 30 --pidfile /var/run/rfled-server.pid | ||
check_dev_null log_end_msg | ||
if start-stop-daemon --start --quiet --oknodo --background --pidfile /var/run/rfled-server.pid --make-pidfile --exec /usr/sbin/rfled-server -- $RFLED_OPTS; then | ||
log_end_msg 0 || true | ||
else | ||
log_end_msg 1 || true | ||
fi | ||
;; | ||
|
||
try-restart) | ||
check_for_upstart 1 | ||
log_daemon_msg "Restarting rfled-server" "rfled-server" || true | ||
RET=0 | ||
start-stop-daemon --stop --quiet --retry 30 --pidfile /var/run/rfled-server.pid || RET="$?" | ||
case $RET in | ||
0) | ||
# old daemon stopped | ||
check_dev_null log_end_msg | ||
if start-stop-daemon --start --quiet --oknodo --background --pidfile /var/run/rfled-server.pid --make-pidfile --exec /usr/sbin/rfled-server -- $RFLED_OPTS; then | ||
log_end_msg 0 || true | ||
else | ||
log_end_msg 1 || true | ||
fi | ||
;; | ||
1) | ||
# daemon not running | ||
log_progress_msg "(not running)" || true | ||
log_end_msg 0 || true | ||
;; | ||
*) | ||
# failed to stop | ||
log_progress_msg "(failed to stop)" || true | ||
log_end_msg 1 || true | ||
;; | ||
esac | ||
;; | ||
|
||
status) | ||
check_for_upstart 1 | ||
status_of_proc -p /var/run/rfled-server.pid /usr/sbin/rfled-server rfled-server && exit 0 || exit $? | ||
;; | ||
|
||
*) | ||
log_action_msg "Usage: /etc/init.d/rfled-server {start|stop|restart|try-restart|status}" || true | ||
exit 1 | ||
esac | ||
|
||
exit 0 |
Oops, something went wrong.