用ChatGPT写了一个shell脚本来方便地手动更新Wordpress到最新版本,因为不想用Wordpress的后台自动更新。
#!/bin/bash
# 设定临时目录用于处理更新
TEMP_DIR="/tmp/wordpress-update"
WP_DIR="/var/www/blog.example.com"
# 下载最新的WordPress并解压到临时目录
echo "Downloading the latest WordPress..."
wget https://wordpress.org/latest.zip -O /tmp/wordpress-latest.zip
echo "Unzipping WordPress..."
unzip -q /tmp/wordpress-latest.zip -d /tmp
# 创建临时更新目录,防止直接解压覆盖
mkdir -p $TEMP_DIR
mv /tmp/wordpress/* $TEMP_DIR
# 移除不需要更新的wp-content目录
echo "Removing wp-content from the update..."
rm -rf $TEMP_DIR/wp-content
# 复制新的文件到WordPress目录
echo "Copying new files to $WP_DIR..."
cp -r $TEMP_DIR/* $WP_DIR
# 清理临时文件
echo "Cleaning up temporary files..."
rm -rf /tmp/wordpress-latest.zip
rm -rf /tmp/wordpress
rm -rf $TEMP_DIR
echo "WordPress has been updated successfully."