Skip to content

Commit 8e125a8

Browse files
committed
Refactor install.sh to add latest version fetching and improve installation process
1 parent 12a9fa8 commit 8e125a8

File tree

1 file changed

+67
-0
lines changed

1 file changed

+67
-0
lines changed

bin/install.sh

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,73 @@
2222
fi
2323
}
2424

25+
phpvm_latest_version() {
26+
# Fetch the latest version from GitHub, if it exists
27+
latest_version=$(curl -s https://api.github.com/repos/Thavarshan/phpvm/releases/latest | grep '"tag_name":' | sed -E 's/.*"([^"]+)".*/\1/')
28+
29+
# Default to 'main' if no release is found
30+
if [ -z "$latest_version" ]; then
31+
phpvm_echo "main"
32+
else
33+
phpvm_echo "$latest_version"
34+
fi
35+
}
36+
37+
phpvm_download() {
38+
if phpvm_has "curl"; then
39+
curl --fail --compressed -q "$@"
40+
elif phpvm_has "wget"; then
41+
ARGS=$(phpvm_echo "$@" | command sed -e 's/--progress-bar /--progress=bar /' \
42+
-e 's/--compressed //' -e 's/--fail //' -e 's/-L //' -e 's/-I /--server-response /' \
43+
-e 's/-s /-q /' -e 's/-sS /-nv /' -e 's/-o /-O /' -e 's/-C - /-c /')
44+
eval wget $ARGS
45+
fi
46+
}
47+
48+
install_phpvm_from_git() {
49+
local INSTALL_DIR
50+
INSTALL_DIR="$(phpvm_install_dir)"
51+
local PHPVM_VERSION
52+
PHPVM_VERSION="${PHPVM_INSTALL_VERSION:-$(phpvm_latest_version)}"
53+
54+
if [ -d "$INSTALL_DIR/.git" ]; then
55+
phpvm_echo "=> phpvm is already installed in $INSTALL_DIR, updating using git"
56+
command printf '\r=> '
57+
else
58+
phpvm_echo "=> Downloading phpvm from git to '$INSTALL_DIR'"
59+
mkdir -p "${INSTALL_DIR}"
60+
command git clone "https://github.com/Thavarshan/phpvm.git" --depth=1 "${INSTALL_DIR}" || {
61+
phpvm_echo >&2 'Failed to clone phpvm repo. Please report this!'
62+
exit 1
63+
}
64+
fi
65+
66+
# Checkout the latest release or 'main' if no releases
67+
command git -C "$INSTALL_DIR" checkout "$PHPVM_VERSION" || {
68+
phpvm_echo >&2 "Failed to checkout the version $PHPVM_VERSION. Please report this!"
69+
exit 1
70+
}
71+
72+
phpvm_echo "=> Cleaning up git repository"
73+
command git -C "$INSTALL_DIR" gc --auto --aggressive --prune=now || {
74+
phpvm_echo >&2 'Failed to clean up git repository. Please report this!'
75+
exit 1
76+
}
77+
78+
if ! phpvm_has "node"; then
79+
phpvm_echo "Node.js is required to run phpvm. Please install Node.js and try again."
80+
exit 1
81+
fi
82+
83+
phpvm_echo "=> Installing Node.js dependencies"
84+
command npm install --prefix "$INSTALL_DIR" || {
85+
phpvm_echo >&2 'Failed to install Node.js dependencies. Please report this!'
86+
exit 1
87+
}
88+
89+
phpvm_create_launcher
90+
}
91+
2592
phpvm_create_launcher() {
2693
local INSTALL_DIR
2794
INSTALL_DIR="$(phpvm_install_dir)"

0 commit comments

Comments
 (0)