membphis commented on a change in pull request #3335:
URL: https://github.com/apache/apisix/pull/3335#discussion_r561774681



##########
File path: bin/apisix
##########
@@ -1,36 +1,43 @@
-#!/usr/bin/env lua
+#!/bin/bash
 
---
--- Licensed to the Apache Software Foundation (ASF) under one or more
--- contributor license agreements.  See the NOTICE file distributed with
--- this work for additional information regarding copyright ownership.
--- The ASF licenses this file to You under the Apache License, Version 2.0
--- (the "License"); you may not use this file except in compliance with
--- the License.  You may obtain a copy of the License at
---
---     http://www.apache.org/licenses/LICENSE-2.0
---
--- Unless required by applicable law or agreed to in writing, software
--- distributed under the License is distributed on an "AS IS" BASIS,
--- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
--- See the License for the specific language governing permissions and
--- limitations under the License.
---
+#
+# Licensed to the Apache Software Foundation (ASF) under one or more
+# contributor license agreements.  See the NOTICE file distributed with
+# this work for additional information regarding copyright ownership.
+# The ASF licenses this file to You under the Apache License, Version 2.0
+# (the "License"); you may not use this file except in compliance with
+# the License.  You may obtain a copy of the License at
+#
+#     http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+#
 
-local pkg_cpath_org = package.cpath
-local pkg_path_org = package.path
+USE_LUA=true
+LUA_VERSION=$(lua -v 2>&1 | grep -E -o  "Lua [0-9]+.[0-9]+")
 
-local apisix_home = "/usr/local/apisix"
-local pkg_cpath = apisix_home .. "/deps/lib64/lua/5.1/?.so;"
-                  .. apisix_home .. "/deps/lib/lua/5.1/?.so;;"
-local pkg_path = apisix_home .. "/deps/share/lua/5.1/?.lua;;"
+if [ -s './apisix/cli/apisix.lua' ]; then
+    APISIX_LUA=./apisix/cli/apisix.lua
+elif [ -s '/usr/share/lua/5.1/apisix/cli/apisix.lua' ]; then
+    APISIX_LUA=/usr/share/lua/5.1/apisix/cli/apisix.lua
+else
+    APISIX_LUA=/usr/local/apisix/apisix/cli/apisix.lua
+fi
 
--- modify the load path to load our dependencies
-package.cpath = pkg_cpath .. pkg_cpath_org
-package.path  = pkg_path .. pkg_path_org
+if [[ "$LUA_VERSION" =~ "Lua 5.1" && $USE_LUA ]]; then

Review comment:
       this is wrong. we should always use `luajit` of openresty

##########
File path: bin/apisix
##########
@@ -1,36 +1,43 @@
-#!/usr/bin/env lua
+#!/bin/bash
 
---
--- Licensed to the Apache Software Foundation (ASF) under one or more
--- contributor license agreements.  See the NOTICE file distributed with
--- this work for additional information regarding copyright ownership.
--- The ASF licenses this file to You under the Apache License, Version 2.0
--- (the "License"); you may not use this file except in compliance with
--- the License.  You may obtain a copy of the License at
---
---     http://www.apache.org/licenses/LICENSE-2.0
---
--- Unless required by applicable law or agreed to in writing, software
--- distributed under the License is distributed on an "AS IS" BASIS,
--- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
--- See the License for the specific language governing permissions and
--- limitations under the License.
---
+#
+# Licensed to the Apache Software Foundation (ASF) under one or more
+# contributor license agreements.  See the NOTICE file distributed with
+# this work for additional information regarding copyright ownership.
+# The ASF licenses this file to You under the Apache License, Version 2.0
+# (the "License"); you may not use this file except in compliance with
+# the License.  You may obtain a copy of the License at
+#
+#     http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+#
 
-local pkg_cpath_org = package.cpath
-local pkg_path_org = package.path
+USE_LUA=true
+LUA_VERSION=$(lua -v 2>&1 | grep -E -o  "Lua [0-9]+.[0-9]+")
 
-local apisix_home = "/usr/local/apisix"
-local pkg_cpath = apisix_home .. "/deps/lib64/lua/5.1/?.so;"
-                  .. apisix_home .. "/deps/lib/lua/5.1/?.so;;"
-local pkg_path = apisix_home .. "/deps/share/lua/5.1/?.lua;;"
+if [ -s './apisix/cli/apisix.lua' ]; then
+    APISIX_LUA=./apisix/cli/apisix.lua
+elif [ -s '/usr/share/lua/5.1/apisix/cli/apisix.lua' ]; then
+    APISIX_LUA=/usr/share/lua/5.1/apisix/cli/apisix.lua
+else
+    APISIX_LUA=/usr/local/apisix/apisix/cli/apisix.lua
+fi
 
