-
Notifications
You must be signed in to change notification settings - Fork 181
/
upgrade.sh
executable file
·158 lines (140 loc) · 4.77 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
#!/bin/bash
# Upgrade the current Allsky release.
[[ -z ${ALLSKY_HOME} ]] && export ALLSKY_HOME="$( realpath "$( dirname "${BASH_ARGV0}" )" )"
ME="$( basename "${BASH_ARGV0}" )"
#shellcheck source-path=.
source "${ALLSKY_HOME}/variables.sh" || exit "${EXIT_ERROR_STOP}"
#shellcheck source-path=scripts
source "${ALLSKY_SCRIPTS}/functions.sh" || exit "${EXIT_ERROR_STOP}"
#shellcheck source-path=scripts
source "${ALLSKY_SCRIPTS}/installUpgradeFunctions.sh" || exit "${EXIT_ERROR_STOP}"
# High-level view of tasks for upgrade:
# Check if ${PRIOR_ALLSKY_DIR} exists.
# If so, warn user they won't be able to save current release.
# Prompt if user wants to carry current settings to new release.
# If so:
# If ${PRIOR_ALLSKY_DIR} exists, error out
# Rename ${ALLSKY_HOME} to ${PRIOR_ALLSKY_DIR}
# Download new release (with optional branch) from GitHub.
# Execute new release's installation script telling it it's an upgrade.
#############
# Changes to install.sh needed:
# * Accept "--upgrade" argument which means we're doing an upgrade.
# - Don't display "**** Welcome to the installer ****"
# - Don't prompt for camera
# - Don't prompt to reboot
# - Don't prompt other things ??
#
#############
# TODO:
# Check for symbolic links
# Allow installing other branches.
#############
############################## functions
function usage_and_exit()
{
local RET=${1}
{
[[ ${RET} -ne 0 ]] && echo -e "${RED}"
echo -e "\nUpgrade the Allsky software to a newer version.."
echo
echo -e "Usage: ${ME} [--help] [--debug] [--branch branch] [--function function]${NC}"
echo
echo "'--help' displays this message and exits."
echo
echo "'--debug' displays debugging information."
echo
echo "'--branch branch' uses 'branch' instead of the production branch."
echo
echo "'--function' executes the specified function and quits."
echo
[[ ${RET} -ne 0 ]] && echo -e "${NC}"
} >&2
exit "${RET}"
}
####################### main part of program
#shellcheck disable=SC2124
ALL_ARGS="$@"
##### Check arguments
OK="true"
HELP="false"
DEBUG="false"; DEBUG_ARG=""
ACTION="upgrade"; WORD="Upgrade" # default
FUNCTION=""
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
;;
--function)
FUNCTION="${2}"
shift
;;
*)
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}"
# shellcheck disable=SC2119
BRANCH="$( get_branch )"
[[ -z ${BRANCH} ]] && BRANCH="${GITHUB_MAIN_BRANCH}"
# TODO: these are here to keep shellcheck quiet while this script is incomplete.
DEBUG="${DEBUG}"
DEBUG_ARG="${DEBUG_ARG}"
FUNCTION="${FUNCTION}"
if [[ "${ACTION}" != "doUpgrade" ]]; then
echo
echo "***********************************************"
echo "*** Welcome to the Allsky Software ${WORD} ***"
echo "***********************************************"
echo
else # we're continuing where we left off, so don't welcome again.
echo -e "* ${GREEN}Continuing the ${WORD}...${NC}"
fi
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.
# Warn the user but let them continue (won't be able to restore from prior).
# Ask user if they want to upgrade in place (i.e., overwrite code),
# or move current code to ${PRIOR_ALLSKY_DIR}.
# If move current code:
# Check for prior Allsky versions:
# If ${PRIOR_ALLSKY_DIR} exist:
# If ${PRIOR_ALLSKY_DIR}-OLDEST exists
# Let user know both old versions exist
# Exit
# Let the user know ${PRIOR_ALLSKY_DIR} exists as FYI:
# echo "Saving prior version in ${PRIOR_ALLSKY_DIR}-OLDEST"
# Move ${PRIOR_ALLSKY_DIR} to ${PRIOR_ALLSKY_DIR}-OLDEST
# Stop allsky
# Move ${ALLSKY_HOME} to ${PRIOR_ALLSKY_DIR}
# 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?
fi