This repository has been archived by the owner on Dec 29, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathe.upgrade
executable file
·87 lines (74 loc) · 2.61 KB
/
e.upgrade
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
#!/bin/bash
#!shellcheck disable=SC1090,SC1091,2174
source e.bash.min new || exit $?
strict.set on
on.exit xcleanup
# installation source code directory
declare DESTDIR=/usr/share/e.bash/
# temporary installation source code directory
declare TMPDESTDIR=/tmp/usr/share/
main() {
# Confirm location of TMPDESTDIR
if [[ ! -d $TMPDESTDIR ]]; then
if [[ -f ${ENTITIES:-/lib/include/e.bash/}.e.production.dir ]]; then
TMPDESTDIR=$(< /lib/include/e.bash/.e.production.dir)
fi
if [[ ! -d $TMPDESTDIR ]]; then
:
fi
fi
msg.info "Production Directory: $TMPDESTDIR"
msg.yn "Check for new version of e.bash?" || exit 1
msg.info "Getting lastest version of e.bash from github..."
mkdir --mode=0755 -p "$TMPDESTDIR"
cd "$TMPDESTDIR" || exit $?
rm -rf "${TMPDESTDIR:=jUnK}/e.bash"
sudo git clone 'https://github.com/OkusiAssociates/entities.bash.git' \
|| { >&2 echo "Not Updated."; exit $?; }
(
local tmp=${_ent_VERSION}
source e.bash/e.d/e.version.bash || exit $?
msg.info '' \
"Currently Installed Version: $tmp" \
"New Version: ${_ent_VERSION}" ''
if [[ $tmp == "${_ent_VERSION}" ]]; then
msg.yn --warning \
"Versions are the same. Would you like to re-install anyway?" || exit $?
fi
)
# FROM e.install
# Do BACKUP of existing $ENTITIES directory
if [[ -d "$ENTITIES" ]]; then
local bdir="$ENTITIES.old/e.bash-${_ent_VERSION:-$(date +%F)}"
msg.sys "Backing up current version of e.bash" "to [$bdir.zip]"
#shellcheck disable=SC2174
mkdir -p --mode=770 "$ENTITIES".old || msg.die "Could not create $ENTITIES.old"
mv "$ENTITIES" "$bdir" || msg.die "$(errno $?)" "Could not move [${ENTITIES}] to [${bdir}]"
( cd "$(dirname "$bdir")" || msg.die "cd $(dirname "$bdir") failed"
/usr/bin/zip --quiet --recurse-paths \
"$bdir".zip "$(basename "$bdir")"/* || msg.die "Zip failed for $bdir.zip"
) || msg.err "Backup zip failed!"
rm -rf "${bdir:-jUnK}" || msg.die "'$bdir' could not be removed"
# get rid of old backups; on if more than 30 backups, and only those more than 30 days old
if (( $(find "$ENTITIES".old -maxdepth 1 -type f -name "*.zip" | wc -l) > 30 )); then
find "$ENTITIES".old -not -newermt '30 days ago' -delete
fi
unset bdir
fi
DESTDIR="/tmp/$ENTITIES"
# remove current ENTITIES
if [[ -d "$DESTDIR" ]]; then
rm -rf "${DESTDIR:-jUnK}"
fi
mkdir -p "$DESTDIR"
rsync -avql "$TMPDESTDIR/e.bash/" "${DESTDIR:-jUnK}/" || exit $?
cd "$DESTDIR" || exit
#"$DESTDIR"/e.install -i || exit $?
msg.info "e.bash has been installed in $DESTDIR"
}
xcleanup() {
echo >&2 "Deleting $TMPDESTDIR/"
rm -rf ${TMPDESTDIR:-jUnK}
}
main "$@"
#fin