forked from Jessecar96/wsjr-data-encoder
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinstall.sh
More file actions
executable file
·126 lines (96 loc) · 3.02 KB
/
install.sh
File metadata and controls
executable file
·126 lines (96 loc) · 3.02 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
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
#!/usr/bin/env bash
if [ "$EUID" -eq 0 ]
then echo "This script must not be run as root"
exit
fi
# Update system
echo "## Updating system ##"
sudo apt-get update
sudo apt-get upgrade -yq
# Install git
echo "## Installing git ##"
sudo apt-get install -yq git
# Check if .dotnet folder exists
echo "## Checking for .NET ##"
if ! command -v dotnet 2>&1 >/dev/null
then
# Install .NET LTS
echo "## Installing .NET ##"
curl -sSL https://dot.net/v1/dotnet-install.sh | bash /dev/stdin --channel 8.0
# Add to PATH
# shellcheck disable=SC2016
echo 'export DOTNET_ROOT=$HOME/.dotnet' >> $HOME/.bashrc
# shellcheck disable=SC2016
echo 'export PATH=$PATH:$HOME/.dotnet' >> $HOME/.bashrc
source "$HOME/.bashrc"
fi
# Enable SPI, this requires reboot
echo "## Enabling SPI ##"
sudo sed -i '/spi=on/s/^#//g' /boot/firmware/config.txt
# git clone project
if [ ! -d $HOME/wsjr-data-encoder ]; then
echo "## Cloning repo ##"
cd $HOME
git clone https://github.com/Jessecar96/wsjr-data-encoder.git $HOME/wsjr-data-encoder
cd $HOME/wsjr-data-encoder
fi
# Get new tags from remote
echo "## Checking out latest version ##"
cd $HOME/wsjr-data-encoder
git fetch --tags
# Reset any changes so there's no issues checking out a new version
git reset --hard
# Get latest tag name
latestTag=$(git describe --tags "$(git rev-list --tags --max-count=1)")
# Checkout latest tag
git checkout -q $latestTag
# Stop service
if [ -f /etc/systemd/system/jrencoder.service ]; then
echo "## Stopping service ##"
sudo systemctl stop jrencoder.service
fi
# Build project
# Must be built as debug, release does not work for some reason
echo "## Building project ##"
mkdir -p $HOME/jrencoder
$HOME/.dotnet/dotnet build --nologo --configuration Debug --property:OutputPath=$HOME/jrencoder/ -property:WarningLevel=0 $HOME/wsjr-data-encoder/JrEncoder.sln
# Check if systemd service exists already
if [ ! -f /etc/systemd/system/jrencoder.service ]; then
echo "## Installing service ##"
first_install=true
else
echo "## Updating service ##"
fi
# Create/update systemd service
cat << EOL | sudo tee /etc/systemd/system/jrencoder.service
[Unit]
Description=Weather Star Data Encoder
After=network.target
[Service]
Type=simple
Restart=always
RestartSec=1
User=${USER}
ExecStart=$HOME/.dotnet/dotnet $HOME/jrencoder/JrEncoder.dll
WorkingDirectory=$HOME/jrencoder/
[Install]
WantedBy=multi-user.target
EOL
# Reload systemctl
sudo systemctl daemon-reload
# Enable at boot
sudo systemctl enable jrencoder.service
# Get wifi IP address
ip=$(ip -4 addr show wlan0 | grep -oP '(?<=inet\s)\d+(\.\d+){3}')
# Check if the service was just installed for the first time
if [ "$first_install" = true ] ; then
# Service was just installed, a reboot is required
printf "\n\nInstall complete!\n"
echo "Reboot your pi to start the program\n"
echo "The configuration UI will be available at http://$ip:5000"
else
echo "## Starting service ##"
sudo systemctl start jrencoder.service
printf "\n\nInstall complete!\n"
echo "The configuration UI is available at http://$ip:5000"
fi