Add installation scripts

master
Aaron 2019-03-29 03:33:14 +00:00 committed by Kevin
parent 7048db42bd
commit df8a3d39bc
15 changed files with 293 additions and 44 deletions

13
.gitignore vendored
View File

@ -17,3 +17,16 @@ core
.vscode/*
venv/*
onionr/fs*
# log files
output.log
*.log
onionr/output.log
onionr/*.log
onionr/data/output.log
onionr/data/*.log
# package files
onionr-*.pkg.tar.gz
pkg/
src/

View File

@ -6,7 +6,7 @@ PREFIX = /usr/local
.DEFAULT_GOAL := setup
setup:
sudo pip3 install -r requirements.txt
pip3 install -r requirements.txt --require-hashes --user
-@cd onionr/static-data/ui/; ./compile.py
install:
@ -32,7 +32,7 @@ reset:
@echo "Hard-resetting Onionr..."
rm -rf onionr/$(ONIONR_HOME)/ | true > /dev/null 2>&1
cd onionr/static-data/www/ui/; rm -rf ./dist; python compile.py
#@./onionr.sh.sh version | grep -v "Failed" --color=always
#@./onionr.sh version | grep -v "Failed" --color=always
plugins-reset:
@echo "Resetting plugins..."

20
PKGBUILD Normal file
View File

@ -0,0 +1,20 @@
url="https://onionr.net/"
pkgname="onionr"
pkgver=0.0
pkgrel=1
pkgdesc="P2P anonymous storage network"
arch=("x86_64")
license=('GPL')
source=("onionr-${pkgver}::git+https://gitlab.com/beardog/onionr.git#branch=master")
md5sums=('SKIP')
makedepends=('git', 'python3-pip')
build() {
cd "$pkgname-${pkgver}"
make
}
package() {
cd "$pkgname-${pkgver}"
# make install
}

BIN
docs/onionr-icon.png Executable file

Binary file not shown.

After

Width:  |  Height:  |  Size: 85 KiB

83
install/install_arch.sh Executable file
View File

@ -0,0 +1,83 @@
#!/bin/bash
EXECUTABLE='/usr/bin/onionr'
OUTPUT_DIR='/usr/share/onionr'
DATA_DIR='/etc/onionr'
LOG_DIR='/var/log/onionr'
BRANCH='master'
# setup error handlers
set -e
trap "echo -e '\033[31mOnionr installation failed.\033[0m' >&2; exit 1337" ERR INT TERM
# require root permissions
if ! [ $(id -u) = 0 ]; then
echo 'This script must be run as root.' >&2
exit 1337
fi
# install basic dependencies
pacman --needed --noconfirm -S git curl python python-pip tor
# get the repository
rm -rf "$OUTPUT_DIR" "$DATA_DIR" "$LOG_DIR"
git clone https://gitlab.com/beardog/onionr "$OUTPUT_DIR"
cd "$OUTPUT_DIR"
git checkout "$BRANCH"
# install python dependencies
pip3 install --no-input -r "$OUTPUT_DIR/requirements.txt" --require-hashes
# create nologin onionr user if not exists
id -u onionr &>/dev/null || useradd -r -s /sbin/nologin onionr
chmod 755 "$OUTPUT_DIR"
chown -R onionr:onionr "$OUTPUT_DIR"
# create directories
mkdir -p "$OUTPUT_DIR/onionr/data" "$LOG_DIR"
mv "$OUTPUT_DIR/onionr/data" "$DATA_DIR"
chmod -R 750 "$DATA_DIR" "$LOG_DIR"
chown -R onionr:onionr "$DATA_DIR" "$LOG_DIR"
# create executable
cp "$OUTPUT_DIR/install/onionr" "$EXECUTABLE"
chmod 755 "$EXECUTABLE"
chown root:root "$EXECUTABLE"
# create systemd service
SERVICE='/etc/systemd/system/onionr.service'
cp "$OUTPUT_DIR/install/onionr.service" "$SERVICE"
chmod 644 "$SERVICE"
chown root:root "$SERVICE"
systemctl daemon-reload
systemctl enable onionr
systemctl start onionr
# pretty header thing
"$EXECUTABLE" --header 'Onionr successfully installed.'
# and we're good!
trap - ERR
exit 0

83
install/install_debian.sh Executable file
View File

@ -0,0 +1,83 @@
#!/bin/bash
EXECUTABLE='/usr/bin/onionr'
OUTPUT_DIR='/usr/share/onionr'
DATA_DIR='/etc/onionr'
LOG_DIR='/var/log/onionr'
BRANCH='master'
# setup error handlers
set -e
trap "echo -e '\033[31mOnionr installation failed.\033[0m' >&2; exit 1337" ERR INT TERM
# require root permissions
if ! [ $(id -u) = 0 ]; then
echo 'This script must be run as root.' >&2
exit 1337
fi
# install basic dependencies
apt -y install git curl python3.7 python3-pip python3-setuptools tor
# get the repository
rm -rf "$OUTPUT_DIR" "$DATA_DIR" "$LOG_DIR"
git clone https://gitlab.com/beardog/onionr "$OUTPUT_DIR"
cd "$OUTPUT_DIR"
git checkout "$BRANCH"
# install python dependencies
python3.7 -m pip install --no-input -r "$OUTPUT_DIR/requirements.txt" --require-hashes
# create nologin onionr user if not exists
id -u onionr &>/dev/null || useradd -r -s /sbin/nologin onionr
chmod 755 "$OUTPUT_DIR"
chown -R onionr:onionr "$OUTPUT_DIR"
# create directories
mkdir -p "$OUTPUT_DIR/onionr/data" "$LOG_DIR"
mv "$OUTPUT_DIR/onionr/data" "$DATA_DIR"
chmod -R 750 "$DATA_DIR" "$LOG_DIR"
chown -R onionr:onionr "$DATA_DIR" "$LOG_DIR"
# create executable
cp "$OUTPUT_DIR/install/onionr" "$EXECUTABLE"
chmod 755 "$EXECUTABLE"
chown root:root "$EXECUTABLE"
# create systemd service
SERVICE='/etc/systemd/system/onionr.service'
cp "$OUTPUT_DIR/install/onionr.service" "$SERVICE"
chmod 644 "$SERVICE"
chown root:root "$SERVICE"
systemctl daemon-reload
systemctl enable onionr
systemctl start onionr
# pretty header thing
"$EXECUTABLE" --header 'Onionr successfully installed.'
# and we're good!
trap - ERR
exit 0

12
install/onionr Executable file
View File

@ -0,0 +1,12 @@
#!/bin/sh
set -e
[ "root" != "$USER" ] && exec sudo $0 "$@"
export OUTPUT_DIR=${OUTPUT_DIR:=/usr/share/onionr}
export ONIONR_HOME=${ONIONR_HOME:=/etc/onionr}
export LOG_DIR=${LOG_DIR:=/var/log/onionr}
cd "$OUTPUT_DIR"
exec su onionr -s /bin/sh -c "./onionr.sh ""$@"""

15
install/onionr.service Normal file
View File

@ -0,0 +1,15 @@
[Unit]
Description=Onionr Daemon
Requires=network.target tor.service
After=network.target tor.service
[Service]
Environment="DATA_DIR=/usr/share/onionr"
Environment="LOG_DIR=/var/log/onionr/"
ExecStart=/usr/bin/onionr --start
ExecStop=/usr/bin/onionr --stop
Type=simple
Restart=always
[Install]
WantedBy=tor.service

View File

@ -20,13 +20,11 @@
import os, json, logger
try:
dataDir = os.environ['ONIONR_HOME']
if not dataDir.endswith('/'):
dataDir += '/'
except KeyError:
dataDir = 'data/'
# set data dir
dataDir = os.environ.get('ONIONR_HOME', os.environ.get('DATA_DIR', 'data/'))
if not dataDir.endswith('/'):
dataDir += '/'
_configfile = os.path.abspath(dataDir + 'config.json')
_config = {}

View File

@ -39,12 +39,10 @@ class Core:
Initialize Core Onionr library
'''
try:
self.dataDir = os.environ['ONIONR_HOME']
if not self.dataDir.endswith('/'):
self.dataDir += '/'
except KeyError:
self.dataDir = 'data/'
# set data dir
self.dataDir = os.environ.get('ONIONR_HOME', os.environ.get('DATA_DIR', 'data/'))
if not self.dataDir.endswith('/'):
self.dataDir += '/'
try:
self.onionrInst = None

View File

@ -64,10 +64,9 @@ class colors:
'''
Use the bitwise operators to merge these settings
'''
USE_ANSI = 0b100
if os.name == 'nt':
USE_ANSI = 0b000
else:
USE_ANSI = 0b100
OUTPUT_TO_CONSOLE = 0b010
OUTPUT_TO_FILE = 0b001
@ -80,7 +79,7 @@ LEVEL_IMPORTANT = 6
_type = OUTPUT_TO_CONSOLE | USE_ANSI # the default settings for logging
_level = LEVEL_DEBUG # the lowest level to log
_outputfile = './output.log' # the file to log to
_outputfile = 'data/onionr.log' # the file to log to
def set_settings(type):
'''

View File

@ -46,12 +46,10 @@ class NetController:
'''
def __init__(self, hsPort, apiServerIP='127.0.0.1'):
try:
self.dataDir = os.environ['ONIONR_HOME']
if not self.dataDir.endswith('/'):
self.dataDir += '/'
except KeyError:
self.dataDir = 'data/'
# set data dir
self.dataDir = os.environ.get('ONIONR_HOME', os.environ.get('DATA_DIR', 'data/'))
if not self.dataDir.endswith('/'):
self.dataDir += '/'
self.torConfigLocation = self.dataDir + 'torrc'
self.readyState = False
@ -165,7 +163,7 @@ HiddenServicePort 80 ''' + self.apiServerIP + ''':''' + str(self.hsPort)
except KeyboardInterrupt:
logger.fatal('Got keyboard interrupt.', timestamp = False, level = logger.LEVEL_IMPORTANT)
return False
logger.debug('Finished starting Tor.', timestamp=True)
self.readyState = True

View File

@ -62,12 +62,13 @@ class Onionr:
except FileNotFoundError:
pass
try:
self.dataDir = os.environ['ONIONR_HOME']
if not self.dataDir.endswith('/'):
self.dataDir += '/'
except KeyError:
self.dataDir = 'data/'
# set data dir
self.dataDir = os.environ.get('ONIONR_HOME', os.environ.get('DATA_DIR', 'data/'))
if not self.dataDir.endswith('/'):
self.dataDir += '/'
# set log file
logger.set_file(os.environ.get('LOG_DIR', 'data') + '/onionr.log')
# Load global configuration data
data_exists = Onionr.setupConfig(self.dataDir, self = self)
@ -144,19 +145,27 @@ class Onionr:
self.execute(command)
return
def exitSigterm(self, signum, frame):
self.killed = True
def setupConfig(dataDir, self = None):
setupconfig.setup_config(dataDir, self)
def cmdHeader(self):
if len(sys.argv) >= 3:
self.header(logger.colors.fg.pink + sys.argv[2].replace('Onionr', logger.colors.bold + 'Onionr' + logger.colors.reset + logger.colors.fg.pink))
else:
self.header(None)
def header(self, message = logger.colors.fg.pink + logger.colors.bold + 'Onionr' + logger.colors.reset + logger.colors.fg.pink + ' has started.'):
if os.path.exists('static-data/header.txt') and logger.get_level() <= logger.LEVEL_INFO:
with open('static-data/header.txt', 'rb') as file:
# only to stdout, not file or log or anything
sys.stderr.write(file.read().decode().replace('P', logger.colors.fg.pink).replace('W', logger.colors.reset + logger.colors.bold).replace('G', logger.colors.fg.green).replace('\n', logger.colors.reset + '\n').replace('B', logger.colors.bold).replace('A', '%s' % API_VERSION).replace('V', ONIONR_VERSION))
logger.info(logger.colors.fg.lightgreen + '-> ' + str(message) + logger.colors.reset + logger.colors.fg.lightgreen + ' <-\n', sensitive=True)
if not message is None:
logger.info(logger.colors.fg.lightgreen + '-> ' + str(message) + logger.colors.reset + logger.colors.fg.lightgreen + ' <-\n', sensitive=True)
def doExport(self, bHash):
exportDir = self.dataDir + 'block-export/'
@ -220,13 +229,13 @@ class Onionr:
def showDetails(self):
commands.onionrstatistics.show_details(self)
def openHome(self):
commands.open_home(self)
def addID(self):
commands.pubkeymanager.add_ID(self)
def changeID(self):
commands.pubkeymanager.change_ID(self)
@ -385,7 +394,7 @@ class Onionr:
'''
Displays a message suggesting help
'''
if __name__ == '__main__':
if __name__ == '__main__':
logger.info('Do ' + logger.colors.bold + sys.argv[0] + ' --help' + logger.colors.reset + logger.colors.fg.green + ' for Onionr help.')
def start(self, input = False, override = False):

View File

@ -53,6 +53,7 @@ def get_commands(onionr_inst):
return {'': onionr_inst.showHelpSuggestion,
'help': onionr_inst.showHelp,
'version': onionr_inst.version,
'header': onionr_inst.cmdHeader,
'config': onionr_inst.configure,
'start': onionr_inst.start,
'stop': onionr_inst.killDaemon,
@ -168,4 +169,4 @@ cmd_help = {
'add-id': 'Generate a new ID (key pair)',
'change-id': 'Change active ID',
'open-home': 'Open your node\'s home/info screen'
}
}

View File

@ -21,12 +21,10 @@
import os, re, importlib, config, logger
import onionrevents as events
try:
dataDir = os.environ['ONIONR_HOME']
if not dataDir.endswith('/'):
dataDir += '/'
except KeyError:
dataDir = 'data/'
# set data dir
dataDir = os.environ.get('ONIONR_HOME', os.environ.get('DATA_DIR', 'data/'))
if not dataDir.endswith('/'):
dataDir += '/'
_pluginsfolder = dataDir + 'plugins/'
_instances = dict()
@ -157,6 +155,28 @@ def stop(name, onionr = None):
return None
# credit: https://stackoverflow.com/a/29589414
def import_module_from_file(full_path_to_module):
"""
Import a module given the full path/filename of the .py file
Python 3.4
"""
module = None
# Get module name and path from full path
module_dir, module_file = os.path.split(full_path_to_module)
module_name, module_ext = os.path.splitext(module_file)
# Get module "spec" from filename
spec = importlib.util.spec_from_file_location(module_name,full_path_to_module)
module = spec.loader.load_module()
return module
def get_plugin(name):
'''
Returns the instance of a module
@ -167,7 +187,7 @@ def get_plugin(name):
if str(name).lower() in _instances:
return _instances[str(name).lower()]
else:
_instances[str(name).lower()] = importlib.import_module(get_plugins_folder(name, False).replace('/', '.') + 'main')
_instances[str(name).lower()] = import_module_from_file(get_plugins_folder(name, False) + 'main.py')
return get_plugin(name)
def get_plugins():