Skip to content

Commit

Permalink
Merge pull request #19 from jingjingxyk/dev
Browse files Browse the repository at this point in the history
改进脚本,完善 install.sh
  • Loading branch information
jingjingxyk authored Jul 17, 2024
2 parents 13b4e96 + 077dbc9 commit ed6afb9
Show file tree
Hide file tree
Showing 5 changed files with 89 additions and 110 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ jobs:
options: -v ${{ github.workspace }}:/work -w /work -e GITHUB_ACTIONS=true
run: |
set -x
sh init.sh
sh install.sh
bash install.sh --install-php 1 --install-phpy --install-python3 1 --debug
macos:
Expand Down
20 changes: 10 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

一行命令给PHP安装上 swoole 扩展

## [配置选项文档](docs/options.md)

## 用法

From https://www.swoole.com:
Expand Down Expand Up @@ -33,21 +35,19 @@ curl -fsSL https://gitee.com/jingjingxyk/swoole-install/raw/main/install.sh | b

## 可能遇到的的问题

### $PATH 环境变量 未检测到php phpize php-config
### $PATH 环境变量中 未检测到 php phpize php-config

通过临时修改 $PATH 环境变量,例子:
` export PATH=your-php-install-dir/bin/:$PATH`

### rhel 系 、alpine、archlinux 解决 `which` command no found

```bash

curl -fsSL https://github.com/swoole/installers/blob/main/init.sh?raw=true | bash
` export PATH=your-php-install-dir/bin/:$PATH `

# mirror
### alpine 环境运行本脚本需要bash

curl -fsSL https://gitee.com/jingjingxyk/swoole-install/raw/main/init.sh | bash
> 第一次用 sh 执行脚本
> 第二次用 bash 执行脚本
```bash
sh install.sh
bash install.sh
```

## 支持的操作系统
Expand Down
14 changes: 6 additions & 8 deletions docs/FAQ.md
Original file line number Diff line number Diff line change
Expand Up @@ -53,14 +53,12 @@ php --ri swoole
通过临时修改 $PATH 环境变量,例子:
` export PATH=your-php-install-dir/bin/:$PATH`

### rhel 系 、alpine、archlinux 解决 `which` command no found
### alpine 环境运行本脚本需要bash

```bash

curl -fsSL https://github.com/swoole/installers/blob/main/init.sh?raw=true | bash

# mirror

curl -fsSL https://gitee.com/jingjingxyk/swoole-install/raw/main/init.sh | bash
> 第一次用 sh 执行脚本
> 第二次用 bash 执行脚本
```bash
sh install.sh
bash install.sh
```
82 changes: 0 additions & 82 deletions init.sh

This file was deleted.

81 changes: 72 additions & 9 deletions install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,36 @@ __DIR__=$(
pwd
)

init() {
OS=$(uname -s)
if [ "${OS}" = 'Linux' ]; then
OS_RELEASE=$(awk -F= '/^ID=/{print $2}' /etc/os-release | tr -d '\n' | tr -d '\"')
case "$OS_RELEASE" in
'rocky' | 'almalinux' | 'alinux' | 'anolis' | 'fedora' | 'openEuler' | 'hce') # | 'amzn' | 'ol' | 'rhel' | 'centos' # 未测试
yum update -y
yum install -y which
;;
'ubuntu') ;;

'alpine')
apk update
apk add bash
;;
'arch')
pacman -Syyu --noconfirm
pacman -Sy --noconfirm which
;;
esac
fi
}

OS=$(uname -s)
ARCH=$(uname -m)
if [ "$OS" = 'Linux' ]; then
init
if [ ! "$BASH_VERSION" ]; then
echo "Please use bash to run this script ($0) " 1>&2
exit 1
exit 0
fi
fi

Expand Down Expand Up @@ -209,7 +233,7 @@ install_system_php() {

}

configure_environment() {
check_php_and_install_php() {
check_php
# 系统未安装PHP
if test ${INSTALL_PHP} -eq 2; then
Expand Down Expand Up @@ -581,11 +605,50 @@ EOF
}

install_system_python3() {
test -f ./init.sh && bash ./init.sh --install-python3 1
test -f ./init.sh || curl -fSL ${INIT_SCRIPT_SRC} | bash -s -- --install-python3 1
case "$OS" in
Darwin | darwin)
export HOMEBREW_NO_ANALYTICS=1
export HOMEBREW_NO_AUTO_UPDATE=1
export HOMEBREW_INSTALL_FROM_API=1
brew install python3
;;
Linux)
OS_RELEASE=$(awk -F= '/^ID=/{print $2}' /etc/os-release | tr -d '\n' | tr -d '\"')
case "$OS_RELEASE" in
'rocky' | 'almalinux' | 'alinux' | 'anolis' | 'fedora' | 'openEuler' | 'hce') # | 'amzn' | 'ol' | 'rhel' | 'centos' # 未测试
yum install -y update
yum install -y python3 python3-devel
;;
'debian' | 'ubuntu' | 'kali')
export DEBIAN_FRONTEND=noninteractive
export TZ="Etc/UTC"
ln -snf /usr/share/zoneinfo/$TZ /etc/localtime && echo $TZ >/etc/timezone
apt update -y
apt install -y python3 python3-dev

;;
'alpine')
apk update
apk add python3 python3-dev
;;
'arch')
pacman -Sy --noconfirm python3

;;

esac
;;
*)
case "$(uname -r)" in
*microsoft* | *Microsoft*)
# WSL
;;
esac
;;
esac
}

check_python_exits() {
check_python3_and_install_python3() {
# shellcheck disable=SC2155
local PYTHON3="$(which python3)"
PYTHON3_CONFIG="$(which python3-config)"
Expand All @@ -601,7 +664,7 @@ check_python_exits() {
local PYTON3_MINOR="$(python3 -V | awk '{ print $2 }' | awk -F '.' '{ print $2 }')"
if [ $((${PYTON3_MAJOR})) -ge 3 ]; then
if [ $((${PYTON3_MAJOR})) -eq 3 ] && [ $((${PYTON3_MINOR})) -lt 10 ]; then
echo "phpy no support python3 ${PYTHON3_VERSION} version ! "
echo "phpy no support python3 ${PYTHON3_VERSION} ! "
exit 0
fi
fi
Expand All @@ -611,7 +674,7 @@ check_python_exits() {
if test ${FORCE_INSTALL_PYTHON3} -eq 3; then
FORCE_INSTALL_PYTHON3=2
install_system_python3
check_python_exits
check_python3_and_install_python3
test $? -eq 0 && return 0
fi
echo 'no found python3 python3-config in $PATH '
Expand Down Expand Up @@ -712,14 +775,14 @@ EOF
}

install() {
configure_environment
check_php_and_install_php
if test ${INSTALL_PHP} -eq 1; then
install_php_ext_swoole_dependent_library
install_php_ext_swoole_dependent_ext
install_php_ext_swoole

if test ${INSTALL_PHPY} -eq 1; then
check_python_exits
check_python3_and_install_python3
if test -x "${PYTHON3_CONFIG}"; then
install_php_ext_phpy
fi
Expand Down

0 comments on commit ed6afb9

Please sign in to comment.