forked from STI/Astroport.ONE
satisfying tools
This commit is contained in:
parent
743c37738f
commit
78e94d1ef2
|
@ -0,0 +1,184 @@
|
|||
#!/usr/bin/env python
|
||||
from __future__ import print_function
|
||||
|
||||
import os
|
||||
import sys
|
||||
import json
|
||||
import struct
|
||||
import subprocess
|
||||
|
||||
VERSION = '7.1b2'
|
||||
|
||||
try:
|
||||
sys.stdin.buffer
|
||||
|
||||
# Python 3.x version
|
||||
# Read a message from stdin and decode it.
|
||||
def getMessage():
|
||||
rawLength = sys.stdin.buffer.read(4)
|
||||
if len(rawLength) == 0:
|
||||
sys.exit(0)
|
||||
messageLength = struct.unpack('@I', rawLength)[0]
|
||||
message = sys.stdin.buffer.read(messageLength).decode('utf-8')
|
||||
return json.loads(message)
|
||||
|
||||
# Send an encoded message to stdout
|
||||
def sendMessage(messageContent):
|
||||
encodedContent = json.dumps(messageContent).encode('utf-8')
|
||||
encodedLength = struct.pack('@I', len(encodedContent))
|
||||
|
||||
sys.stdout.buffer.write(encodedLength)
|
||||
sys.stdout.buffer.write(encodedContent)
|
||||
sys.stdout.buffer.flush()
|
||||
|
||||
except AttributeError:
|
||||
# Python 2.x version (if sys.stdin.buffer is not defined)
|
||||
# Read a message from stdin and decode it.
|
||||
def getMessage():
|
||||
rawLength = sys.stdin.read(4)
|
||||
if len(rawLength) == 0:
|
||||
sys.exit(0)
|
||||
messageLength = struct.unpack('@I', rawLength)[0]
|
||||
message = sys.stdin.read(messageLength)
|
||||
return json.loads(message)
|
||||
|
||||
# Send an encoded message to stdout
|
||||
def sendMessage(messageContent):
|
||||
encodedContent = json.dumps(messageContent)
|
||||
encodedLength = struct.pack('@I', len(encodedContent))
|
||||
|
||||
sys.stdout.write(encodedLength)
|
||||
sys.stdout.write(encodedContent)
|
||||
sys.stdout.flush()
|
||||
|
||||
|
||||
def install():
|
||||
home_path = os.getenv('HOME')
|
||||
|
||||
manifest = {
|
||||
'name': 'open_with',
|
||||
'description': 'Open With native host',
|
||||
'path': os.path.realpath(__file__),
|
||||
'type': 'stdio',
|
||||
}
|
||||
locations = {
|
||||
'chrome': os.path.join(home_path, '.config', 'google-chrome', 'NativeMessagingHosts'),
|
||||
'chromium': os.path.join(home_path, '.config', 'chromium', 'NativeMessagingHosts'),
|
||||
'firefox': os.path.join(home_path, '.mozilla', 'native-messaging-hosts'),
|
||||
}
|
||||
filename = 'open_with.json'
|
||||
|
||||
for browser, location in locations.items():
|
||||
if os.path.exists(os.path.dirname(location)):
|
||||
if not os.path.exists(location):
|
||||
os.mkdir(location)
|
||||
|
||||
browser_manifest = manifest.copy()
|
||||
if browser == 'firefox':
|
||||
browser_manifest['allowed_extensions'] = ['openwith@darktrojan.net']
|
||||
else:
|
||||
browser_manifest['allowed_origins'] = [
|
||||
'chrome-extension://cogjlncmljjnjpbgppagklanlcbchlno/', # Chrome
|
||||
'chrome-extension://fbmcaggceafhobjkhnaakhgfmdaadhhg/', # Opera
|
||||
]
|
||||
|
||||
with open(os.path.join(location, filename), 'w') as file:
|
||||
file.write(
|
||||
json.dumps(browser_manifest, indent=2, separators=(',', ': '), sort_keys=True).replace(' ', '\t') + '\n'
|
||||
)
|
||||
|
||||
|
||||
def _read_desktop_file(path):
|
||||
with open(path, 'r') as desktop_file:
|
||||
current_section = None
|
||||
name = None
|
||||
command = None
|
||||
for line in desktop_file:
|
||||
if line[0] == '[':
|
||||
current_section = line[1:-2]
|
||||
if current_section != 'Desktop Entry':
|
||||
continue
|
||||
|
||||
if line.startswith('Name='):
|
||||
name = line[5:].strip()
|
||||
elif line.startswith('Exec='):
|
||||
command = line[5:].strip()
|
||||
|
||||
return {
|
||||
'name': name,
|
||||
'command': command
|
||||
}
|
||||
|
||||
|
||||
def find_browsers():
|
||||
apps = [
|
||||
'Chrome',
|
||||
'Chromium',
|
||||
'chromium-browser',
|
||||
'firefox',
|
||||
'Firefox',
|
||||
'Google Chrome',
|
||||
'google-chrome',
|
||||
'opera',
|
||||
'Opera',
|
||||
'SeaMonkey',
|
||||
'seamonkey',
|
||||
]
|
||||
paths = [
|
||||
os.path.join(os.getenv('HOME'), '.local/share/applications'),
|
||||
'/usr/local/share/applications',
|
||||
'/usr/share/applications'
|
||||
]
|
||||
suffix = '.desktop'
|
||||
|
||||
results = []
|
||||
for p in paths:
|
||||
for a in apps:
|
||||
fp = os.path.join(p, a) + suffix
|
||||
if os.path.exists(fp):
|
||||
results.append(_read_desktop_file(fp))
|
||||
return results
|
||||
|
||||
|
||||
def listen():
|
||||
receivedMessage = getMessage()
|
||||
if receivedMessage == 'ping':
|
||||
sendMessage({
|
||||
'version': VERSION,
|
||||
'file': os.path.realpath(__file__)
|
||||
})
|
||||
elif receivedMessage == 'find':
|
||||
sendMessage(find_browsers())
|
||||
else:
|
||||
for k, v in os.environ.items():
|
||||
if k.startswith('MOZ_'):
|
||||
try:
|
||||
os.unsetenv(k)
|
||||
except:
|
||||
os.environ[k] = ''
|
||||
|
||||
devnull = open(os.devnull, 'w')
|
||||
subprocess.Popen(receivedMessage, stdout=devnull, stderr=devnull)
|
||||
sendMessage(None)
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
if len(sys.argv) == 2:
|
||||
if sys.argv[1] == 'install':
|
||||
install()
|
||||
sys.exit(0)
|
||||
elif sys.argv[1] == 'find_browsers':
|
||||
print(find_browsers())
|
||||
sys.exit(0)
|
||||
|
||||
allowed_extensions = [
|
||||
'openwith@darktrojan.net',
|
||||
'chrome-extension://cogjlncmljjnjpbgppagklanlcbchlno/',
|
||||
'chrome-extension://fbmcaggceafhobjkhnaakhgfmdaadhhg/',
|
||||
]
|
||||
for ae in allowed_extensions:
|
||||
if ae in sys.argv:
|
||||
listen()
|
||||
sys.exit(0)
|
||||
|
||||
print('Open With native helper, version %s.' % VERSION)
|
|
@ -0,0 +1,111 @@
|
|||
#!/bin/bash
|
||||
########################################################################
|
||||
{ # this ensures the entire script is downloaded #
|
||||
MY_PATH="`dirname \"$0\"`" # relative
|
||||
MY_PATH="`( cd \"$MY_PATH\" && pwd )`" # absolutized and normalized
|
||||
ME="${0##*/}"
|
||||
|
||||
# CHECK not root user !!
|
||||
if [ "$EUID" -eq 0 ]
|
||||
then echo -e "DO NOT EXECUTE AS root. Choose a user for your Astroport Station (we like pi)"
|
||||
exit 1
|
||||
else echo -e "OK $USER, let's go!";
|
||||
fi
|
||||
|
||||
# Ask user password on start
|
||||
sudo true
|
||||
|
||||
## Error funciton
|
||||
err() {
|
||||
echo -e "ERREUR: $1"
|
||||
exit 1
|
||||
}
|
||||
|
||||
# CHECK if daemon is already running
|
||||
if [[ $(ps auxf --sort=+utime | grep -w ipfs | grep -v -E 'color=auto|grep' | tail -n 1 | cut -d " " -f 1) ]]; then
|
||||
ipfs id && echo "ipfs swarm peers: " && ipfs swarm peers
|
||||
echo "ipfs bootstrap list: " && ipfs bootstrap list
|
||||
echo "ipfs daemon already running...!"
|
||||
exit 0
|
||||
fi
|
||||
|
||||
echo -e "Astroport activate IPFS Layer installation..."
|
||||
|
||||
# CHECK node IP isLAN?
|
||||
myIP=$(hostname -I | awk '{print $1}')
|
||||
isLAN=$(echo $myIP | grep -E "/(^127\.)|(^192\.168\.)|(^10\.)|(^172\.1[6-9]\.)|(^172\.2[0-9]\.)|(^172\.3[0-1]\.)|(^::1$)|(^[fF][cCdD])/")
|
||||
|
||||
MACHINE_TYPE=`uname -m`
|
||||
|
||||
# INIT ipfs
|
||||
[[ $isLAN ]] && ipfs init -p lowpower \
|
||||
|| ipfs init -p server
|
||||
|
||||
## Special Xbian init.d config
|
||||
if [[ "$USER" == "xbian" ]]; then
|
||||
sudo cp ~/.zen/astrXbian/.install/templates/ipfs/ipfs-initV.sh /etc/init.d/ipfs
|
||||
sudo chmod 755 /etc/init.d/ipfs
|
||||
sudo touch /var/log/ipfs.log && sudo chown xbian /var/log/ipfs.log
|
||||
else
|
||||
## DEBIAN
|
||||
echo "CREATE SYSTEMD ipfs SERVICE >>>>>>>>>>>>>>>>>>"
|
||||
cat > /tmp/ipfs.service <<EOF
|
||||
[Unit]
|
||||
Description=IPFS daemon
|
||||
After=network.target
|
||||
|
||||
[Service]
|
||||
User=_USER_
|
||||
ExecStart=/usr/local/bin/ipfs daemon --enable-pubsub-experiment --enable-namesys-pubsub --enable-gc
|
||||
Restart=on-failure
|
||||
CPUAccounting=true
|
||||
CPUQuota=60%
|
||||
|
||||
[Install]
|
||||
WantedBy=multi-user.target
|
||||
EOF
|
||||
|
||||
sudo cp -f /tmp/ipfs.service /etc/systemd/system/
|
||||
sudo sed -i "s/_USER_/$USER/g" /etc/systemd/system/ipfs.service
|
||||
|
||||
[[ -d ~/.ipfs ]] && sudo chown -R $USER:$USER ~/.ipfs
|
||||
sudo systemctl daemon-reload
|
||||
sudo systemctl enable ipfs
|
||||
fi
|
||||
|
||||
|
||||
###########################################
|
||||
# ACTIVATE IPFS OPTIONS: #swarm0 INIT
|
||||
###########################################
|
||||
### IMPORTANT !!!!!!! IMPORTANT !!!!!!
|
||||
###########################################
|
||||
# DHT PUBSUB mode
|
||||
ipfs config Pubsub.Router gossipsub
|
||||
# MAXSTORAGE = 1/2 available
|
||||
availableDiskSize=$(df -P ~/ | awk 'NR>1{sum+=$4}END{print sum}')
|
||||
diskSize="$((availableDiskSize / 2))"
|
||||
ipfs config Datastore.StorageMax $diskSize
|
||||
## Activate Rapid "ipfs p2p"
|
||||
ipfs config --json Experimental.Libp2pStreamMounting true
|
||||
ipfs config --json Experimental.P2pHttpProxy true
|
||||
ipfs config --json Swarm.ConnMgr.LowWater 0
|
||||
ipfs config --json Swarm.ConnMgr.HighWater 0
|
||||
ipfs config --json API.HTTPHeaders.Access-Control-Allow-Origin '["http://127.0.0.1:8080", "http://astroport", "https://astroport.com", "https://qo-op.com", "https://tube.copylaradio.com" ]'
|
||||
ipfs config --json API.HTTPHeaders.Access-Control-Allow-Methods '["PUT", "GET", "POST"]'
|
||||
ipfs config --json API.HTTPHeaders.Access-Control-Allow-Credentials '["true"]'
|
||||
|
||||
ipfs config Addresses.API "/ip4/0.0.0.0/tcp/5001"
|
||||
ipfs config Addresses.Gateway "/ip4/0.0.0.0/tcp/8080"
|
||||
|
||||
######### CLEAN DEFAULT BOOTSTRAP TO STAY INVISIBLE ###########
|
||||
ipfs bootstrap rm --all
|
||||
###########################################
|
||||
# BOOTSTRAP NODES ARE ADDED LATER
|
||||
###########################################
|
||||
# AVOID CONFLICT WITH KODI ./.install/.kodi/userdata/guisettings.xml
|
||||
ipfs config Addresses.Gateway "/ip4/0.0.0.0/tcp/8080"
|
||||
|
||||
[[ "$USER" != "xbian" ]] && sudo systemctl restart ipfs
|
||||
|
||||
} # this ensures the entire script is downloaded #
|
||||
# IPFS CONFIG documentation: https://github.com/ipfs/go-ipfs/blob/master/docs/config.md#addressesswarm
|
Loading…
Reference in New Issue