first commit
This commit is contained in:
3
.gitignore
vendored
Normal file
3
.gitignore
vendored
Normal file
@@ -0,0 +1,3 @@
|
|||||||
|
/*.pkg.tar.zst
|
||||||
|
/src/
|
||||||
|
/pkg/
|
||||||
102
PKGBUILD
Normal file
102
PKGBUILD
Normal file
@@ -0,0 +1,102 @@
|
|||||||
|
# Maintainer: Your Name <your.email@example.com>
|
||||||
|
|
||||||
|
pkgname=smarttms-mysql
|
||||||
|
pkgver=5.6.47
|
||||||
|
pkgrel=1
|
||||||
|
pkgdesc="MySQL 5.6.47 Database Server for SmartTMS Application (pre-compiled binary)"
|
||||||
|
arch=('x86_64')
|
||||||
|
url="https://www.mysql.com/"
|
||||||
|
license=('GPLv2')
|
||||||
|
# Arch Linux 通常不直接使用 group 字段,但可以作为 pkgdesc 的补充
|
||||||
|
# group="Applications/Databases"
|
||||||
|
|
||||||
|
# Source0 是 MySQL 预编译二进制包
|
||||||
|
# Source1 是自定义的 my.cnf 配置文件
|
||||||
|
# Source2 是 systemd 服务单元文件
|
||||||
|
# Source3 是 SmartTMS 应用程序的初始数据库 SQL 文件
|
||||||
|
# 注意:这里假设这些文件与 PKGBUILD 在同一目录。
|
||||||
|
# 对于 mysql-5.6.47-linux-glibc2.12-x86_64.tar.gz,建议提供一个可下载的URL或确保本地存在。
|
||||||
|
# 如果你希望从官方下载,可以修改为:
|
||||||
|
# "mysql-5.6.47-linux-glibc2.12-x86_64.tar.gz::https://downloads.mysql.com/archives/get/file/mysql-5.6.47-linux-glibc2.12-x86_64.tar.gz"
|
||||||
|
source=(
|
||||||
|
"mysql-5.6.47-linux-glibc2.12-x86_64.tar.gz"
|
||||||
|
"my.cnf"
|
||||||
|
"mysqld.service"
|
||||||
|
"tms_db_s3.sql"
|
||||||
|
)
|
||||||
|
|
||||||
|
# 构建依赖
|
||||||
|
# systemd 是运行时依赖,tar/gzip 是 pacman 自动处理的
|
||||||
|
makedepends=('systemd') # systemd 用于处理服务文件
|
||||||
|
|
||||||
|
# 运行时依赖
|
||||||
|
# shadow-utils 提供 useradd/groupadd
|
||||||
|
# libaio 是 MySQL 常见的运行时依赖
|
||||||
|
# perl-data-dumper 是 mysql_install_db 脚本的依赖
|
||||||
|
depends=(
|
||||||
|
'systemd'
|
||||||
|
'libaio'
|
||||||
|
'perl-data-dumper'
|
||||||
|
)
|
||||||
|
|
||||||
|
# 安装脚本,用于处理用户/组、数据目录、服务启用和数据库初始化
|
||||||
|
install="${pkgname}.install"
|
||||||
|
|
||||||
|
# 校验和,请使用 makepkg -g 生成
|
||||||
|
# makepkg -g >> PKGBUILD
|
||||||
|
sha256sums=('be2fa4fffc74dff626cfa8d62f16d9eef93bcd81bc8133ae500e04460e1fb795'
|
||||||
|
'a664d5b110640f877bd994e3218a0ae4531a0493f0a3869eea8973928f06e0cd'
|
||||||
|
'92cc61a5db1e791e463a030955566c1a6eb308f1cd3ff921f6d7bd1e4cdd48ff'
|
||||||
|
'b9e6e58cbc4809a2dd3432d36272ba71e0fc63af4a48288b24f30968c830e0c9')
|
||||||
|
|
||||||
|
|
||||||
|
# 配置备份,如果用户修改了这些文件,升级时会生成 .pacnew 文件
|
||||||
|
backup=(
|
||||||
|
'etc/my.cnf'
|
||||||
|
'etc/profile.d/mysql.sh'
|
||||||
|
'etc/systemd/system/mysqld.service' # 虽然是服务文件,但如果用户修改了,也可以备份
|
||||||
|
)
|
||||||
|
|
||||||
|
prepare() {
|
||||||
|
# 解压 MySQL 二进制包
|
||||||
|
# tar -xzf "${srcdir}/mysql-5.6.47-linux-glibc2.12-x86_64.tar.gz" -C "${srcdir}"
|
||||||
|
# 假设 tarball 内部顶层目录名为 mysql-5.6.47-linux-glibc2.12-x86_64
|
||||||
|
cd "${srcdir}/mysql-5.6.47-linux-glibc2.12-x86_64"
|
||||||
|
}
|
||||||
|
|
||||||
|
build() {
|
||||||
|
# 对于预编译二进制包,通常不需要编译步骤。
|
||||||
|
# 如果需要,可以在这里添加编译命令。
|
||||||
|
msg "No build step required for pre-compiled binaries."
|
||||||
|
}
|
||||||
|
|
||||||
|
package() {
|
||||||
|
# 清理构建根目录 (makepkg 会自动清理 $pkgdir)
|
||||||
|
# rm -rf "${pkgdir}"
|
||||||
|
|
||||||
|
# 创建安装路径
|
||||||
|
install -d "${pkgdir}/usr/local"
|
||||||
|
install -d "${pkgdir}/etc/systemd/system" # systemd 服务文件通常放在这里
|
||||||
|
install -d "${pkgdir}/etc/profile.d"
|
||||||
|
install -d "${pkgdir}/usr/share/${pkgname}" # 用于存放 SQL 导入文件
|
||||||
|
|
||||||
|
# 复制 MySQL 二进制文件到 /usr/local/
|
||||||
|
# 注意:prepare 已经将内容解压到 "${srcdir}/mysql-5.6.47-linux-glibc2.12-x86_64"
|
||||||
|
cp -a "${srcdir}/mysql-5.6.47-linux-glibc2.12-x86_64/." "${pkgdir}/usr/local/mysql-5.6.47-linux-glibc2.12-x86_64"
|
||||||
|
|
||||||
|
# 创建 /usr/local/mysql 软链接
|
||||||
|
ln -s mysql-5.6.47-linux-glibc2.12-x86_64 "${pkgdir}/usr/local/mysql"
|
||||||
|
|
||||||
|
# 复制配置文件
|
||||||
|
install -m644 "${srcdir}/my.cnf" "${pkgdir}/etc/my.cnf"
|
||||||
|
|
||||||
|
# 复制 systemd 服务文件
|
||||||
|
install -m644 "${srcdir}/mysqld.service" "${pkgdir}/etc/systemd/system/mysqld.service"
|
||||||
|
|
||||||
|
# 创建 PATH 环境变量配置脚本
|
||||||
|
echo 'PATH=/usr/local/mysql/bin:$PATH' > "${pkgdir}/etc/profile.d/mysql.sh"
|
||||||
|
chmod 0644 "${pkgdir}/etc/profile.d/mysql.sh"
|
||||||
|
|
||||||
|
# 复制初始 SQL 导入文件
|
||||||
|
install -m644 "${srcdir}/tms_db_s3.sql" "${pkgdir}/usr/share/${pkgname}/tms_db_s3.sql"
|
||||||
|
}
|
||||||
34
my.cnf
Normal file
34
my.cnf
Normal file
@@ -0,0 +1,34 @@
|
|||||||
|
# For advice on how to change settings please see
|
||||||
|
# http://dev.mysql.com/doc/refman/5.6/en/server-configuration-defaults.html
|
||||||
|
# *** DO NOT EDIT THIS FILE. It's a template which will be copied to the
|
||||||
|
# *** default location during install, and will be replaced if you
|
||||||
|
# *** upgrade to a newer version of MySQL.
|
||||||
|
|
||||||
|
[mysqld]
|
||||||
|
datadir=/data/mysql #指定mysql的数据目录
|
||||||
|
innodb_file_per_table=on #在mariadb5.5以上版的是默认值,可不加
|
||||||
|
skip_name_resolve=on #禁止主机名解析,建议使用
|
||||||
|
|
||||||
|
# Remove leading # and set to the amount of RAM for the most important data
|
||||||
|
# cache in MySQL. Start at 70% of total RAM for dedicated server, else 10%.
|
||||||
|
# innodb_buffer_pool_size = 128M
|
||||||
|
|
||||||
|
# Remove leading # to turn on a very important data integrity option: logging
|
||||||
|
# changes to the binary log between backups.
|
||||||
|
# log_bin
|
||||||
|
|
||||||
|
# These are commonly set, remove the # and set as required.
|
||||||
|
# basedir = .....
|
||||||
|
# datadir = .....
|
||||||
|
# port = .....
|
||||||
|
# server_id = .....
|
||||||
|
# socket = .....
|
||||||
|
|
||||||
|
# Remove leading # to set options mainly useful for reporting servers.
|
||||||
|
# The server defaults are faster for transactions and fast SELECTs.
|
||||||
|
# Adjust sizes as needed, experiment to find the optimal values.
|
||||||
|
# join_buffer_size = 128M
|
||||||
|
# sort_buffer_size = 2M
|
||||||
|
# read_rnd_buffer_size = 2M
|
||||||
|
|
||||||
|
sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES
|
||||||
BIN
mysql-5.6.47-linux-glibc2.12-x86_64.tar.gz
Normal file
BIN
mysql-5.6.47-linux-glibc2.12-x86_64.tar.gz
Normal file
Binary file not shown.
27
mysqld.service
Normal file
27
mysqld.service
Normal file
@@ -0,0 +1,27 @@
|
|||||||
|
[Unit]
|
||||||
|
Description=MySQL Server
|
||||||
|
After=network.target
|
||||||
|
|
||||||
|
[Service]
|
||||||
|
Type=simple
|
||||||
|
User=mysql
|
||||||
|
Group=mysql
|
||||||
|
|
||||||
|
# 直接使用 mysqld
|
||||||
|
ExecStart=/usr/local/mysql/bin/mysqld --defaults-file=/etc/my.cnf
|
||||||
|
ExecStop=/usr/local/mysql/bin/mysqladmin shutdown
|
||||||
|
|
||||||
|
# 重启策略
|
||||||
|
Restart=on-failure
|
||||||
|
RestartSec=5s
|
||||||
|
|
||||||
|
# 超时设置
|
||||||
|
TimeoutStartSec=300
|
||||||
|
TimeoutStopSec=60
|
||||||
|
|
||||||
|
# 资源限制
|
||||||
|
LimitNOFILE=65536
|
||||||
|
|
||||||
|
[Install]
|
||||||
|
WantedBy=multi-user.target
|
||||||
|
|
||||||
159
smarttms-mysql.install
Normal file
159
smarttms-mysql.install
Normal file
@@ -0,0 +1,159 @@
|
|||||||
|
# smarttms-mysql.install
|
||||||
|
#
|
||||||
|
# 这个脚本处理 smarttms-mysql 包的安装、升级和卸载时的操作。
|
||||||
|
|
||||||
|
pkgname="smarttms-mysql"
|
||||||
|
mysql_install_dir="/usr/local/mysql"
|
||||||
|
mysql_data_dir="/data/mysql"
|
||||||
|
mysql_user="mysql"
|
||||||
|
mysql_group="mysql"
|
||||||
|
mysql_uid="306" # 与 RPM spec 保持一致
|
||||||
|
mysql_gid="306" # 与 RPM spec 保持一致
|
||||||
|
mysql_root_password="PythA90ra5"
|
||||||
|
mysql_sql_file="/usr/share/${pkgname}/tms_db_s3.sql"
|
||||||
|
mysql_service="mysqld.service"
|
||||||
|
|
||||||
|
# pre_install 钩子在安装文件复制到系统之前运行
|
||||||
|
pre_install() {
|
||||||
|
# 创建 mysql 用户和组,如果不存在的话
|
||||||
|
if ! getent group "${mysql_group}" >/dev/null; then
|
||||||
|
echo "Creating group '${mysql_group}' with GID ${mysql_gid}..."
|
||||||
|
groupadd -r -g "${mysql_gid}" "${mysql_group}"
|
||||||
|
fi
|
||||||
|
if ! getent passwd "${mysql_user}" >/dev/null; then
|
||||||
|
echo "Creating user '${mysql_user}' with UID ${mysql_uid}..."
|
||||||
|
useradd -r -g "${mysql_gid}" -u "${mysql_uid}" -d "${mysql_data_dir}" -s /sbin/nologin "${mysql_user}"
|
||||||
|
fi
|
||||||
|
|
||||||
|
# 创建数据目录并设置权限
|
||||||
|
if [ ! -d "${mysql_data_dir}" ]; then
|
||||||
|
echo "Creating MySQL data directory '${mysql_data_dir}'..."
|
||||||
|
mkdir -p "${mysql_data_dir}"
|
||||||
|
chown "${mysql_user}":"${mysql_group}" "${mysql_data_dir}"
|
||||||
|
chmod 0750 "${mysql_data_dir}"
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
# post_install 钩子在安装文件复制到系统之后运行
|
||||||
|
post_install() {
|
||||||
|
local install_type="$1"
|
||||||
|
local timeout=60 # 等待 MySQL 启动的超时时间
|
||||||
|
|
||||||
|
echo "Reloading systemd daemon..."
|
||||||
|
systemctl daemon-reload
|
||||||
|
|
||||||
|
# 仅在首次安装时初始化数据库、设置密码和导入数据
|
||||||
|
if [ ! -d "${mysql_data_dir}/mysql" ]; then
|
||||||
|
echo "Performing initial MySQL database setup..."
|
||||||
|
cd "${mysql_install_dir}" || { echo "Error: MySQL install directory not found."; exit 1; }
|
||||||
|
|
||||||
|
echo "Initializing MySQL database in '${mysql_data_dir}'..."
|
||||||
|
"${mysql_install_dir}/scripts/mysql_install_db" --datadir="${mysql_data_dir}" --user="${mysql_user}"
|
||||||
|
chown -R "${mysql_user}":"${mysql_group}" "${mysql_data_dir}"
|
||||||
|
|
||||||
|
# 1. 启动 MySQL 服务 (保持 --skip-name-resolve 启用)
|
||||||
|
echo "Starting MySQL service..."
|
||||||
|
systemctl start "${mysql_service}"
|
||||||
|
|
||||||
|
# 2. 等待 MySQL 服务启动并可用
|
||||||
|
echo "Waiting for MySQL server to start (up to ${timeout} seconds)..."
|
||||||
|
for i in $(seq 1 "${timeout}"); do
|
||||||
|
"${mysql_install_dir}/bin/mysqladmin" ping -h 127.0.0.1 -P 3306 &>/dev/null && break
|
||||||
|
sleep 1
|
||||||
|
done
|
||||||
|
|
||||||
|
if ! "${mysql_install_dir}/bin/mysqladmin" ping -h 127.0.0.1 -P 3306 &>/dev/null; then
|
||||||
|
echo "Error: MySQL server did not start in time for initial setup." >&2
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
echo "MySQL server is running."
|
||||||
|
|
||||||
|
# 3. 设置 root@localhost 的初始密码
|
||||||
|
# 这是 mysql_install_db 后最可靠的设置初始 root 密码的方式
|
||||||
|
echo "Setting initial root password for 'root@localhost' using mysqladmin..."
|
||||||
|
"${mysql_install_dir}/bin/mysqladmin" -uroot password "${mysql_root_password}"
|
||||||
|
echo "Initial root@localhost password set."
|
||||||
|
|
||||||
|
# 4. 更新所有 root 条目的密码 (包括 127.0.0.1, ::1, gg-3b8l1hmcqanykaan)
|
||||||
|
# 此时 --skip-name-resolve 保持启用,但我们更新的是 mysql.user 表中的条目。
|
||||||
|
# 连接时使用 'localhost',它通常可以通过 Unix socket 或特殊处理连接。
|
||||||
|
echo "Updating password for all root user entries (localhost, 127.0.0.1, ::1, gg-3b8l1hmcqanykaan)..."
|
||||||
|
"${mysql_install_dir}/bin/mysql" -uroot -p"${mysql_root_password}" -e "
|
||||||
|
UPDATE mysql.user SET Password = PASSWORD('${mysql_root_password}') WHERE User = 'root' AND Host IN ('localhost', '127.0.0.1', '::1', 'gg-3b8l1hmcqanykaan');
|
||||||
|
FLUSH PRIVILEGES;
|
||||||
|
"
|
||||||
|
echo "All relevant root user passwords updated."
|
||||||
|
|
||||||
|
# 5. 删除匿名用户和 test 数据库,进一步安全加固
|
||||||
|
echo "Securing MySQL installation (dropping anonymous users and test database)..."
|
||||||
|
"${mysql_install_dir}/bin/mysql" -uroot -p"${mysql_root_password}" -e "
|
||||||
|
DELETE FROM mysql.user WHERE User='';
|
||||||
|
DROP DATABASE IF EXISTS test;
|
||||||
|
FLUSH PRIVILEGES;
|
||||||
|
"
|
||||||
|
echo "Anonymous users and test database removed."
|
||||||
|
|
||||||
|
# 6. 导入初始数据库
|
||||||
|
echo "Importing initial database schema from '${mysql_sql_file}'..."
|
||||||
|
if [ -f "${mysql_sql_file}" ]; then
|
||||||
|
"${mysql_install_dir}/bin/mysql" -uroot -p"${mysql_root_password}" < "${mysql_sql_file}"
|
||||||
|
echo "Database initialization and import complete."
|
||||||
|
else
|
||||||
|
echo "Error: ${mysql_sql_file} not found. Database import failed." >&2
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
else # 数据目录已存在,说明不是首次安装,可能是升级或者之前安装过
|
||||||
|
echo "MySQL data directory already exists. Skipping database initialization."
|
||||||
|
|
||||||
|
fi
|
||||||
|
|
||||||
|
echo "SmartTMS MySQL installation/upgrade complete."
|
||||||
|
}
|
||||||
|
|
||||||
|
# pre_remove 钩子在卸载文件被删除之前运行
|
||||||
|
pre_remove() {
|
||||||
|
echo "Stopping MySQL service before removal..."
|
||||||
|
systemctl stop "${mysql_service}"
|
||||||
|
}
|
||||||
|
|
||||||
|
# post_remove 钩子在卸载文件被删除之后运行
|
||||||
|
post_remove() {
|
||||||
|
local remove_type="0" # 0 表示完全卸载,1 表示升级
|
||||||
|
|
||||||
|
echo "Disabling MySQL service..."
|
||||||
|
systemctl disable "${mysql_service}"
|
||||||
|
echo "Reloading systemd daemon..."
|
||||||
|
systemctl daemon-reload
|
||||||
|
|
||||||
|
# 如果是完全卸载 (即 $1 为 0),则清理用户、组和数据目录
|
||||||
|
if [ "${remove_type}" -eq 0 ]; then
|
||||||
|
echo "Performing full uninstallation cleanup..."
|
||||||
|
|
||||||
|
rm -rf /usr/local/mysql-5.6.47-linux-glibc2.12-x86_64
|
||||||
|
rm -rf /usr/local/mysql
|
||||||
|
|
||||||
|
# 警告用户数据目录将被删除
|
||||||
|
echo "WARNING: This will remove the MySQL data directory '${mysql_data_dir}' and all its data."
|
||||||
|
echo "Removing MySQL data directory '${mysql_data_dir}'..."
|
||||||
|
rm -rf "${mysql_data_dir}"
|
||||||
|
|
||||||
|
|
||||||
|
# 删除用户和组
|
||||||
|
if getent passwd "${mysql_user}" >/dev/null; then
|
||||||
|
echo "Removing user '${mysql_user}'..."
|
||||||
|
userdel "${mysql_user}"
|
||||||
|
fi
|
||||||
|
if getent group "${mysql_group}" >/dev/null; then
|
||||||
|
echo "Removing group '${mysql_group}'..."
|
||||||
|
groupdel "${mysql_group}"
|
||||||
|
fi
|
||||||
|
|
||||||
|
# 删除 PATH 环境变量配置脚本
|
||||||
|
echo "Removing PATH configuration script '/etc/profile.d/mysql.sh'..."
|
||||||
|
rm -f /etc/profile.d/mysql.sh
|
||||||
|
echo "Full uninstallation cleanup complete."
|
||||||
|
else # remove_type is 1 (upgrade)
|
||||||
|
echo "MySQL package upgraded. Data directory and user/group are retained."
|
||||||
|
fi
|
||||||
|
}
|
||||||
1799
tms_db_s3.sql
Normal file
1799
tms_db_s3.sql
Normal file
File diff suppressed because it is too large
Load Diff
68
up+.sh
Executable file
68
up+.sh
Executable file
@@ -0,0 +1,68 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
#set -e
|
||||||
|
##################################################################################################################
|
||||||
|
# Author : Erik Dubois
|
||||||
|
# Website : https://www.erikdubois.be
|
||||||
|
# Website : https://www.alci.online
|
||||||
|
# Website : https://www.ariser.eu
|
||||||
|
# Website : https://www.arcolinux.info
|
||||||
|
# Website : https://www.arcolinux.com
|
||||||
|
# Website : https://www.arcolinuxd.com
|
||||||
|
# Website : https://www.arcolinuxb.com
|
||||||
|
# Website : https://www.arcolinuxiso.com
|
||||||
|
# Website : https://www.arcolinuxforum.com
|
||||||
|
##################################################################################################################
|
||||||
|
#
|
||||||
|
# DO NOT JUST RUN THIS. EXAMINE AND JUDGE. RUN AT YOUR OWN RISK.
|
||||||
|
#
|
||||||
|
##################################################################################################################
|
||||||
|
#tput setaf 0 = black
|
||||||
|
#tput setaf 1 = red
|
||||||
|
#tput setaf 2 = green
|
||||||
|
#tput setaf 3 = yellow
|
||||||
|
#tput setaf 4 = dark blue
|
||||||
|
#tput setaf 5 = purple
|
||||||
|
#tput setaf 6 = cyan
|
||||||
|
#tput setaf 7 = gray
|
||||||
|
#tput setaf 8 = light blue
|
||||||
|
##################################################################################################################
|
||||||
|
|
||||||
|
# reset - commit your changes or stash them before you merge
|
||||||
|
# git reset --hard - personal alias - grh
|
||||||
|
|
||||||
|
echo "Deleting the work folder if one exists"
|
||||||
|
[ -d work ] && rm -rf work
|
||||||
|
|
||||||
|
# checking if I have the latest files from github
|
||||||
|
echo "Checking for newer files online first"
|
||||||
|
git pull
|
||||||
|
|
||||||
|
# Below command will backup everything inside the project folder
|
||||||
|
git add --all .
|
||||||
|
|
||||||
|
# Give a comment to the commit if you want
|
||||||
|
echo "####################################"
|
||||||
|
echo "Write your commit comment!"
|
||||||
|
echo "####################################"
|
||||||
|
|
||||||
|
read input
|
||||||
|
|
||||||
|
# Committing to the local repository with a message containing the time details and commit text
|
||||||
|
|
||||||
|
git commit -m "$input"
|
||||||
|
|
||||||
|
# Push the local files to github
|
||||||
|
|
||||||
|
if grep -q main .git/config; then
|
||||||
|
echo "Using main"
|
||||||
|
git push -u origin main
|
||||||
|
fi
|
||||||
|
|
||||||
|
if grep -q master .git/config; then
|
||||||
|
echo "Using master"
|
||||||
|
git push -u origin master
|
||||||
|
fi
|
||||||
|
|
||||||
|
echo "################################################################"
|
||||||
|
echo "################### Git Push Done ######################"
|
||||||
|
echo "################################################################"
|
||||||
Reference in New Issue
Block a user