brew 安装任意版本 PHP(7.3、7.4、8.0、8.1、8.2、8.3) 作者: Chuwen 时间: 2023-09-19 分类: Linux 评论 ## 依赖 * [brew](https://brew.sh/ "brew") ## 安装 首先添加 `shivammathur/php` 仓库源: ```shell brew tap shivammathur/php ``` 搜索可安装的 PHP 版本 `brew search shivammathur/php` ```shell shine@shine:~/work/xxxxx-web$ brew search shivammathur/php ==> Formulae shivammathur/php/php shivammathur/php/php@7.0-debug shivammathur/php/php@7.3 shivammathur/php/php@8.0-debug shivammathur/php/php@8.4 shivammathur/php/php-debug shivammathur/php/php@7.1 shivammathur/php/php@7.3-debug shivammathur/php/php@8.1 shivammathur/php/php@8.4-debug shivammathur/php/php@5.6 shivammathur/php/php@7.1-debug shivammathur/php/php@7.4 shivammathur/php/php@8.1-debug shivammathur/php/php@5.6-debug shivammathur/php/php@7.2 shivammathur/php/php@7.4-debug shivammathur/php/php@8.3 shivammathur/php/php@7.0 shivammathur/php/php@7.2-debug shivammathur/php/php@8.0 shivammathur/php/php@8.3-debug ``` 比如你要这些 PHP 版本就这样操作: * PHP 8.1:`brew install shivammathur/php/php@8.1` * PHP 8.2:`brew install shivammathur/php/php@8.2` * PHP 8.3:`brew install shivammathur/php/php@8.3`
批量修改 git commit 的作者和邮箱信息 作者: Chuwen 时间: 2023-03-31 分类: Linux 评论 ## 脚本 通过此脚本即可实现一键修改 ```shell #!/bin/sh git filter-branch --env-filter ' OLD_EMAIL="填写原来的邮箱" CORRECT_NAME="填写现在的名称" CORRECT_EMAIL="填写现在的邮箱" if [ "$GIT_COMMITTER_EMAIL" = "$OLD_EMAIL" ] then export GIT_COMMITTER_NAME="$CORRECT_NAME" export GIT_COMMITTER_EMAIL="$CORRECT_EMAIL" fi if [ "$GIT_AUTHOR_EMAIL" = "$OLD_EMAIL" ] then export GIT_AUTHOR_NAME="$CORRECT_NAME" export GIT_AUTHOR_EMAIL="$CORRECT_EMAIL" fi ' --tag-name-filter cat -- --branches --tags ``` 运行后,然后执行 `git push -f` 即可
记一个困扰我 2 天的问题——rsync 命令 作者: Chuwen 时间: 2022-12-28 分类: Linux 评论 最近在忙着迁移服务器,流水线脚本没改,只是换了服务器,结果新服务器 `rsync` 有问题,不遵从 `--exclude=` 规则,导致 `.env` 文件被删除 但是手动拿出执行又是正常的 ## 服务器信息 **旧服务器**(使用*原脚本*运行正常) ```shell 18:30:41 root@shine-prod ~ lsb_release -a LSB Version: :core-4.1-amd64:core-4.1-noarch Distributor ID: CentOS Description: CentOS Linux release 8.5.2111 Release: 8.5.2111 Codename: n/a 18:30:43 root@shine-prod ~ rsync --version rsync version 3.1.3 protocol version 31 Copyright (C) 1996-2018 by Andrew Tridgell, Wayne Davison, and others. Web site: http://rsync.samba.org/ Capabilities: 64-bit files, 64-bit inums, 64-bit timestamps, 64-bit long ints, socketpairs, hardlinks, symlinks, IPv6, batchfiles, inplace, append, ACLs, xattrs, iconv, symtimes, prealloc rsync comes with ABSOLUTELY NO WARRANTY. This is free software, and you are welcome to redistribute it under certain conditions. See the GNU General Public Licence for details. ``` **新服务器**(使用*原脚本*运行错误) ```shell root@shine-prod-1:~# lsb_release -a LSB Version: security-11.1.0ubuntu4-noarch Distributor ID: Ubuntu Description: Ubuntu 22.04.1 LTS Release: 22.04 Codename: jammy root@shine-prod-1:~# rsync --version rsync version 3.2.3 protocol version 31 Copyright (C) 1996-2020 by Andrew Tridgell, Wayne Davison, and others. Web site: https://rsync.samba.org/ Capabilities: 64-bit files, 64-bit inums, 64-bit timestamps, 64-bit long ints, socketpairs, hardlinks, hardlink-specials, symlinks, IPv6, atimes, batchfiles, inplace, append, ACLs, xattrs, optional protect-args, iconv, symtimes, prealloc, stop-at, no crtimes Optimizations: SIMD, no asm, openssl-crypto Checksum list: xxh128 xxh3 xxh64 (xxhash) md5 md4 none Compress list: zstd lz4 zlibx zlib none rsync comes with ABSOLUTELY NO WARRANTY. This is free software, and you are welcome to redistribute it under certain conditions. See the GNU General Public Licence for details. ``` ## 原脚本 注意看以下脚本中 `--exclude={'.git','.idea','storage','node_modules','.env','shell','docker-compose.yaml'}` 部分,这个如果是通过阿里云流水线-主机部署执行这条命令,不会起作用,但是你手动去执行又是正常的 导致把你的 `.env` 文件给删了,然后后置脚本就运行失败了 *就是因为这个把我折腾死的烦躁、怀疑人生* ```shell rm -rf $TMP_DEPLOY_PATH mkdir -p $TMP_DEPLOY_PATH mkdir -p $ES_STAGING_PATH tar zxvf "$package_download_path" -C "$TMP_DEPLOY_PATH" EXCLUDE_COMPOSER_ARG=$([ "$ES_UPDATE_COMPOSER" = "true" ] && echo "" || echo --exclude="vendor") ####### 预发布环境部署 rsync -zarp --delete \ --exclude={'.git','.idea','storage','node_modules','.env','shell','docker-compose.yaml'} \ $EXCLUDE_COMPOSER_ARG \ $TMP_DEPLOY_PATH $DEPLOY_STAGING_PATH cd $DEPLOY_STAGING_PATH || exit docker-compose exec app sh deploy/laravels.sh ``` ## 解决方案-现脚本 一次偶然的尝试,改成 `--exclude=".env"` ... 这样一个一个加上,发现脚本正常运行,达到我预期效果,`.env` 终于不会被删除了!!! ```shell rm -rf $TMP_DEPLOY_PATH mkdir -p $TMP_DEPLOY_PATH mkdir -p $ES_STAGING_PATH tar zxvf "$package_download_path" -C "$TMP_DEPLOY_PATH" >>/dev/null EXCLUDE_COMPOSER_ARG=$([ "$ES_UPDATE_COMPOSER" = "true" ] && echo "" || echo --exclude="vendor") #### 预发布环境部署 rsync -zarp --delete \ --exclude=".git" --exclude=".idea" --exclude=".env" \ --exclude="storage" --exclude="node_modules" --exclude="shell" \ --exclude="docker-compose.yaml" $EXCLUDE_COMPOSER_ARG \ $TMP_DEPLOY_PATH $DEPLOY_STAGING_PATH cd $DEPLOY_STAGING_PATH || exit docker compose exec -T app sh deploy/laravels.sh ``` --- 具体原因还未找到,等找到原因再更新文章
Shell 输出有颜色文本并封装成函数 作者: Chuwen 时间: 2022-12-10 分类: Linux 评论 ```shell #!/bin/bash # 输出红字 function echo_error() { [ $# -ne 1 ] && return 0 echo -e "\033[31m $1 \033[0m" } # 输出红底白字 function echo_danger() { [ $# -ne 1 ] && return 0 echo -e "\033[41;37m $1 \033[0m" } # 输出绿字 function echo_info() { [ $# -ne 1 ] && return 0 echo -e "\033[32m $1 \033[0m" } # 输出绿底白字 function echo_success() { [ $# -ne 1 ] && return 0 echo -e "\033[42;37m $1 \033[0m" } # 输出黄字 function echo_warning() { [ $# -ne 1 ] && return 0 echo -e "\033[33m $1 \033[0m" } ``` ## 运行结果截图 ```shell echo_error "输出红字" echo_danger "输出红底白字" echo_info "输出绿字" echo_success "输出绿底白字" echo_warning "输出黄字" ``` ![](https://cdn.nowtime.cc/2022/12/10/445780269.png) --- 通过 gist 查看:https://gist.github.com/PrintNow/a33da4cf74bb2f097deb00ac0dadd003
解决 GitHub Connect: kex_exchange_identification: Connection closed by remote host 作者: Chuwen 时间: 2022-07-30 分类: Linux 评论 # 背景 想要克隆项目/推送代码到 GitHub 老实错误,检查发现: ```shell ➜ ~ ssh -vvv git@github.com OpenSSH_8.1p1, LibreSSL 2.7.3 debug1: Reading configuration data /Users/chuwen/.ssh/config debug1: /Users/chuwen/.ssh/config line 1: Applying options for * debug1: /Users/chuwen/.ssh/config line 6: Applying options for github.com debug1: Reading configuration data /etc/ssh/ssh_config debug1: /etc/ssh/ssh_config line 47: Applying options for * debug1: Executing proxy command: exec nc -v -x 127.0.0.1:7890 github.com 443 debug1: identity file /Users/chuwen/.ssh/id_rsa type 0 debug1: identity file /Users/chuwen/.ssh/id_rsa-cert type -1 debug1: identity file /Users/chuwen/.ssh/id_dsa type -1 debug1: identity file /Users/chuwen/.ssh/id_dsa-cert type -1 debug1: identity file /Users/chuwen/.ssh/id_ecdsa type -1 debug1: identity file /Users/chuwen/.ssh/id_ecdsa-cert type -1 debug1: identity file /Users/chuwen/.ssh/id_ed25519 type -1 debug1: identity file /Users/chuwen/.ssh/id_ed25519-cert type -1 debug1: identity file /Users/chuwen/.ssh/id_xmss type -1 debug1: identity file /Users/chuwen/.ssh/id_xmss-cert type -1 debug1: Local version string SSH-2.0-OpenSSH_8.1 Connection to github.com port 443 [tcp/https] succeeded! kex_exchange_identification: Connection closed by remote host ``` # 解决方案 最后找到[一篇文章](https://idreamshen.github.io/posts/github-connection-closed/ "一篇文章")解决了这个问题。 只需要在 `~/.ssh/config` 配置以下项目即可 ```config Host github.com HostName ssh.github.com User git Port 443 ``` 如果想要配置代理可以这样: ```config Host github.com HostName ssh.github.com User git Port 443 # 走 HTTP 代理 # ProxyCommand socat - PROXY:127.0.0.1:%h:%p,proxyport=8080 # 走 socks5 代理(如 Shadowsocks) ProxyCommand nc -v -x 127.0.0.1:7890 %h %p ``` ## 最终解决了问题 ```shell ➜ ~ ssh -T git@github.com Connection to ssh.github.com port 443 [tcp/https] succeeded! Hi PrintNow/react-i18next-base-usage! You've successfully authenticated, but GitHub does not provide shell access ```