|
1 | 1 | #!/usr/bin/env bash
|
2 | 2 |
|
3 |
| -{ # this ensures the entire script is downloaded # |
4 |
| - |
| 3 | +{ |
5 | 4 | phpvm_has() {
|
6 | 5 | type "$1" >/dev/null 2>&1
|
7 | 6 | }
|
|
22 | 21 | fi
|
23 | 22 | }
|
24 | 23 |
|
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 | 24 | phpvm_download() {
|
34 | 25 | if phpvm_has "curl"; then
|
35 | 26 | curl --fail --compressed -q "$@"
|
36 | 27 | 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 /') |
| 28 | + ARGS=$(phpvm_echo "$@" | command sed -e 's/--progress-bar /--progress=bar /' -e 's/--compressed //' -e 's/--fail //' -e 's/-L //' -e 's/-I /--server-response /' -e 's/-s /-q /' -e 's/-sS /-nv /' -e 's/-o /-O /' -e 's/-C - /-c /') |
40 | 29 | eval wget $ARGS
|
41 | 30 | fi
|
42 | 31 | }
|
43 | 32 |
|
44 | 33 | install_phpvm_from_git() {
|
45 | 34 | local INSTALL_DIR
|
46 | 35 | INSTALL_DIR="$(phpvm_install_dir)"
|
47 |
| - local PHPVM_VERSION |
48 |
| - PHPVM_VERSION="${PHPVM_INSTALL_VERSION:-$(phpvm_latest_version)}" |
49 | 36 |
|
50 | 37 | if [ -d "$INSTALL_DIR/.git" ]; then
|
51 | 38 | phpvm_echo "=> phpvm is already installed in $INSTALL_DIR, updating using git"
|
52 |
| - command printf '\r=> ' |
| 39 | + command git -C "$INSTALL_DIR" pull --ff-only || { |
| 40 | + phpvm_echo >&2 'Failed to update phpvm. Please report this!' |
| 41 | + exit 1 |
| 42 | + } |
53 | 43 | else
|
54 | 44 | phpvm_echo "=> Downloading phpvm from git to '$INSTALL_DIR'"
|
55 | 45 | mkdir -p "${INSTALL_DIR}"
|
|
59 | 49 | }
|
60 | 50 | fi
|
61 | 51 |
|
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 |
| - |
| 52 | + # Install Node.js dependencies |
78 | 53 | phpvm_echo "=> Installing Node.js dependencies"
|
79 | 54 | command npm install --prefix "$INSTALL_DIR" || {
|
80 | 55 | phpvm_echo >&2 'Failed to install Node.js dependencies. Please report this!'
|
81 | 56 | exit 1
|
82 | 57 | }
|
83 |
| - |
84 |
| - # Ensure the bin directory and executable exist |
85 |
| - phpvm_create_bin |
86 | 58 | }
|
87 | 59 |
|
88 |
| - phpvm_create_bin() { |
89 |
| - local INSTALL_DIR |
90 |
| - INSTALL_DIR="$(phpvm_install_dir)" |
91 |
| - |
92 |
| - # Create the bin directory if it doesn't exist |
93 |
| - mkdir -p "$INSTALL_DIR/bin" |
| 60 | + inject_phpvm_config() { |
| 61 | + local PHPVM_PROFILE |
| 62 | + PHPVM_PROFILE="$(phpvm_detect_profile)" |
| 63 | + local PROFILE_INSTALL_DIR |
| 64 | + PROFILE_INSTALL_DIR="$(phpvm_install_dir | command sed "s:^$HOME:\$HOME:")" |
94 | 65 |
|
95 |
| - # Create a symlink to the phpvm executable |
96 |
| - ln -sf "$INSTALL_DIR/index.js" "$INSTALL_DIR/bin/phpvm" |
| 66 | + PHPVM_CONFIG_STR=" |
| 67 | +# Load PHPVM if necessary (this will allow phpvm to be invoked manually) |
| 68 | +if [ -s \"\$PHPVM_DIR/index.js\" ]; then |
| 69 | + export PATH=\"\$PHPVM_DIR/bin:\$PATH\" |
| 70 | +fi |
| 71 | +" |
97 | 72 |
|
98 |
| - # Make the symlink executable |
99 |
| - chmod +x "$INSTALL_DIR/bin/phpvm" |
| 73 | + if [ -n "$PHPVM_PROFILE" ]; then |
| 74 | + if ! command grep -qc '/phpvm/index.js' "$PHPVM_PROFILE"; then |
| 75 | + phpvm_echo "=> Injecting phpvm config into $PHPVM_PROFILE" |
| 76 | + echo -e "$PHPVM_CONFIG_STR" >>"$PHPVM_PROFILE" |
| 77 | + else |
| 78 | + phpvm_echo "=> phpvm config already exists in $PHPVM_PROFILE" |
| 79 | + fi |
| 80 | + else |
| 81 | + phpvm_echo "=> No profile found for phpvm config injection" |
| 82 | + fi |
100 | 83 | }
|
101 | 84 |
|
102 | 85 | phpvm_detect_profile() {
|
|
127 | 110 | fi
|
128 | 111 | }
|
129 | 112 |
|
130 |
| - inject_phpvm_config() { |
131 |
| - local PHPVM_PROFILE |
132 |
| - PHPVM_PROFILE="$(phpvm_detect_profile)" |
133 |
| - local PROFILE_INSTALL_DIR |
134 |
| - PROFILE_INSTALL_DIR="$(phpvm_install_dir | command sed "s:^$HOME:\$HOME:")" |
135 |
| - |
136 |
| - PHPVM_CONFIG_STR=" |
137 |
| -# Load PHPVM if necessary (this will allow phpvm to be invoked manually) |
138 |
| -if [ -s \"\$PHPVM_DIR/index.js\" ]; then |
139 |
| - export PATH=\"\$PHPVM_DIR/bin:\$PATH\" |
140 |
| -fi |
141 |
| -" |
142 |
| - |
143 |
| - if [ -n "$PHPVM_PROFILE" ]; then |
144 |
| - if ! command grep -qc '/phpvm/index.js' "$PHPVM_PROFILE"; then |
145 |
| - phpvm_echo "=> Injecting phpvm config into $PHPVM_PROFILE" |
146 |
| - echo -e "$PHPVM_CONFIG_STR" >>"$PHPVM_PROFILE" |
147 |
| - else |
148 |
| - phpvm_echo "=> phpvm config already exists in $PHPVM_PROFILE" |
149 |
| - fi |
150 |
| - else |
151 |
| - phpvm_echo "=> No profile found for phpvm config injection" |
152 |
| - fi |
153 |
| - } |
154 |
| - |
155 | 113 | phpvm_do_install() {
|
156 |
| - if [ -z "${METHOD}" ]; then |
157 |
| - if phpvm_has git; then |
158 |
| - install_phpvm_from_git |
159 |
| - elif phpvm_has curl || phpvm_has wget; then |
160 |
| - install_phpvm_as_script |
161 |
| - else |
162 |
| - phpvm_echo >&2 'You need git, curl, or wget to install phpvm' |
163 |
| - exit 1 |
164 |
| - fi |
165 |
| - else |
166 |
| - phpvm_echo >&2 "Unexpected install method: $METHOD" |
167 |
| - exit 1 |
168 |
| - fi |
169 |
| - |
| 114 | + install_phpvm_from_git |
170 | 115 | inject_phpvm_config
|
171 |
| - |
172 |
| - node "$(phpvm_install_dir)/index.js" |
173 |
| - |
174 | 116 | phpvm_echo "=> phpvm installation completed successfully!"
|
175 | 117 | }
|
176 | 118 |
|
177 | 119 | phpvm_do_install
|
178 |
| - |
179 |
| -} # this ensures the entire script is downloaded # |
| 120 | +} |
0 commit comments