-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathnewupgrade.sh
executable file
·197 lines (171 loc) · 6.52 KB
/
newupgrade.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
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
#!/bin/bash
clear
# Colour settings
red=`tput setaf 1`
green=`tput setaf 2`
reset=`tput sgr0`
cat << "EOF"
,------. ,--. ,--. ,--.,--. ,---. ,------. ,--. ,--.
| .--. '`--',--. ,--.,---. ,--,--, ,-| | ,---. | || | / O \ | .--. '| `.' |
| '--'.',--. \ `' /| .-. :| \' .-. || .-. :| || | | .-. || '--'.'| |'.'| |
| |\ \ | | \ / \ --.| || |\ `-' |\ --.| || | | | | || |\ \ | | | |
`--' '--'`--' `--' `----'`--''--' `---' `----'`--'`--' `--' `--'`--' '--'`--' `--'
EOF
test -f '/etc/os-release' && {
. /etc/os-release
distro=${distro:-$ID}
codename=${codename:-$VERSION_CODENAME}
codename=${codename:-$(echo $VERSION | cut -d '(' -f 2 | cut -d ')' -f 1)}
version=${version:-$VERSION_ID}
}
# CPU arch detetction
arch=$(uname -m)
if [[ $arch == x86_64* ]]; then
cpu="AMD/Intel 64bit Architecture"
elif [[ $arch == i*86 ]]; then
cpu="AMD/Intel 32bit Architecture"
elif [[ $arch == arm* ]]; then
cpu="ARM 32bit Architecture"
elif [[ $arch == aarch64 ]]; then
cpu="ARM 64bit Architecture"
fi
echo ; echo "${red}Rivendell upgrade script for CentOS, Raspberry Pi OS and Debian Buster/Bullseye."
echo "For more information visit github.com/edgeradio993fm/rivendell"
echo "More information and original project source code at rivendellaudio.org${reset}"
echo
#while true; do
#echo -n "Please enter the password for sudo user" ${red}${SUDO_USER:-$USER}${reset} "and press enter..."
#echo
#[ "$UID" -eq 0 ] || exec sudo bash "$0" "$@"
#if su $USER -c true 2>/dev/null; then echo -e "\n${green}Success!${reset}"
#break
#echo
#else
#echo -e "\n${red}Wrong Password. Please try again or ctrl+c to exit.${reset}"
#echo
#fi
#done
# System details section
echo
echo "${green}Your System Details${reset}"
echo "OS:" $distro $version $codename
#$( lsb_release -ds || cat /etc/*release || uname -om ) 2>/dev/null | head -n1
echo "Kernel:" $(uname) $(uname -r)
echo "Arch:" $cpu "($(uname -m))"
echo "Hostname:" $(hostname)
echo "IP Address:" $(hostname -I)
echo "User:" ${SUDO_USER:-$USER}
echo "Uptime:" $(uptime -p | cut -d " " -f2-)
echo
# Detection of Rivendell details
echo "${green}Your Rivendell Installation Details${reset}"
sudo rddbmgr --version
sudo rddbmgr
echo
# Check if database is stored locally
if grep -rnwi '/etc/rd.conf' -e 'Hostname=localhost' 1>/dev/null; then
host="server"
echo "Looks like this system hosts a Rivendell database."
echo "This process will allow you to backup your current database and update your install to the latest schema."
echo "This assumes your installation uses the default database credentials."
echo "${red}Please Note: This process does not backup any audio files.${reset}"
else
host="workstation"
echo "Looks like this system is a Rivendell workstation."
echo "To be safe we will skip the database backup & update process after your installation is upgraded."
fi
echo
# Backup database if stored locally
if [[ "$host" == "server" ]]; then
while true; do
read -r -p "Would you like to backup your database before upgrading? [y/N] " response
if [[ "$response" =~ ^([yY][eE][sS]|[yY])$ ]] ; then
echo ; echo "${green}Backing up your database. Please wait...${reset}"
mkdir ~/DB_BACKUP 2>/dev/null
mysqldump -u rduser -pletmein -h localhost Rivendell > ~/DB_BACKUP/DBBK-$(date +%F).sql
echo ; echo "Done! Your database backup is stored in $HOME/DB_BACKUP/" ; echo
break
elif [[ ! "$response" =~ ^([yY][eE][sS]|[yY]|[nN][oO]|[nN])$ ]] ; then
echo ; echo "${red}Invalid input...${reset}" ; echo
else
echo ; echo "${red}Skipping...${reset}" ; echo
break 1
fi
done
fi
while true; do
read -r -p "Are you sure you would like to upgrade your Rivendell installation? [y/N] " response
if [[ "$response" =~ ^([yY][eE][sS]|[yY])$ ]] ; then
echo ; echo "Continuing..."
break
elif [[ ! "$response" =~ ^([yY][eE][sS]|[yY]|[nN][oO]|[nN])$ ]] ; then
echo ; echo "${red}Invalid input...${reset}" ; echo
else
echo ; echo "${red}Exiting...${reset}" ; echo
exit 1
fi
done
# Package variables
YUM_PACKAGE_NAME="rivendell"
DEB_PACKAGE_NAME="rivendell"
# Check for CentOS and run the upgrade
if cat /etc/*release | grep ^NAME | grep CentOS 1> /dev/null; then
echo
echo "${green}Upgrading package $YUM_PACKAGE_NAME on "$distro${reset}
echo
sudo yum install -y $YUM_PACKAGE_NAME
# Check for Debian
elif cat /etc/*release | grep ^NAME | grep Debian 1> /dev/null || cat /etc/*release | grep ^NAME | grep Raspbian 1> /dev/null; then
# Checking for old repository and updating
echo ; echo "${green}Checking for the old repository and removing if needed...${reset}" ; echo
if sudo sed -i '/7edg/d' /etc/apt/sources.list; then
echo "Done!"
else
echo "Nothing to remove" ; echo
fi
# Add Rivendell ARM repository if needed
echo ; echo "${green}Adding Rivendell on ARM repository to your system...${reset}" ; echo
if cat /etc/*release | grep ^NAME | grep Debian 1> /dev/null | test -f /etc/apt/sources.list.d/7edg-rivendell-arm.list; then
echo "Reopsitory already added. Skipping..." ; echo
else
echo "Adding the reopsitory..." ; echo
curl -1sLf 'https://dl.cloudsmith.io/public/7edg/rivendell-arm/setup.deb.sh' | sudo -E distro=debian bash
echo
fi
# Run the upgrade for Debian
echo
echo "${green}Upgrading package $DEB_PACKAGE_NAME on "$distro${reset}
echo
sudo apt-get update
sudo apt-get install -y $DEB_PACKAGE_NAME
else
echo "Your operating system isn't supported by this upgrade script."
exit 1;
fi
echo ; echo "${green}Restarting system services...${reset}" ; echo
sudo ldconfig
sudo systemctl daemon-reload
sudo systemctl restart rivendell
echo "Done!"
echo
if [[ "$host" == "server" ]]; then
while true; do
read -r -p "Do you want to update your Rivendell database? [y/N] " response
if [[ "$response" =~ ^([yY][eE][sS]|[yY])$ ]] ; then
echo ; echo "${green}Modifying Rivendell database...${reset}"
sudo rddbmgr --modify
break
elif [[ ! "$response" =~ ^([yY][eE][sS]|[yY]|[nN][oO]|[nN])$ ]] ; then
echo ; echo "${red}Invalid input...${reset}"
else
echo ; echo "${red}Database not updated...${reset}"
break 1
fi
done
fi
echo
echo "${green}Your Rivendell installation is now:${reset}"
sudo rddbmgr --version
sudo rddbmgr ; echo
echo "Upgrade complete. Please reboot your system to fully complete the upgrade." ; echo
exit 1