forked from fruxefarms/FruxePi
-
Notifications
You must be signed in to change notification settings - Fork 1
/
update.sh
executable file
·131 lines (106 loc) · 3.02 KB
/
update.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
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
#!/bin/sh
# FRUXEPI DOCKER update
echo ""
echo -e "\e[1m\e[45mFruxePi Update Script\e[0m"
echo -e "\e[1mlatest version:\e[0m \e[37mfrx-pi-v0.3-BETA\e[0m"
echo -e "\e[1mweb:\e[0m \e[37mdocs.fruxe.co\e[0m"
echo ""
# Script arguments
args=$1
# Detect RPi model function
detect_rpi_model()
{
if cat /proc/cpuinfo | grep -q '9000c1' || cat /proc/cpuinfo | grep -q '900092' || cat /proc/cpuinfo | grep -q '900093'; then
rpi_model="armv6"
else
rpi_model="armv7"
fi
}
detect_rpi_model
# Check if git installed function
check_for_git() {
echo "Checking for Git installation..."
git --version
GIT_IS_AVAILABLE=$?
if [ ! $GIT_IS_AVAILABLE -eq 0 ]; then
echo "Installing Git"
sudo apt-get install git
fi
}
# Build Docker function
build_docker()
{
cd docker/$1/
sudo docker-compose up -d --force-recreate
}
# Determine RaspberryPi build architecture
build_containers()
{
if cat /proc/cpuinfo | grep -q '9000c1' || cat /proc/cpuinfo | grep -q '900092' || cat /proc/cpuinfo | grep -q '900093'; then
echo "Deploying Raspberry Pi Zero (ARMv6) compatible containers..."
# Enable Logging
if [ "$args" == "-log" ]; then
build_docker $rpi_model
else
{
build_docker $rpi_model
} &> /dev/null
fi
else
echo "Deploying Raspberry Pi 3 (ARMv7) compatible containers..."
# Enable Logging
if [ "$args" == "-log" ]; then
build_docker $rpi_model
else
{
build_docker $rpi_model
} &> /dev/null
fi
fi
}
# Hard reset function
hard_reset() {
# Remove previous version
echo -e "\e[35mRemoving Previous Version...\e[0m"
sudo docker rm -f frxpi-APACHE frxpi-PHPMYADMIN frxpi-MYSQL
sudo docker system prune -a --volumes
# Run fresh installation script
sudo bash install.sh -log
}
# Run Update Check
update_check() {
# Check if Docker containers deployed are running
echo -e "\e[35mChecking installation...\e[0m"
if docker inspect -f '{{.State.Running}}' 'frxpi-APACHE' | grep -q 'true' && docker inspect -f '{{.State.Running}}' 'frxpi-MYSQL' | grep -q 'true' ; then
echo ""
# Get Raspberry Pi local network IP address
rpi_ip="$(ip addr | grep 'wlan0' | grep -o '[0-9]\{1,3\}\.[0-9]\{1,3\}\.[0-9]\{1,3\}\.[0-9]\{1,3\}' | head -1)"
msg="Visit \e[1mhttp://${rpi_ip}/\e[0m on your local network to access the FruxePi Dashboard."
echo -e "\e[45mUpgrade complete!\e[0m"
echo -e $msg
echo ""
exit 0
else
echo -e "\e[91mError! Upgrade process encountered errors and is incomplete.\e[0m"
exit 1
fi
}
# Run updates function
run_update() {
echo -e "\e[35mRunning update...\e[0m"
# Fetch updates
check_for_git
sudo git fetch --all
git reset --hard origin/master
# Rebuild docker containers
build_containers
# Check update
update_check
}
# Run Hard Reset update
if [ "$args" == "-reset" ]; then
hard_reset
exit 0
fi
# Run normal update]
run_update