--- modify the load path to load our dependencies
-package.cpath = pkg_cpath .. pkg_cpath_org
-package.path  = pkg_path .. pkg_path_org
+if [[ "$LUA_VERSION" =~ "Lua 5.1" && $USE_LUA ]]; then

Review comment:
       this is wrong. we should always use `luajit` of openresty

##########
File path: bin/apisix
##########
@@ -1,36 +1,43 @@
-#!/usr/bin/env lua
+#!/bin/bash
 
---
--- Licensed to the Apache Software Foundation (ASF) under one or more
--- contributor license agreements.  See the NOTICE file distributed with
--- this work for additional information regarding copyright ownership.
--- The ASF licenses this file to You under the Apache License, Version 2.0
--- (the "License"); you may not use this file except in compliance with
--- the License.  You may obtain a copy of the License at
---
---     http://www.apache.org/licenses/LICENSE-2.0
---
--- Unless required by applicable law or agreed to in writing, software
--- distributed under the License is distributed on an "AS IS" BASIS,
--- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
--- See the License for the specific language governing permissions and
--- limitations under the License.
---
+#
+# Licensed to the Apache Software Foundation (ASF) under one or more
+# contributor license agreements.  See the NOTICE file distributed with
+# this work for additional information regarding copyright ownership.
+# The ASF licenses this file to You under the Apache License, Version 2.0
+# (the "License"); you may not use this file except in compliance with
+# the License.  You may obtain a copy of the License at
+#
+#     http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+#
 
-local pkg_cpath_org = package.cpath
-local pkg_path_org = package.path
+USE_LUA=true
+LUA_VERSION=$(lua -v 2>&1 | grep -E -o  "Lua [0-9]+.[0-9]+")
 
-local apisix_home = "/usr/local/apisix"
-local pkg_cpath = apisix_home .. "/deps/lib64/lua/5.1/?.so;"
-                  .. apisix_home .. "/deps/lib/lua/5.1/?.so;;"
-local pkg_path = apisix_home .. "/deps/share/lua/5.1/?.lua;;"
+if [ -s './apisix/cli/apisix.lua' ]; then
+    APISIX_LUA=./apisix/cli/apisix.lua
+elif [ -s '/usr/share/lua/5.1/apisix/cli/apisix.lua' ]; then
+    APISIX_LUA=/usr/share/lua/5.1/apisix/cli/apisix.lua
+else
+    APISIX_LUA=/usr/local/apisix/apisix/cli/apisix.lua
+fi
 
--- modify the load path to load our dependencies
-package.cpath = pkg_cpath .. pkg_cpath_org
-package.path  = pkg_path .. pkg_path_org
+if [[ "$LUA_VERSION" =~ "Lua 5.1" && $USE_LUA ]]; then

Review comment:
       this is fine for the old users, sure for this

##########
File path: bin/apisix
##########
@@ -1,36 +1,35 @@
-#!/usr/bin/env lua
+#!/bin/bash
 
---
--- Licensed to the Apache Software Foundation (ASF) under one or more
--- contributor license agreements.  See the NOTICE file distributed with
--- this work for additional information regarding copyright ownership.
--- The ASF licenses this file to You under the Apache License, Version 2.0
--- (the "License"); you may not use this file except in compliance with
--- the License.  You may obtain a copy of the License at
---
---     http://www.apache.org/licenses/LICENSE-2.0
---
--- Unless required by applicable law or agreed to in writing, software
--- distributed under the License is distributed on an "AS IS" BASIS,
--- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
--- See the License for the specific language governing permissions and
--- limitations under the License.
---
+#
+# Licensed to the Apache Software Foundation (ASF) under one or more
+# contributor license agreements.  See the NOTICE file distributed with
+# this work for additional information regarding copyright ownership.
+# The ASF licenses this file to You under the Apache License, Version 2.0
+# (the "License"); you may not use this file except in compliance with
+# the License.  You may obtain a copy of the License at
+#
+#     http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+#
 
-local pkg_cpath_org = package.cpath
-local pkg_path_org = package.path
+if [ -s './apisix/cli/apisix.lua' ]; then
+    APISIX_LUA=./apisix/cli/apisix.lua
+elif [ -s '/usr/share/lua/5.1/apisix/cli/apisix.lua' ]; then
+    APISIX_LUA=/usr/share/lua/5.1/apisix/cli/apisix.lua
+else
+    APISIX_LUA=/usr/local/apisix/apisix/cli/apisix.lua
+fi
 
