This repository has been archived by the owner on Dec 16, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathmewdeko-latest-installer
executable file
·140 lines (102 loc) · 4.82 KB
/
mewdeko-latest-installer
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
#!/bin/bash
#
# Download and update Mewdeko.
#
# Comment Key:
# A.1. - Due to permission errors cropping up every now and then, especially when the
# installer is executed with root privilege then later as a non-root user, it's
# necessary to make sure that '/tmp/NuGetScratch' and '/home/$USER/.nuget' are
# owned by the user that the installer is currently being run under.
#
########################################################################################
#### [ Variables ]
export DOTNET_CLI_TELEMETRY_OPTOUT=1 # Used when compiling code.
service_is_active=false
current_creds="Mewdeko/src/Mewdeko/credentials.json"
new_creds="Mewdeko_tmp/Mewdeko/src/Mewdeko/credentials.json"
current_database="Mewdeko/src/Mewdeko/bin/Release/net6.0/data/Mewdeko.db"
new_database="Mewdeko_tmp/Mewdeko/src/Mewdeko/bin/Release/net6.0/data/Mewdeko.db"
current_data="Mewdeko/src/Mewdeko/data"
new_data="Mewdeko_tmp/Mewdeko/src/Mewdeko/data"
#### End of [ Variables ]
########################################################################################
#### [ Main ]
read -rp "We will now download/update Mewdeko. Press [Enter] to begin."
########################################################################################
#### [[ Stop Service ]]
## Stop the service if it's currently running.
if [[ $_SERVICE_STATUS = "active" ]]; then
service_is_active=true
_STOP_SERVICE
fi
#### End of [[ Stop Service ]]
########################################################################################
#### [[ Create Backup and Update ]]
## Create a temporary folder to download Mewdeko into.
mkdir Mewdeko_tmp
cd Mewdeko_tmp || _STDERR "Failed to change working directory" "1"
echo "Downloading Mewdeko into 'Mewdeko_tmp'..."
git clone -b "$_BOT_INSTALL_VERSION" --recursive --depth 1 https://github.com/Sylveon76/Mewdeko \
|| _STDERR "Failed to download Mewdeko" "1"
## A.1.
if [[ -d /tmp/NuGetScratch ]]; then
echo "Modifying ownership of '/tmp/NuGetScratch'..."
sudo chown -R "$USER":"$USER" /tmp/NuGetScratch \
|| _STDERR "Failed to to modify the ownership of '/tmp/NuGetScratch'" "1"
fi
## A.1.
if [[ -d /home/$USER/.nuget ]]; then
echo "Modifying ownership of '/home/$USER/.nuget'..."
sudo chown -R "$USER":"$USER" /home/"$USER"/.nuget \
|| _STDERR "Failed to to modify the ownership of '/home/$USER/.nuget'..." "1"
fi
echo "Building Mewdeko..."
# shellcheck disable=SC2015
cd Mewdeko/src/Mewdeko \
&& dotnet build -c Release \
&& cd "$_WORKING_DIR" \
|| _STDERR "Failed to build Mewdeko" "1"
## Move credentials, database, and other data to the new version of Mewdeko.
if [[ -d Mewdeko_tmp/Mewdeko && -d Mewdeko ]]; then
echo "Copying 'credentials.json' to the new version..."
cp -f "$current_creds" "$new_creds" &>/dev/null
echo "Copying database to the new version..."
cp -RT "$current_database" "$new_database" &>/dev/null
echo "Copying other data to the new version..."
#### The end-user will have to manually re-add their strings after each update as
#### updates may cause a number of strings to become obsolete, changed, etc.
#### However, old user's strings will be backed up as strings_old.
## Back up new strings to reverse rewrite.
rm -rf "$new_data"/strings_new &>/dev/null
mv -fT "$new_data"/strings "$new_data"/strings_new
## Delete old string backups.
rm -rf "$current_data"/strings_old &>/dev/null
rm -rf "$current_data"/strings_new &>/dev/null
# Back up new aliases to reverse rewrite.
mv -f "$new_data"/aliases.yml "$new_data"/aliases_new.yml
# Move old data folder contents (and overwrite).
cp -RT "$current_data" "$new_data"
# Back up old aliases.
mv -f "$new_data"/aliases.yml "$new_data"/aliases_old.yml
# Restore new aliases.
mv -f "$new_data"/aliases_new.yml "$new_data"/aliases.yml
# Back up old strings.
mv -f "$new_data"/strings "$new_data"/strings_old
# Restore new strings.
mv -f "$new_data"/strings_new "$new_data"/strings
rm -rf Mewdeko_old && mv -f Mewdeko Mewdeko_old
fi
mv Mewdeko_tmp/Mewdeko . && rmdir Mewdeko_tmp
#### End of [[ Create Backup and Update ]]
########################################################################################
#### [[ Clean Up and Present Results ]]
echo -e "\n${_GREEN}Finished downloading/updating Mewdeko${_NC}"
if "$service_is_active"; then
echo "${_CYAN}NOTE: '$_SERVICE_NAME' was stopped to update Mewdeko and" \
"needs to be started using one of the run modes in the installer menu${_NC}"
fi
read -rp "Press [Enter] to apply any existing changes to the installers"
#### End of [[ Clean Up and Present Results ]]
########################################################################################
#### End of [ Main ]
########################################################################################