-
Notifications
You must be signed in to change notification settings - Fork 180
/
upgrade.sh
executable file
·225 lines (196 loc) · 6.8 KB
/
upgrade.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
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
#!/bin/bash
# Upgrade an existing release of Allsky.
# This includes upgrading code as well as configuration files.
############################
# TODO: This file currently just checks if there's a newer version on GitHub,
# and if so, it grabs the newer version and executes it.
# We did this so we could distribute a basic script with the new release,
# but didn't have time to fully complete and test this script.
############################
# TODO: Move variables and functions used by this script and install.sh into
# scripts/installUpgradeFunctions.sh, including functions in functiton.sh that
# are only used by upgrade.sh and install.sh.
############################
[[ -z ${ALLSKY_HOME} ]] && export ALLSKY_HOME="$(realpath "$(dirname "${BASH_ARGV0}")")"
ME="$(basename "${BASH_ARGV0}")"
#shellcheck disable=SC2086 source-path=.
source "${ALLSKY_HOME}/variables.sh" || exit ${ALLSKY_ERROR_STOP}
#shellcheck disable=SC2086 source-path=scripts
source "${ALLSKY_SCRIPTS}/functions.sh" || exit ${ALLSKY_ERROR_STOP}
if [[ ${EUID} -eq 0 ]]; then
display_msg error "This script must NOT be run as root, do NOT use 'sudo'."
exit 1
fi
#shellcheck disable=SC2086
cd "${ALLSKY_HOME}" || exit ${ALLSKY_ERROR_STOP}
####
usage_and_exit()
{
RET=${1}
if [[ ${RET} -eq 0 ]]; then
C="${YELLOW}"
else
C="${RED}"
fi
# Don't show the "--newer", "--no-check", or "--force-check" options since users
# should never use them.
# TODO: Also don't show future --doUpgrade and --doUpgradeInPlace options.
echo
echo -e "${C}Usage: ${ME} [--help] [--debug] [--restore] [--function function]${NC}"
echo
echo "'--help' displays this message and exits."
echo
echo "'--debug' displays debugging information."
echo
echo "'--restore' restores a previously upgraded Allsky. Rarely needed."
echo
echo "'--function' executes the specified function and quits."
echo
#shellcheck disable=SC2086
exit ${RET}
}
####################### main part of program
#shellcheck disable=SC2124
ALL_ARGS="$@"
##### Check arguments
OK="true"
HELP="false"
DEBUG="false"
DEBUG_ARG=""
NEWER="false"
ACTION="upgrade"
WORD="Upgrade"
FUNCTION=""
FORCE_CHECK="true" # Set to "true" to ALWAYS do the version check
while [ $# -gt 0 ]; do
ARG="${1}"
case "${ARG}" in
--help)
HELP="true"
;;
--debug)
DEBUG="true"
DEBUG_ARG="${ARG}" # we can pass this to other scripts
;;
--newer)
NEWER="true"
;;
--restore)
ACTION="restore"
WORD="Restorer"
;;
--function)
FUNCTION="${2}"
shift
;;
--no-check)
FORCE_CHECK="false"
;;
--force-check)
FORCE_CHECK="true"
;;
*)
display_msg error "Unknown argument: '${ARG}'."
OK="false"
;;
esac
shift
done
[[ ${HELP} == "true" ]] && usage_and_exit 0
[[ ${OK} == "false" || $# -ne 0 ]] && usage_and_exit 1
[[ ${DEBUG} == "true" ]] && echo "Running: ${ME} ${ALL_ARGS}"
BRANCH="$( get_branch )"
[[ -z ${BRANCH} ]] && BRANCH="${GITHUB_MAIN_BRANCH}"
# Unless forced to, only do the version check if we're on the main branch,
# not on development branches, because when we're updating this script we
# don't want to have the updates overwritten from an older version on GitHub.
if [[ ${FORCE_CHECK} == "true" || ${BRANCH} == "${GITHUB_MAIN_BRANCH}" ]]; then
CURRENT_SCRIPT="${ALLSKY_HOME}/${ME}"
if [[ ${NEWER} == "true" ]]; then
# This is the newer version
echo "[${CURRENT_SCRIPT}] was replaced by newer version from GitHub."
cp "${BASH_ARGV0}" "${CURRENT_SCRIPT}"
chmod 775 "${CURRENT_SCRIPT}"
else
# See if there's a newer version of this script; if so, download it and execute it.
BRANCH="$(getBranch)" || exit 2
NEWER_SCRIPT="/tmp/${ME}"
checkAndGetNewerFile --branch "${BRANCH}" "${CURRENT_SCRIPT}" "${ME}" "${NEWER_SCRIPT}"
RET=$?
[[ ${RET} -eq 2 ]] && exit 2
if [[ ${RET} -eq 1 ]]; then
exec "${NEWER_SCRIPT}" --newer "${ALL_ARGS}"
# Does not return
fi
fi
fi
# TODO: these are here to keep shellcheck quiet.
DEBUG="${DEBUG}"
DEBUG_ARG="${DEBUG_ARG}"
FUNCTION="${FUNCTION}"
WORD="${WORD}"
#shellcheck disable=SC2086,SC1091 # file doesn't exist in GitHub
source "${ALLSKY_CONFIG}/config.sh" || exit ${ALLSKY_ERROR_STOP}
#shellcheck disable=SC2086,SC1091 # file doesn't exist in GitHub
source "${ALLSKY_CONFIG}/ftp-settings.sh" || exit ${ALLSKY_ERROR_STOP}
if [[ ${ACTION} == "upgrade" ]]; then
:
# First part of upgrade, executed by user in ${ALLSKY_HOME}.
# Make sure we can upgrade:
# If config/ does NOT exist, the user hasn't installed Allsky.
# Tell the user.
# Invoke install.sh, or exit ?????
# Ask user if they want to upgrade in place (i.e., overwrite code),
# or move current code to ${ALLSKY_HOME}-OLD.
# If move current code:
# Check for prior Allsky versions:
# If ${ALLSKY_HOME}-OLD exist:
# If ${ALLSKY_HOME}-OLDEST exists
# Let user know both old versions exist
# Exit
# Let the user know ${ALLSKY_HOME}-OLD exists as FYI:
# echo "Saving prior version in ${ALLSKY_HOME}-OLDEST"
# Move ${ALLSKY_HOME}-OLD to ${ALLSKY_HOME}-OLDEST
# Stop allsky
# Move ${ALLSKY_HOME} to ${ALLSKY_HOME}-OLD
# cd
# Git new code into ${ALLSKY_HOME}
# cd ${ALLSKY_HOME}
# Run: ./install.sh $DEBUG_ARG .... --doUpgrade
# --doUpgrade tells it to use prior version without asking and to
# not display header, change messages to say "upgrade", not "install", etc.
# ?? anything else?
# Else (upgrade in place)
# Git new code into ${ALLSKY_HOME}-NEW
# ?? move ${ALLSKY_HOME}/upgrade.sh to ${ALLSKY_HOME}/upgrade-OLD.sh
# exec ${ALLSKY_HOME}/upgrade-OLD.sh
# Copy (don't move) everything from ${ALLSKY_HOME}-NEW to ${ALLSKY_HOME}
# Run: install.sh ${ALL_ARGS} --doUpgradeInPlace
# --doUpgradeInPlace tells it to use prior version without asking and to
# not display header, change messages to say "upgrade", not "install", etc.
# How is --doUpgradeInPlace different from --doUpgrade ??
# ?? anything else?
elif [[ ${ACTION} == "restore" ]]; then
:
# If running in $ALLSKY_HOME # us 1st time through
# Make sure ${ALLSKY_HOME}-OLD exists
# If not, warn user and exit:
# "No prior version to restore from: ${ALLSKY_HOME}-OLD does not exist".
# cp ${ME} /tmp
# chmod 775 /tmp/${ME}
# exec /tmp/${ME} --restore ${ALL_ARGS} $ALLSKY_HOME
# Else # running from /tmp - do the actual work
# Stop allsky
# mv $ALLSKY_HOME} ${ALLSKY_HOME}-new_tmp
# mv ${ALLSKY_HOME}-OLD $ALLSKY_HOME
# move images from ${ALLSKY_HOME}-new_tmp to $ALLSKY_HOME
# move darks from ${ALLSKY_HOME}-new_tmp to $ALLSKY_HOME
# copy scripts/endOfNight_additionalSteps.sh from ${ALLSKY_HOME}-new_tmp to $ALLSKY_HOME
# Prompt the user if they want to:
# restore their old "images" folder (if there's anything in it)
# restore their old "darks" folder (if there's anything in it)
# restore their old configuration settings
# (config.sh, ftp-settings.sh, scripts/endOfNight_additionalSteps.sh)
# upgrade their WebUI (if installed)
# upgrade their Website (if installed)
fi