-local apisix_home = "/usr/local/apisix"
-local pkg_cpath = apisix_home .. "/deps/lib64/lua/5.1/?.so;"
-                  .. apisix_home .. "/deps/lib/lua/5.1/?.so;;"
-local pkg_path = apisix_home .. "/deps/share/lua/5.1/?.lua;;"
+# find the openresty
+OR_EXEC=$(which openresty)

Review comment:
       This step may fail, and we need to do some exception checks.
   
   If the openresty command is not found, you can actively determine whether 
there is this directory in /usr/local/openresty.

##########
File path: bin/apisix
##########
@@ -1,36 +1,35 @@
-#!/usr/bin/env lua
+#!/bin/bash
 
---
--- Licensed to the Apache Software Foundation (ASF) under one or more
--- contributor license agreements.  See the NOTICE file distributed with
--- this work for additional information regarding copyright ownership.
--- The ASF licenses this file to You under the Apache License, Version 2.0
--- (the "License"); you may not use this file except in compliance with
--- the License.  You may obtain a copy of the License at
---
---     http://www.apache.org/licenses/LICENSE-2.0
---
--- Unless required by applicable law or agreed to in writing, software
--- distributed under the License is distributed on an "AS IS" BASIS,
--- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
--- See the License for the specific language governing permissions and
--- limitations under the License.
---
+#
+# Licensed to the Apache Software Foundation (ASF) under one or more
+# contributor license agreements.  See the NOTICE file distributed with
+# this work for additional information regarding copyright ownership.
+# The ASF licenses this file to You under the Apache License, Version 2.0
+# (the "License"); you may not use this file except in compliance with
+# the License.  You may obtain a copy of the License at
+#
+#     http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+#
 
-local pkg_cpath_org = package.cpath
-local pkg_path_org = package.path
+if [ -s './apisix/cli/apisix.lua' ]; then
+    APISIX_LUA=./apisix/cli/apisix.lua
+elif [ -s '/usr/share/lua/5.1/apisix/cli/apisix.lua' ]; then
+    APISIX_LUA=/usr/share/lua/5.1/apisix/cli/apisix.lua
+else
+    APISIX_LUA=/usr/local/apisix/apisix/cli/apisix.lua
+fi
 
-local apisix_home = "/usr/local/apisix"
-local pkg_cpath = apisix_home .. "/deps/lib64/lua/5.1/?.so;"
-                  .. apisix_home .. "/deps/lib/lua/5.1/?.so;;"
-local pkg_path = apisix_home .. "/deps/share/lua/5.1/?.lua;;"
+# find the openresty
+OR_EXEC=$(which openresty)

Review comment:
       eg: 
   
   https://github.com/apache/apisix/blob/master/Makefile#L36

##########
File path: bin/apisix
##########
@@ -1,36 +1,35 @@
-#!/usr/bin/env lua
+#!/bin/bash
 
---
--- Licensed to the Apache Software Foundation (ASF) under one or more
--- contributor license agreements.  See the NOTICE file distributed with
--- this work for additional information regarding copyright ownership.
--- The ASF licenses this file to You under the Apache License, Version 2.0
--- (the "License"); you may not use this file except in compliance with
--- the License.  You may obtain a copy of the License at
---
---     http://www.apache.org/licenses/LICENSE-2.0
---
--- Unless required by applicable law or agreed to in writing, software
--- distributed under the License is distributed on an "AS IS" BASIS,
--- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
--- See the License for the specific language governing permissions and
--- limitations under the License.
---
+#
+# Licensed to the Apache Software Foundation (ASF) under one or more
+# contributor license agreements.  See the NOTICE file distributed with
+# this work for additional information regarding copyright ownership.
+# The ASF licenses this file to You under the Apache License, Version 2.0
+# (the "License"); you may not use this file except in compliance with
+# the License.  You may obtain a copy of the License at
+#
+#     http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+#
 
-local pkg_cpath_org = package.cpath
-local pkg_path_org = package.path
+if [ -s './apisix/cli/apisix.lua' ]; then
+    APISIX_LUA=./apisix/cli/apisix.lua
+elif [ -s '/usr/share/lua/5.1/apisix/cli/apisix.lua' ]; then
+    APISIX_LUA=/usr/share/lua/5.1/apisix/cli/apisix.lua
+else
+    APISIX_LUA=/usr/local/apisix/apisix/cli/apisix.lua
+fi
 
-local apisix_home = "/usr/local/apisix"
-local pkg_cpath = apisix_home .. "/deps/lib64/lua/5.1/?.so;"
-                  .. apisix_home .. "/deps/lib/lua/5.1/?.so;;"
-local pkg_path = apisix_home .. "/deps/share/lua/5.1/?.lua;;"
+# find the openresty
+OR_EXEC=$(which openresty)

Review comment:
       thrown an error if failed to find the `openresty`




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
[email protected]


Reply via email to