-
-
Notifications
You must be signed in to change notification settings - Fork 18
Expand file tree
/
Copy pathstremio_server_setup.sh
More file actions
93 lines (73 loc) · 2.85 KB
/
stremio_server_setup.sh
File metadata and controls
93 lines (73 loc) · 2.85 KB
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
#!/bin/bash
scripts_dir="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
RUN_AS="$(ls -ld "$scripts_dir" | awk 'NR==1 {print $3}')"
if [ "$USER" != "$RUN_AS" ]
then
echo "This script must run as $RUN_AS, trying to change user..."
exec sudo -u $RUN_AS $0
fi
# Detect architecture
ARCH=$(uname -m)
echo "Detected Architecture: $ARCH"
# If ARM64 or ARMv8, set target for ARM64
if [ "$ARCH" == "aarch64" ]; then
TARGET="aarch64-unknown-linux-gnu"
echo "Compiling for ARM64 or ARMv8..."
# If ARM32 (armv7l), set target for ARM32
elif [ "$ARCH" == "armv7l" ]; then
TARGET="armv7-unknown-linux-gnueabihf"
echo "Compiling for ARM32 (armv7)..."
# If x86_64, set target for x86_64
elif [ "$ARCH" == "x86_64" ]; then
TARGET="x86_64-unknown-linux-gnu"
echo "Compiling for x86_64..."
# Add other architectures as needed
else
echo "Unsupported architecture: $ARCH"
exit 1
fi
sudo apt-get update
sudo apt-get install git libssl-dev libglib2.0-dev libgtk-3-dev nodejs
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh
source /home/${USER}/.cargo/env
mkdir -p /home/${USER}/stremio
git clone https://github.com/shivasiddharth/stremio-service.git /home/${USER}/stremio/stremio-service
cd /home/${USER}/stremio/stremio-service
rustup target add $TARGET
cargo build --target $TARGET --release
# Check if build succeeded
if [ $? -ne 0 ]; then
echo "Build failed! Please fix the errors above before proceeding."
exit 1
fi
# Output location
echo "Build complete. Check the binary in target/$TARGET/release/"
echo "Generating certificates..."
cd /home/${USER}/stremio/stremio-service/resources/certificates
openssl genpkey -algorithm RSA -out stremio.key -pkeyopt rsa_keygen_bits:2048
openssl req -new -key stremio.key -out stremio.csr
openssl x509 -req -days 9999 -in stremio.csr -signkey stremio.key -out stremio.cert
# Define the file to be edited
file="/home/${USER}/stremio/stremio-service/resources/bin/linux/server.js"
# Replace the line with the desired block of code
sed -i "/var sserver = https.createServer(app);/c\
try {\n\
var fs = require(\"fs\");\n\
var https = require(\"https\");\n\
_cr = {\n\
key: fs.readFileSync(\"/home/${USER}/stremio/stremio-service/resources/certificates/stremio.key\", \"utf8\"),\n\
cert: fs.readFileSync(\"/home/${USER}/stremio/stremio-service/resources/certificates/stremio.cert\", \"utf8\")\n\
};\n\
} catch (e) {\n\
console.error(\"Failed to load SSL cert:\", e);\n\
_cr = { };\n\
}\n\
var sserver = https.createServer(_cr, app);" "$file"
echo "Replacement complete in $file."
echo "Copying application files..."
cd "$scripts_dir"
cp main.js package.json icon.png /home/${USER}/stremio/
echo "Installing Electron dependencies..."
cd /home/${USER}/stremio
npm install
echo "Installation complete. Please Reboot."