forked from XX-net/XX-Net
-
Notifications
You must be signed in to change notification settings - Fork 0
/
start
executable file
·113 lines (96 loc) · 2.77 KB
/
start
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
#!/bin/bash
SCRIPTPATH="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
cd "$SCRIPTPATH"
if python -V | grep -q "Python 3" ;then
PYTHON="python2"
else
PYTHON="python"
fi
if [ -f code/version.txt ]; then
VERSION=`cat code/version.txt`
else
VERSION="default"
fi
if [ ! -f "code/$VERSION/launcher/start.py" ]; then
VERSION="default"
fi
echo "XX-Net version:$VERSION"
# launch xx-net service by ignore hungup signal
function launchWithNoHungup() {
nohup ${PYTHON} code/${VERSION}/launcher/start.py >/dev/null 2>&1 &
}
# launch xx-net service by hungup signal
function launchWithHungup() {
${PYTHON} code/${VERSION}/launcher/start.py
}
# get operating system name
os_name=`uname -s`
# check command avalibility
function has_command() {
command -v $1 > /dev/null
}
# Install Packages
if [ $os_name = 'Linux' ]; then
if ! ${PYTHON} -c 'import OpenSSL' 2> /dev/null; then
echo 'Installing pyOpenSSL for your system... Please type in your password if requested'
if has_command zypper; then
# openSUSE
sudo zypper in -y python-pyOpenSSL
elif has_command apt-get; then
# Debian or Debian-like
sudo apt-get install -y python-openssl
elif has_command dnf; then
# Fedora
sudo dnf install -y pyOpenSSL
elif has_command yum; then
# RedHat
sudo yum install -y pyOpenSSL
elif has_command pacman; then
# ArchLinux
sudo pacman -S --noconfirm openssl python2-pyopenssl
fi
fi
fi
# create a desktop startup file when the distro is Ubuntu.
function createDesktopStartup() {
DESKFILE='XX-Net.desktop'
if [[ -f $DESKFILE ]]; then
echo "$DESKFILE already exists"
return
else
echo "$DESKFILE does not exist,create a new one"
fi
NAME="XX-Net"
EXEC="$SCRIPTPATH/start > /dev/null"
ICON="$SCRIPTPATH/code/default/launcher/web_ui/favicon.ico"
TERMINAL="false"
TYPE="Application"
CATEGORIES="Development"
echo "[Desktop Entry]" >> $DESKFILE
echo "Version=$VERSION" >> $DESKFILE
echo "Name=$NAME" >> $DESKFILE
echo "Exec=$EXEC" >> $DESKFILE
echo "Terminal=$TERMINAL" >> $DESKFILE
echo "Icon=$ICON" >> $DESKFILE
echo "Type=$TYPE" >> $DESKFILE
echo "Categories=$CATEGORIES" >> $DESKFILE
chmod 744 $DESKFILE
DESKDIR=~/Desktop/
cp $DESKFILE $DESKDIR
if [[ -d $DESKDIR ]]; then
cp $DESKFILE $DESKDIR
else
echo "$DESKDIR does not exist"
fi
}
DIS=`cat /etc/issue 2> /dev/null`
if [[ $DIS == *Ubuntu* ]]; then
createDesktopStartup
fi
# Start Application
if [ $os_name = 'Darwin' ] && ! [ "$1" = '-hungup' ]; then
PYTHON="/usr/bin/python2.7"
launchWithNoHungup
else
launchWithHungup
fi