-
Notifications
You must be signed in to change notification settings - Fork 18
/
installer.sh
executable file
·101 lines (90 loc) · 3.12 KB
/
installer.sh
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
#!/bin/bash
echo "This script is for Linux and macOS, and it's still in testing phases. If you encounter any bugs, please open an issue."
read -p "Press the enter key to continue..."
echo ""
# Check if script is running as root
if [ `whoami` == "root" ]; then
echo "This script cannot be run as root. Please run as a regular user"
exit 1
fi
# Check if config.json file exists
if [ ! -f "config.json" ]; then
echo "Error: config.json file not found. Please make sure it exists in the current directory"
echo "files in current directory:"
ls
exit 1
fi
# Create necessary files if they don't exist
for file in games.txt icons.txt customGameIDs.json; do
if [ ! -e "$(pwd)/$file" ]; then
echo "creating $file"
[ "$file" == "customGameIDs.json" ] && echo "{}" > "$(pwd)/$file" || touch "$(pwd)/$file"
fi
done
echo "Setting up virtual environment"
mkdir venv
cd venv
python3 -m venv .
./bin/python -m pip install --upgrade pip wheel
./bin/python -m pip install -r ../requirements.txt
cd ..
echo ""
echo "Testing if the script works"
echo ""
# Run the Python script in the background
./venv/bin/python ./main.py &
# Get the background process's PID
PYTHON_PID=$!
# Sleep for 2.5 seconds
sleep 2.5
# Kill the background process
kill $PYTHON_PID
echo "Test might've worked, did it spit out any errors?"
echo "Commands executed."
# Create a shell script wrapper for macOS
if [[ "$OSTYPE" == "darwin"* ]]; then
echo '#!/bin/bash' > steam-presence
echo "DIR=\"\$( cd \"\$( dirname \"\${BASH_SOURCE[0]}\" )\" && pwd )\"" >> steam-presence
echo "exec \"\$DIR/venv/bin/python\" \"\$DIR/main.py\"" >> steam-presence
chmod +x steam-presence
fi
# Detect OS and perform OS-specific tasks
if [[ "$OSTYPE" == "linux-gnu"* || "$OSTYPE" == "linux" ]]; then
echo "Setting up service file for Linux"
mkdir -p "$HOME/.config/systemd/user"
sed -e "s~steam-presence/bin/python~steam-presence/venv/bin/python~g" -e "s~/home/deck/steam-presence~$PWD~g" "$PWD/steam-presence.service" > $HOME/.config/systemd/user/steam-presence.service
echo "Starting service"
systemctl --user daemon-reload
systemctl --user --now enable "steam-presence.service"
elif [[ "$OSTYPE" == "darwin"* ]]; then
echo "Setting up launchd plist file for macOS"
PLIST="$HOME/Library/LaunchAgents/com.github.justtemmie.steam-presence.plist"
cat <<EOL > $PLIST
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>Label</key>
<string>Steam Presence</string>
<key>ProgramArguments</key>
<array>
<string>$(pwd)/steam-presence</string>
</array>
<key>RunAtLoad</key>
<true/>
<key>StandardOutPath</key>
<string>$(pwd)/steam-presence.log</string>
<key>StandardErrorPath</key>
<string>$(pwd)/steam-presence-error.log</string>
</dict>
</plist>
EOL
echo "Starting service"
launchctl load $PLIST
else
echo "Unsupported OS. This script is designed for Linux and macOS only."
exit 1
fi
echo "If you encountered any errors with this script, please create an issue on the GitHub page"
echo ""
echo "Script completed."