Skip to content

Commit 12a9fa8

Browse files
committed
Refactor install.sh to remove unnecessary code and improve installation process
1 parent f29e3f6 commit 12a9fa8

File tree

1 file changed

+2
-66
lines changed

1 file changed

+2
-66
lines changed

bin/install.sh

Lines changed: 2 additions & 66 deletions
Original file line numberDiff line numberDiff line change
@@ -22,68 +22,6 @@
2222
fi
2323
}
2424

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

13876
PHPVM_CONFIG_STR="
139-
# Load PHPVM if necessary (this will allow phpvm to be invoked manually)
140-
if [ -s \"\$PHPVM_DIR/bin/phpvm\" ]; then
141-
export PATH=\"\$PHPVM_DIR/bin:\$PATH\"
142-
fi
77+
# Load PHPVM if it exists (similar to nvm)
78+
[[ -s \"\$PHPVM_DIR/index.js\" ]] && export PATH=\"\$PHPVM_DIR/bin:\$PATH\" && node \"\$PHPVM_DIR/index.js\"
14379
"
14480

14581
if [ -n "$PHPVM_PROFILE" ]; then

0 commit comments

Comments
 (0)