Skip to content

Commit 9b77088

Browse files
authored
Move ds_version and ds_update_available to main.sh (#1966)
`run_script 'ds-version'` was failing on fresh install because the `.scripts` folder wasn't there yet. Moved the function to `main.sh` to fix that. Did the same for `ds_update_available`.
1 parent b63c251 commit 9b77088

File tree

4 files changed

+32
-50
lines changed

4 files changed

+32
-50
lines changed

.scripts/ds_update_available.sh

Lines changed: 0 additions & 21 deletions
This file was deleted.

.scripts/ds_version.sh

Lines changed: 0 additions & 24 deletions
This file was deleted.

.scripts/update_self.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ commands_update_self() {
5353
pushd "${SCRIPTPATH}" &> /dev/null || fatal "Failed to change directory.\nFailing command: ${F[C]}push \"${SCRIPTPATH}\""
5454
if [[ -z ${BRANCH-} ]]; then
5555
BRANCH="$(git branch --show)"
56-
if ! run_script 'ds_update_available'; then
56+
if ! ds_update_available; then
5757
notice "${APPLICATION_NAME} is already up to date on branch ${BRANCH}."
5858
return
5959
fi

main.sh

Lines changed: 31 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -118,16 +118,43 @@ run_script() {
118118
fi
119119
}
120120

121+
ds_version() {
122+
local Branch Version
123+
pushd "${SCRIPTPATH}" &> /dev/null || fatal "Failed to change directory.\nFailing command: ${F[C]}pushd \"${SCRIPTPATH}\""
124+
git fetch --quiet &> /dev/null || true
125+
126+
# Get the branch
127+
Branch="$(git symbolic-ref --short -q HEAD 2> /dev/null || true)"
128+
# Get the current tag. If no tag, use the commit instead.
129+
Version="$(git describe --tags --exact-match 2> /dev/null || true)"
130+
if [[ -z ${Version-} ]]; then
131+
Version="commit $(git rev-parse --short HEAD 2> /dev/null || true)"
132+
fi
133+
134+
echo "${Branch-} ${Version-}"
135+
popd &> /dev/null
136+
}
137+
ds_update_available() {
138+
pushd "${SCRIPTPATH}" &> /dev/null || fatal "Failed to change directory.\nFailing command: ${F[C]}pushd \"${SCRIPTPATH}\""
139+
git fetch --quiet &> /dev/null
140+
local -i result=0
141+
# shellcheck disable=SC2319 # This $? refers to a condition, not a command. Assign to a variable to avoid it being overwritten.
142+
[[ $(git rev-parse HEAD 2> /dev/null) != $(git rev-parse '@{u}' 2> /dev/null) ]] || result=$?
143+
popd &> /dev/null
144+
return ${result}
145+
}
146+
147+
121148
declare -x APPLICATION_VERSION
122-
APPLICATION_VERSION="$(run_script 'ds_version')"
149+
APPLICATION_VERSION="$(ds_version)"
123150
readonly APPLICATION_VERSION
124151

125152
usage() {
126153
local APPLICATION_HEADING="${APPLICATION_NAME}"
127154
if [[ ${APPLICATION_VERSION-} ]]; then
128155
APPLICATION_HEADING+=" [${APPLICATION_VERSION}]"
129156
fi
130-
if run_script 'ds_update_available'; then
157+
if ds_update_available; then
131158
APPLICATION_HEADING+=" (Update Available)"
132159
fi
133160
cat << EOF
@@ -633,7 +660,7 @@ _dialog_() {
633660

634661
CleanRightBackTitle=''
635662
RightBackTitle=''
636-
if run_script 'ds_update_available'; then
663+
if ds_update_available; then
637664
CleanRightBackTitle="(Update Available)"
638665
RightBackTitle="${DC[ApplicationUpdateBrackets]}(${DC[ApplicationUpdate]}Update Available${DC[ApplicationUpdateBrackets]})${DC[NC]}"
639666
fi
@@ -810,7 +837,7 @@ main() {
810837
run_script 'symlink_ds'
811838
# Apply the GUI theme
812839
run_script 'apply_theme'
813-
if run_script 'ds_update_available'; then
840+
if ds_update_available; then
814841
notice "An update to ${APPLICATION_NAME} is available. Run 'ds -u' to update."
815842
fi
816843
# Execute CLI Argument Functions

0 commit comments

Comments
 (0)