Skip to content
This repository was archived by the owner on Jan 25, 2022. It is now read-only.

Commit 72b77ac

Browse files
committed
Fixed git errors.
1 parent 2018c87 commit 72b77ac

File tree

1 file changed

+35
-13
lines changed

1 file changed

+35
-13
lines changed

commands/self-update

Lines changed: 35 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -2,31 +2,53 @@
22
#
33
# Update WPLib Box scripts.
44
#
5-
# Be careful with making ANY changes to this script.
6-
# Any changes will potentially alter this script on disk in future versions.
5+
# This script will handle having itself updated by creating a secondary script that contains
6+
# all the git commands.
7+
# This will be exec at the very end ensuring itself wont be changed during the update.
78

89

9-
BASEDIR="${WPLIB_BOX_CLI_DIR}"
10-
BOX_VERSION="`cat /opt/box/version`"
10+
# Don't reference common variables as they may not exist.
11+
WPLIB_BOX_SCRIPTS_REPO="https://github.com/wplib/box-scripts"
12+
WPLIB_BOX_CLI_DIR="/opt/box"
13+
DEFAULT_VERSION="master"
14+
1115

1216
# Determine version to run.
1317
if [ "$1" == "" ]
1418
then
15-
VERSION="$BOX_VERSION"
19+
VERSION="`cat ${WPLIB_BOX_CLI_DIR}/version`"
20+
if [ "$DEFAULT_VERSION" == "" ]
21+
then
22+
VERSION=${DEFAULT_VERSION}
23+
fi
1624
else
1725
VERSION="$1"
1826
fi
1927

28+
2029
# Pull from GitHub.
21-
if [ -d ${BASEDIR} ]
30+
if [ -d ${WPLIB_BOX_CLI_DIR} ]
2231
then
23-
cd ${BASEDIR}
24-
sudo git clean -q -d -fx "" 2>/dev/null
25-
sudo git reset -q --hard $VERSION 2>/dev/null
26-
sudo git pull 2>/dev/null
27-
sudo git checkout -q $VERSION 2>/dev/null
32+
cat <<EOF > /tmp/self-update.$$
33+
cd ${WPLIB_BOX_CLI_DIR}
34+
echo "# WPLib-Box: Updating /opt/box with version ${VERSION}"
35+
sudo git clean -q -d -fx "" > /dev/null
36+
sudo git reset -q --hard ${VERSION} > /dev/null
37+
sudo git pull -q ${WPLIB_BOX_SCRIPTS_REPO} > /dev/null
38+
sudo git checkout -q ${VERSION} > /dev/null
39+
echo $VERSION > /opt/box/version
40+
echo "Done"
41+
exec rm -f /tmp/self-update.$$
42+
EOF
2843
else
29-
sudo git clone "#{WPLIB_BOX_SCRIPTS_REPO}" "${WPLIB_BOX_CLI_DIR}"
44+
cat <<EOF > /tmp/self-update.$$
45+
echo "# WPLib-Box: Initializing /opt/box with version ${VERSION}"
46+
sudo git clone -q ${WPLIB_BOX_SCRIPTS_REPO} ${WPLIB_BOX_CLI_DIR} > /dev/null
47+
echo $VERSION > /opt/box/version
48+
echo "Done"
49+
exec rm -f /tmp/self-update.$$
50+
EOF
3051
fi
31-
echo $VERSION > /opt/box/version
3252

53+
chmod a+x /tmp/self-update.$$
54+
exec /tmp/self-update.$$

0 commit comments

Comments
 (0)