修复错误,优化性能,实现类型系统,优化安装卸载过程
This commit is contained in:
1 parent
fd5f320360
commit
48eec484b7
104 files changed
+4127
-845
No files matched your search
@@ -1,57 +0,0 @@
|
||||
# ChuSQL 全局配置。
|
||||
#
|
||||
# 整条链路共用这一份文件,按分区各管各的,互不影响:
|
||||
# 数据库服务:[server](TCP 监听地址、端口、单行上限、单次结果行数上限)
|
||||
# —— 只有它装入 chusql_core_storage 动态库并独占数据目录
|
||||
# Web / 命令行:[web](账号名、会话、分页上限、静态目录),都经 [server] 走
|
||||
# 数据目录在 [storage] data_dir;这一行是安装时会替换的占位:
|
||||
# 不写就按平台惯例(Windows %LOCALAPPDATA%\ChuSQL\data,
|
||||
# Unix ${XDG_DATA_HOME:-$HOME/.local/share}/chusql/data)。
|
||||
# 每一层只读自己那几段,读完就关,不长期占着文件句柄,别的层照样能读。
|
||||
# 只有这一份文件说了算:没有任何环境变量覆盖。
|
||||
# 位置是固定的:Windows 在 %APPDATA%\ChuSQL\chusql.toml,其它平台在
|
||||
# $XDG_CONFIG_HOME/ChuSQL/chusql.toml(没设就是 ~/.config/ChuSQL/chusql.toml)。
|
||||
# 想临时读别处,三个可执行文件都认命令行 --config <path>。
|
||||
|
||||
[page]
|
||||
size = 4096
|
||||
|
||||
[btree]
|
||||
order = 4
|
||||
|
||||
[buffer]
|
||||
pool_size = 1024
|
||||
|
||||
[storage]
|
||||
# 安装时被替换成实际数据目录(--data-dir / -DataDir);不写就按平台惯例:
|
||||
# Windows %LOCALAPPDATA%\ChuSQL\data,Unix ${XDG_DATA_HOME:-$HOME/.local/share}/chusql/data
|
||||
data_dir = "../localdata"
|
||||
|
||||
# TCP 数据库服务(chusql-server)。单独一段,别层的进程不认识它、也不需要认识。
|
||||
[server]
|
||||
host = "127.0.0.1"
|
||||
port = 7777
|
||||
max_message = 1048576
|
||||
max_rows = 1000
|
||||
|
||||
[log]
|
||||
level = "info"
|
||||
|
||||
[web]
|
||||
host = "127.0.0.1"
|
||||
port = 7778
|
||||
static_dir = "static"
|
||||
# 管理员账号名。口令存在系统表 __system_users 里,不写进这份文件;
|
||||
# 首启为空口令,登录后用 ALTER USER 或在 Web 账号页设置。
|
||||
user = "root"
|
||||
# 会话与登录限流
|
||||
session_idle = 28800
|
||||
session_max = 86400
|
||||
login_max_attempts = 5
|
||||
login_window = 300
|
||||
# 请求与分页上限
|
||||
body_limit = 65536
|
||||
rows_per_page = 25
|
||||
max_page_size = 500
|
||||
max_rows = 1000
|
||||
max_sql_length = 20000
|
||||
+10
-8
@@ -1,6 +1,6 @@
|
||||
$ErrorActionPreference = 'Stop'
|
||||
|
||||
# csql-web:先起独占数据目录的 server,再起 Web 服务,配置读 chusql.toml。
|
||||
# csql-web:先起独占数据目录的 server,再起 Web 服务,配置读 settings.toml。
|
||||
|
||||
# 打印错误并退出 1。
|
||||
function Fail([string]$msg) { Write-Host "!! $msg" -ForegroundColor Red; exit 1 }
|
||||
@@ -11,16 +11,16 @@ $home_dir = Split-Path -Parent $MyInvocation.MyCommand.Path
|
||||
$bin = Join-Path $home_dir 'bin'
|
||||
|
||||
$config_dir = if ($env:APPDATA) { Join-Path $env:APPDATA 'ChuSQL' } else { Join-Path $home_dir 'config' }
|
||||
$config = Join-Path $config_dir 'chusql.toml'
|
||||
$config = Join-Path $config_dir 'settings.toml'
|
||||
if (-not (Test-Path $config)) { Fail "config not found: $config" }
|
||||
|
||||
# 从配置里取一个 [web] 段的值。
|
||||
function Get-WebSetting([string]$Key, [string]$Default) {
|
||||
# 从配置里取某个分区的一个值。
|
||||
function Get-SectionSetting([string]$Section, [string]$Key, [string]$Default) {
|
||||
$section = ''
|
||||
$pattern = '^\s*' + [regex]::Escape($Key) + '\s*='
|
||||
foreach ($raw in (Get-Content -Path $config -Encoding UTF8)) {
|
||||
if ($raw -match '^\s*\[') { $section = ($raw -replace '[\[\]\s]', ''); continue }
|
||||
if ($section -ne 'web') { continue }
|
||||
if ($section -ne $Section) { continue }
|
||||
$line = $raw -replace '#.*$', ''
|
||||
if ($line -match $pattern) {
|
||||
return (($line -replace '^[^=]*=\s*', '').Trim().Trim('"'))
|
||||
@@ -34,9 +34,11 @@ $web_exe = Join-Path $bin 'chusql-web.exe'
|
||||
if (-not (Test-Path $server_exe)) { Fail "server binary not found in $bin" }
|
||||
if (-not (Test-Path $web_exe)) { Fail "web binary not found in $bin" }
|
||||
|
||||
$host_addr = Get-WebSetting 'host' '127.0.0.1'
|
||||
$port = Get-WebSetting 'port' '7778'
|
||||
$log_dir = Join-Path $home_dir 'logs'
|
||||
# 监听地址与端口取 [web] 段,日志目录取 [storage] log_files(相对路径以安装目录为基准)。
|
||||
$host_addr = Get-SectionSetting 'web' 'listen_host' '127.0.0.1'
|
||||
$port = Get-SectionSetting 'web' 'port' '7778'
|
||||
$log_setting = Get-SectionSetting 'storage' 'log_files' './logs'
|
||||
$log_dir = if ([System.IO.Path]::IsPathRooted($log_setting)) { $log_setting } else { Join-Path $home_dir $log_setting }
|
||||
New-Item -ItemType Directory -Force -Path $log_dir | Out-Null
|
||||
|
||||
$server = $null
|
||||
|
||||
+15
-10
@@ -1,24 +1,24 @@
|
||||
#!/bin/sh
|
||||
set -eu
|
||||
|
||||
# csql-web:先起独占数据目录的 server,再起 Web 服务,配置读 chusql.toml。
|
||||
# csql-web:先起独占数据目录的 server,再起 Web 服务,配置读 settings.toml。
|
||||
|
||||
home_dir=$(CDPATH= cd -- "$(dirname -- "$0")" && pwd)
|
||||
bin="$home_dir/bin"
|
||||
|
||||
# 和在 Windows 的 csql-web.ps1(Start-Process -WorkingDirectory)保持一致:
|
||||
# 先切到安装目录,配置里写相对的 static_dir / data_dir 才有确定的解析基准。
|
||||
# 先切到安装目录,配置里写相对的 log_files 才有确定的解析基准。
|
||||
cd "$home_dir"
|
||||
|
||||
config_dir="${XDG_CONFIG_HOME:-$HOME/.config}/ChuSQL"
|
||||
config="$config_dir/chusql.toml"
|
||||
config="$config_dir/settings.toml"
|
||||
[ -f "$config" ] || { echo "!! config not found: $config" >&2; exit 1; }
|
||||
|
||||
# 从配置里取一个 [web] 段的值。
|
||||
web_setting() {
|
||||
awk -v key="$1" -v def="$2" '
|
||||
# 从配置里取某分区的一个值。
|
||||
section_setting() {
|
||||
awk -v section_key="$1" -v key="$2" -v def="$3" '
|
||||
/^[[:space:]]*\[/ { section = $0; gsub(/[][[:space:]]/, "", section); next }
|
||||
section != "web" { next }
|
||||
section != section_key { next }
|
||||
{
|
||||
line = $0
|
||||
sub(/#.*/, "", line)
|
||||
@@ -40,9 +40,14 @@ web_exe="$bin/chusql-web"
|
||||
[ -x "$server_exe" ] || { echo "!! server binary not found in $bin" >&2; exit 1; }
|
||||
[ -x "$web_exe" ] || { echo "!! web binary not found in $bin" >&2; exit 1; }
|
||||
|
||||
host=$(web_setting host 127.0.0.1)
|
||||
port=$(web_setting port 7778)
|
||||
log_dir="$home_dir/logs"
|
||||
# 监听地址与端口取 [web] 段,日志目录取 [storage] log_files(相对路径以安装目录为基准)。
|
||||
host=$(section_setting web listen_host 127.0.0.1)
|
||||
port=$(section_setting web port 7778)
|
||||
log_setting=$(section_setting storage log_files ./logs)
|
||||
case "$log_setting" in
|
||||
/*) log_dir="$log_setting" ;;
|
||||
*) log_dir="$home_dir/$log_setting" ;;
|
||||
esac
|
||||
mkdir -p "$log_dir"
|
||||
|
||||
# server 先起来:它进程内装入存储库、独占数据目录,Web 的存储请求都经它转发
|
||||
|
||||
+18
-18
@@ -166,7 +166,7 @@ if (-not $Component) {
|
||||
}
|
||||
|
||||
# 管理员口令是装机必答项:交互时当场设,非交互时给 -Password 或
|
||||
# CHUSQL_ADMIN_PASSWORD。口令只经 stdin 传给 csql-bootstrap,不落 chusql.toml。
|
||||
# CHUSQL_ADMIN_PASSWORD。口令只经 stdin 传给 csql-bootstrap,不落 settings.toml。
|
||||
$adminPassword = "$env:CHUSQL_ADMIN_PASSWORD"
|
||||
if ($Password) { $adminPassword = $Password }
|
||||
if ($canPrompt) {
|
||||
@@ -202,7 +202,8 @@ $downloaded = $false
|
||||
$tempDir = ''
|
||||
|
||||
if (-not $InstallDir) { $InstallDir = Join-Path $env:LOCALAPPDATA 'ChuSQL' }
|
||||
if (-not $DataDir) { $DataDir = Join-Path $InstallDir 'data' }
|
||||
if (-not $DataDir) { $DataDir = Join-Path (Join-Path $env:LOCALAPPDATA 'ChuSQL') 'data' }
|
||||
$LogDir = Join-Path (Join-Path $env:LOCALAPPDATA 'ChuSQL') 'logs'
|
||||
$InstallDir = [System.IO.Path]::GetFullPath($InstallDir)
|
||||
$DataDir = [System.IO.Path]::GetFullPath($DataDir)
|
||||
|
||||
@@ -289,8 +290,8 @@ if ($wantWeb) {
|
||||
if ($wantCli) {
|
||||
if (-not (Test-Path (Join-Path $pack 'bin\csql.exe'))) { Fail 'package is incomplete: bin\csql.exe not found' }
|
||||
}
|
||||
$template = Join-Path $pack 'scripts\chusql.toml'
|
||||
if (-not (Test-Path $template)) { Fail 'package is incomplete: scripts\chusql.toml not found' }
|
||||
$template = Join-Path $pack 'resources\settings.toml.windows'
|
||||
if (-not (Test-Path $template)) { Fail 'package is incomplete: resources\settings.toml.windows not found' }
|
||||
|
||||
Say "ChuSQL installer"
|
||||
Say (" version {0}" -f $Version)
|
||||
@@ -298,12 +299,12 @@ Say (" components {0}" -f $componentLabel)
|
||||
if ($downloaded) { Say (" release {0}" -f $Version) }
|
||||
Say (" install to {0}" -f $InstallDir)
|
||||
Say (" data dir {0}" -f $DataDir)
|
||||
Say (" root user {0} (password asked above, kept out of chusql.toml)" -f $RootUser)
|
||||
Say (" root user {0} (password asked above, kept out of settings.toml)" -f $RootUser)
|
||||
|
||||
# ---- 释放文件 ----
|
||||
# 包是合在一起的(web 和 cli 都在),这里按这次的选择逐个释放:没选的组件不落地
|
||||
Step 'Installing files'
|
||||
New-Item -ItemType Directory -Force -Path (Join-Path $InstallDir 'bin'), (Join-Path $InstallDir 'logs'), $DataDir | Out-Null
|
||||
New-Item -ItemType Directory -Force -Path (Join-Path $InstallDir 'bin'), $LogDir, $DataDir | Out-Null
|
||||
Copy-Item $storageLib (Join-Path $InstallDir 'bin') -Force
|
||||
Copy-Item (Join-Path $pack 'bin\chusql-server.exe') (Join-Path $InstallDir 'bin') -Force
|
||||
Copy-Item (Join-Path $pack 'bin\csql-bootstrap.exe') (Join-Path $InstallDir 'bin') -Force
|
||||
@@ -325,26 +326,25 @@ if ($wantWeb) {
|
||||
}
|
||||
|
||||
# ---- 写全局配置 ----
|
||||
Step 'Writing chusql.toml'
|
||||
Step 'Writing settings.toml'
|
||||
$configDir = if ($env:APPDATA) { Join-Path $env:APPDATA 'ChuSQL' } else { Join-Path $InstallDir 'config' }
|
||||
$configFile = Join-Path $configDir 'chusql.toml'
|
||||
$configFile = Join-Path $configDir 'settings.toml'
|
||||
$toml = Get-Content -Path $template -Raw -Encoding UTF8
|
||||
$toml = $toml -replace '(?m)^(\s*user\s*=\s*).*$', "`$1`"$RootUser`""
|
||||
$toml = $toml -replace '(?m)^(\s*data_dir\s*=\s*).*$', "`$1`"$($DataDir -replace '\\', '/')`""
|
||||
$toml = $toml.Replace('@DATA_DIR@', ($DataDir -replace '\\', '/')).Replace('@LOG_DIR@', ($LogDir -replace '\\', '/'))
|
||||
New-Item -ItemType Directory -Force -Path $configDir | Out-Null
|
||||
Set-Content -Path $configFile -Value $toml -Encoding UTF8
|
||||
Say (" config file {0}" -f $configFile)
|
||||
|
||||
# ---- 引导系统目录 ----
|
||||
# csql-bootstrap 建 system 数据库和 __system_users 表,口令只走 stdin,不进 chusql.toml
|
||||
Step 'Creating the system catalog'
|
||||
# 引导身份目录、root 与预装类型,口令通过标准输入传递
|
||||
Step 'Initializing the administrator identity and preinstalled types'
|
||||
$bootstrap = Join-Path $InstallDir 'bin\csql-bootstrap.exe'
|
||||
$bootstrapArgs = @('--config', $configFile, '--user', $RootUser)
|
||||
$bootstrapArgs += '--password-stdin'
|
||||
$bootstrapOutput = $adminPassword | & $bootstrap @bootstrapArgs 2>&1
|
||||
$bootstrapOutput | ForEach-Object { Say (" {0}" -f $_) }
|
||||
if ($LASTEXITCODE -ne 0) {
|
||||
Fail ("the bootstrap program failed (exit {0}); the system catalog is not ready" -f $LASTEXITCODE)
|
||||
Fail ("the bootstrap program failed (exit {0}); identities or preinstalled types are not ready" -f $LASTEXITCODE)
|
||||
}
|
||||
|
||||
# ---- 命令入口 ----
|
||||
@@ -401,11 +401,11 @@ $serverPid = 0
|
||||
if ($NoStart) {
|
||||
Say ' -NoStart: the server was not started'
|
||||
} else {
|
||||
$serverLog = Join-Path $InstallDir 'logs\server.err.log'
|
||||
$serverLog = Join-Path $LogDir 'server.err.log'
|
||||
$serverProc = Start-Process -FilePath $serverPath `
|
||||
-ArgumentList @('--config', $configFile) `
|
||||
-ArgumentList @('--config', $configFile, '--user', $RootUser) `
|
||||
-WorkingDirectory $InstallDir -WindowStyle Hidden -PassThru `
|
||||
-RedirectStandardOutput (Join-Path $InstallDir 'logs\server.log') `
|
||||
-RedirectStandardOutput (Join-Path $LogDir 'server.log') `
|
||||
-RedirectStandardError $serverLog
|
||||
Start-Sleep -Milliseconds 1200
|
||||
if ($serverProc.HasExited) {
|
||||
@@ -417,13 +417,13 @@ if ($NoStart) {
|
||||
}
|
||||
|
||||
Step 'Done'
|
||||
Say (" chusql.toml {0}" -f $configFile)
|
||||
Say (" settings.toml {0}" -f $configFile)
|
||||
Say (" data {0}" -f $DataDir)
|
||||
$startWith = @()
|
||||
if ($wantWeb) { $startWith += 'csql-web' }
|
||||
if ($wantCli) { $startWith += 'csql' }
|
||||
Say (" start with {0}" -f ($startWith -join ', '))
|
||||
Say (" tcp server {0} (listens on [server] host/port, defaults 127.0.0.1:7777)" -f $serverPath)
|
||||
Say (" tcp server {0} (listens on [server] listen_host/port, defaults 127.0.0.1:7777)" -f $serverPath)
|
||||
if ($serverPid -gt 0) {
|
||||
Say (" running pid {0} (stop it with: Stop-Process -Id {0})" -f $serverPid)
|
||||
} else {
|
||||
|
||||
+25
-24
@@ -30,7 +30,7 @@ usage: ./install.sh [--component web|cli|both] [options]
|
||||
web front end (browser UI)? default no [y/N]
|
||||
it then asks whether to give the administrator account a
|
||||
password (default no); that password goes straight into the
|
||||
system catalog and is never written to chusql.toml
|
||||
system catalog and is never written to settings.toml
|
||||
|
||||
--interactive ask even when there is no terminal; the answers are
|
||||
read from stdin (one per line)
|
||||
@@ -129,7 +129,8 @@ case "$self" in
|
||||
esac
|
||||
|
||||
[ -n "$install_dir" ] || install_dir="$HOME/.local/share/chusql"
|
||||
[ -n "$data_dir" ] || data_dir="$install_dir/data"
|
||||
[ -n "$data_dir" ] || data_dir="${XDG_DATA_HOME:-$HOME/.local/share}/chusql/data"
|
||||
log_dir="${XDG_STATE_HOME:-$HOME/.local/state}/chusql/logs"
|
||||
|
||||
# ---- 交互:先确定答案从哪来 ----
|
||||
# 管道安装(curl ... | sh -s --)时 stdin 是脚本本身,所以优先开 /dev/tty;
|
||||
@@ -203,7 +204,7 @@ if [ "$component" = '' ] && [ "$list_versions" = 'no' ]; then
|
||||
fi
|
||||
|
||||
# 管理员口令是装机必答项:交互时当场设,非交互时给 --password 或
|
||||
# CHUSQL_ADMIN_PASSWORD。口令只经 stdin 传给 csql-bootstrap,不落 chusql.toml。
|
||||
# CHUSQL_ADMIN_PASSWORD。口令只经 stdin 传给 csql-bootstrap,不落 settings.toml。
|
||||
admin_password="${CHUSQL_ADMIN_PASSWORD:-}"
|
||||
if [ "$list_versions" = 'no' ]; then
|
||||
if [ -n "$password_arg" ]; then
|
||||
@@ -491,7 +492,7 @@ if [ "$from_source" = 'yes' ]; then
|
||||
note "source $src"
|
||||
fi
|
||||
[ -f "$src/chusql-core/storage/Cargo.toml" ] || fail "not a ChuSQL checkout (chusql-core/storage/Cargo.toml missing): $src"
|
||||
[ -f "$src/scripts/chusql.toml" ] || fail "not a ChuSQL checkout (scripts/chusql.toml missing): $src"
|
||||
[ -f "$src/resources/settings.toml.linux" ] || fail "not a ChuSQL checkout (resources/settings.toml.linux missing): $src"
|
||||
|
||||
if command -v pkg-config >/dev/null 2>&1 && ! pkg-config --exists zlib 2>/dev/null; then
|
||||
note 'hint the Haskell zlib binding needs the C library: apt-get install zlib1g-dev (or dnf install zlib-devel)'
|
||||
@@ -504,9 +505,9 @@ if [ "$from_source" = 'yes' ]; then
|
||||
|
||||
step 'Staging the package'
|
||||
pack="$tmp/stage"
|
||||
mkdir -p "$pack/bin" "$pack/scripts"
|
||||
mkdir -p "$pack/bin" "$pack/resources"
|
||||
cp "$storage_lib" "$pack/bin/"
|
||||
cp "$src/scripts/chusql.toml" "$pack/scripts/"
|
||||
cp "$src/resources/settings.toml.linux" "$pack/resources/"
|
||||
cp "$src/scripts/install.sh" "$pack/"
|
||||
for comp in $wanted; do
|
||||
if [ "$comp" = 'web' ]; then
|
||||
@@ -605,19 +606,19 @@ fi
|
||||
if [ "$want_cli" = 'yes' ]; then
|
||||
[ -f "$pack/bin/csql" ] || fail 'package is incomplete: bin/csql not found'
|
||||
fi
|
||||
[ -f "$pack/scripts/chusql.toml" ] || fail 'package is incomplete: scripts/chusql.toml not found'
|
||||
[ -f "$pack/resources/settings.toml.linux" ] || fail 'package is incomplete: resources/settings.toml.linux not found'
|
||||
|
||||
echo 'ChuSQL installer'
|
||||
echo " version $version"
|
||||
echo " components $component_label"
|
||||
echo " install to $install_dir"
|
||||
echo " data dir $data_dir"
|
||||
echo " root user $root_user (password asked above, kept out of chusql.toml)"
|
||||
echo " root user $root_user (password asked above, kept out of settings.toml)"
|
||||
|
||||
# ---- 释放文件 ----
|
||||
# 包是合在一起的(web 和 cli 都在),这里按这次的选择逐个释放:没选的组件不落地
|
||||
step 'Installing files'
|
||||
mkdir -p "$install_dir/bin" "$install_dir/logs" "$data_dir"
|
||||
mkdir -p "$install_dir/bin" "$log_dir" "$data_dir"
|
||||
cp "$pack/bin/chusql-server" "$install_dir/bin/"
|
||||
cp "$pack/bin/csql-bootstrap" "$install_dir/bin/"
|
||||
for lib in "$pack/bin/"libchusql_core_storage.*; do
|
||||
@@ -641,22 +642,22 @@ fi
|
||||
chmod +x "$install_dir/bin/"* 2>/dev/null || true
|
||||
|
||||
# ---- 写全局配置 ----
|
||||
step 'Writing chusql.toml'
|
||||
step 'Writing settings.toml'
|
||||
config_dir="${XDG_CONFIG_HOME:-$HOME/.config}/ChuSQL"
|
||||
config_file="$config_dir/chusql.toml"
|
||||
config_file="$config_dir/settings.toml"
|
||||
mkdir -p "$config_dir"
|
||||
sed -e "s|^\(user[[:space:]]*=[[:space:]]*\).*|\1\"$root_user\"|" \
|
||||
-e "s|^\(data_dir[[:space:]]*=[[:space:]]*\).*|\1\"$data_dir\"|" \
|
||||
"$pack/scripts/chusql.toml" > "$config_file"
|
||||
sed -e "s|@DATA_DIR@|$(printf '%s' "$data_dir" | sed 's/[\&|]/\\&/g')|g" \
|
||||
-e "s|@LOG_DIR@|$(printf '%s' "$log_dir" | sed 's/[\&|]/\\&/g')|g" \
|
||||
"$pack/resources/settings.toml.linux" > "$config_file"
|
||||
echo " config file $config_file"
|
||||
|
||||
# ---- 引导系统目录 ----
|
||||
# csql-bootstrap 建 system 数据库和 __system_users 表;口令只走 stdin,不进 chusql.toml
|
||||
step 'Creating the system catalog'
|
||||
# 引导身份目录、root 与预装类型,口令通过标准输入传递
|
||||
step 'Initializing the administrator identity and preinstalled types'
|
||||
bootstrap="$install_dir/bin/csql-bootstrap"
|
||||
[ -n "$admin_password" ] || fail 'the administrator password is required'
|
||||
printf '%s\n' "$admin_password" | "$bootstrap" --config "$config_file" --user "$root_user" --password-stdin ||
|
||||
fail 'the bootstrap program failed; the system catalog is not ready'
|
||||
fail 'the bootstrap program failed; identities or preinstalled types are not ready'
|
||||
|
||||
# ---- 命令入口 ----
|
||||
step 'Creating commands'
|
||||
@@ -717,19 +718,19 @@ if [ "$no_start" = 'yes' ]; then
|
||||
note '--no-start: the server was not started'
|
||||
else
|
||||
step 'Starting the server'
|
||||
mkdir -p "$install_dir/logs"
|
||||
nohup "$server_bin" --config "$config_file" > "$install_dir/logs/server.log" 2> "$install_dir/logs/server.err.log" &
|
||||
mkdir -p "$log_dir"
|
||||
nohup "$server_bin" --config "$config_file" --user "$root_user" > "$log_dir/server.log" 2> "$log_dir/server.err.log" &
|
||||
server_pid=$!
|
||||
sleep 1
|
||||
if ! kill -0 "$server_pid" 2>/dev/null; then
|
||||
fail "the server stopped right away; look at $install_dir/logs/server.err.log"
|
||||
fail "the server stopped right away; look at $log_dir/server.err.log"
|
||||
fi
|
||||
note "server running, pid $server_pid"
|
||||
note "log $install_dir/logs/server.err.log"
|
||||
note "log $log_dir/server.err.log"
|
||||
fi
|
||||
|
||||
step 'Done'
|
||||
echo " chusql.toml $config_file"
|
||||
echo " settings.toml $config_file"
|
||||
echo " data $data_dir"
|
||||
start_with=''
|
||||
if [ "$want_web" = 'yes' ]; then start_with='csql-web'; fi
|
||||
@@ -737,9 +738,9 @@ if [ "$want_cli" = 'yes' ]; then
|
||||
if [ -n "$start_with" ]; then start_with="$start_with, csql"; else start_with='csql'; fi
|
||||
fi
|
||||
echo " start with $start_with"
|
||||
echo " tcp server $server_bin (listens on [server] host/port, defaults 127.0.0.1:7777)"
|
||||
echo " tcp server $server_bin (listens on [server] listen_host/port, defaults 127.0.0.1:7777)"
|
||||
if [ -n "$server_pid" ]; then
|
||||
echo " running pid $server_pid (stop it with: kill $server_pid)"
|
||||
else
|
||||
echo " start it $server_bin --config \"$config_file\""
|
||||
echo " start it $server_bin --config \"$config_file\" --user $root_user"
|
||||
fi
|
||||
+12
-5
@@ -57,7 +57,7 @@ function Assert-Stage([string]$stage) {
|
||||
'bin\csql-bootstrap.exe',
|
||||
'static\index.html',
|
||||
'csql-web.ps1',
|
||||
'scripts\chusql.toml',
|
||||
'resources\settings.toml.windows',
|
||||
'install.ps1',
|
||||
'install.sh',
|
||||
'uninstall.ps1',
|
||||
@@ -110,7 +110,10 @@ function Test-Installed([string]$name, [string]$comp) {
|
||||
(Join-Path $opt 'bin\chusql-server.exe'),
|
||||
(Join-Path $opt 'bin\csql-bootstrap.exe'),
|
||||
(Join-Path $data 'system\catalog.json'),
|
||||
(Join-Path $appdata 'ChuSQL\chusql.toml')
|
||||
(Join-Path $data 'system\__system_identities.db'),
|
||||
(Join-Path $data 'system\__system_users.db'),
|
||||
(Join-Path $data 'system\__system_types.db'),
|
||||
(Join-Path $appdata 'ChuSQL\settings.toml')
|
||||
)
|
||||
$forbidden = @()
|
||||
if ($comp -eq 'web') {
|
||||
@@ -130,7 +133,11 @@ function Test-Installed([string]$name, [string]$comp) {
|
||||
}
|
||||
foreach ($f in $checks) { if (-not (Test-Path $f)) { $ok = $false; Write-Host " missing: $f" } }
|
||||
foreach ($f in $forbidden) { if (Test-Path $f) { $ok = $false; Write-Host " should not be there: $f" } }
|
||||
$config = Join-Path $appdata 'ChuSQL\chusql.toml'
|
||||
$systemCatalog = Get-Content -LiteralPath (Join-Path $data 'system\catalog.json') -Raw | ConvertFrom-Json
|
||||
if (-not $systemCatalog.tables.__system_types.system -or $systemCatalog.tables.__system_types.row_count -lt 18) {
|
||||
Fail "$name`: preinstalled types were not initialized during installation"
|
||||
}
|
||||
$config = Join-Path $appdata 'ChuSQL\settings.toml'
|
||||
$expectDataDir = $data -replace '\\', '/'
|
||||
if (-not (Test-Path $config) -or -not (Select-String -Path $config -SimpleMatch "data_dir = ""$expectDataDir""" -Quiet)) {
|
||||
$ok = $false
|
||||
@@ -190,7 +197,7 @@ New-Item -ItemType Directory -Force -Path $OutDir | Out-Null
|
||||
try {
|
||||
Step "Packing $name"
|
||||
if (Test-Path $stageRoot) { Remove-Item -Recurse -Force $stageRoot }
|
||||
New-Item -ItemType Directory -Force -Path (Join-Path $stage 'bin'), (Join-Path $stage 'scripts') | Out-Null
|
||||
New-Item -ItemType Directory -Force -Path (Join-Path $stage 'bin'), (Join-Path $stage 'resources') | Out-Null
|
||||
|
||||
$storage = Join-Path $repoRoot 'chusql-core\storage\target\release\chusql_core_storage.dll'
|
||||
if (-not (Test-Path $storage)) { Fail 'chusql-core\storage\target\release\chusql_core_storage.dll is not built (run without -NoBuild)' }
|
||||
@@ -227,7 +234,7 @@ try {
|
||||
Where-Object { $_.Name -notlike 'chusql*' } |
|
||||
ForEach-Object { Copy-Item $_.FullName (Join-Path $stage 'bin') }
|
||||
|
||||
Copy-Item (Join-Path $repoRoot 'scripts\chusql.toml') (Join-Path $stage 'scripts')
|
||||
Copy-Item (Join-Path $repoRoot 'resources\settings.toml.windows') (Join-Path $stage 'resources')
|
||||
Copy-Item (Join-Path $repoRoot 'scripts\install.ps1'), (Join-Path $repoRoot 'scripts\install.sh') $stage
|
||||
Copy-Item (Join-Path $repoRoot 'scripts\uninstall.ps1'), (Join-Path $repoRoot 'scripts\uninstall.sh') $stage
|
||||
New-Item -ItemType Directory -Force -Path (Join-Path $stage 'static') | Out-Null
|
||||
|
||||
+8
-5
@@ -93,7 +93,7 @@ check_stage() {
|
||||
[ -f "$stage/bin/csql-bootstrap" ] || Fail 'bin/csql-bootstrap is missing from the package'
|
||||
[ -f "$stage/static/index.html" ] || Fail 'static/index.html is missing from the package'
|
||||
[ -f "$stage/csql-web.sh" ] || Fail 'csql-web.sh is missing from the package'
|
||||
[ -f "$stage/scripts/chusql.toml" ] || Fail 'scripts/chusql.toml is missing from the package'
|
||||
[ -f "$stage/resources/settings.toml.linux" ] || Fail 'resources/settings.toml.linux is missing from the package'
|
||||
[ -f "$stage/install.sh" ] || Fail 'install.sh is missing from the package'
|
||||
[ -f "$stage/install.ps1" ] || Fail 'install.ps1 is missing from the package'
|
||||
[ -f "$stage/uninstall.sh" ] || Fail 'uninstall.sh is missing from the package'
|
||||
@@ -133,8 +133,11 @@ verify_package() {
|
||||
[ -f "$vtmp/opt/bin/chusql-server" ] || ok=no
|
||||
[ -f "$vtmp/opt/bin/csql-bootstrap" ] || ok=no
|
||||
[ -f "$vtmp/data/system/catalog.json" ] || ok=no
|
||||
[ -f "$vtmp/home/.config/ChuSQL/chusql.toml" ] || ok=no
|
||||
grep -q "data_dir = \"$vtmp/data\"" "$vtmp/home/.config/ChuSQL/chusql.toml" || ok=no
|
||||
[ -f "$vtmp/data/system/__system_identities.db" ] || ok=no
|
||||
[ -f "$vtmp/data/system/__system_users.db" ] || ok=no
|
||||
[ -f "$vtmp/data/system/__system_types.db" ] || ok=no
|
||||
[ -f "$vtmp/home/.config/ChuSQL/settings.toml" ] || ok=no
|
||||
grep -q "data_dir = \"$vtmp/data\"" "$vtmp/home/.config/ChuSQL/settings.toml" || ok=no
|
||||
if [ "$comp" = web ]; then
|
||||
[ -f "$vtmp/opt/bin/chusql-web" ] || ok=no
|
||||
[ -f "$vtmp/opt/static/index.html" ] || ok=no
|
||||
@@ -183,7 +186,7 @@ trap 'rm -rf "$out_dir/.stage"' EXIT INT TERM
|
||||
|
||||
Step "Packing $name"
|
||||
rm -rf "$out_dir/.stage"
|
||||
mkdir -p "$stage/bin" "$stage/scripts"
|
||||
mkdir -p "$stage/bin" "$stage/resources"
|
||||
|
||||
cp "$repo_root/chusql-core/storage/target/release/"libchusql_core_storage.* "$stage/bin/" \
|
||||
|| Fail "chusql-core/storage/target/release/libchusql_core_storage.* is not built (run without --no-build)"
|
||||
@@ -217,7 +220,7 @@ for lib in "$repo_root"/chusql-core/storage/target/release/*.so "$repo_root"/chu
|
||||
cp "$lib" "$stage/bin/"
|
||||
done
|
||||
|
||||
cp "$repo_root/scripts/chusql.toml" "$stage/scripts/"
|
||||
cp "$repo_root/resources/settings.toml.linux" "$stage/resources/"
|
||||
cp "$repo_root/scripts/install.sh" "$repo_root/scripts/install.ps1" "$repo_root/scripts/uninstall.sh" "$repo_root/scripts/uninstall.ps1" "$stage/"
|
||||
mkdir -p "$stage/static"
|
||||
cp -R "$repo_root"/chusql-web/static/. "$stage/static/"
|
||||
|
||||
@@ -20,11 +20,11 @@ function Say([string]$msg) { Write-Host $msg }
|
||||
function Fail([string]$msg) { Write-Host "!! $msg" -ForegroundColor Red; exit 1 }
|
||||
|
||||
if (-not $InstallDir) { $InstallDir = Join-Path $env:LOCALAPPDATA 'ChuSQL' }
|
||||
if (-not $DataDir) { $DataDir = Join-Path $InstallDir 'data' }
|
||||
if (-not $DataDir) { $DataDir = Join-Path (Join-Path $env:LOCALAPPDATA 'ChuSQL') 'data' }
|
||||
$InstallDir = [System.IO.Path]::GetFullPath($InstallDir)
|
||||
$DataDir = [System.IO.Path]::GetFullPath($DataDir)
|
||||
$configDir = if ($env:APPDATA) { Join-Path $env:APPDATA 'ChuSQL' } else { Join-Path $InstallDir 'config' }
|
||||
$configFile = Join-Path $configDir 'chusql.toml'
|
||||
$configFile = Join-Path $configDir 'settings.toml'
|
||||
|
||||
if (-not $Yes) {
|
||||
if ([Console]::IsInputRedirected) {
|
||||
@@ -73,7 +73,7 @@ if (-not (Test-Path $InstallDir)) {
|
||||
Say (" removed {0}" -f $InstallDir)
|
||||
}
|
||||
|
||||
Step 'Removing chusql.toml'
|
||||
Step 'Removing settings.toml'
|
||||
if ($KeepConfig) {
|
||||
Say (" kept config: {0}" -f $configFile)
|
||||
} else {
|
||||
|
||||
@@ -19,7 +19,7 @@ Usage: uninstall.sh [options]
|
||||
--install-dir DIR program directory (default: $HOME/.local/share/chusql)
|
||||
--data-dir DIR data directory (default: <install-dir>/data)
|
||||
--keep-data keep the data directory, remove programs only
|
||||
--keep-config keep chusql.toml
|
||||
--keep-config keep settings.toml
|
||||
--yes do not ask (required when there is no terminal)
|
||||
-h, --help show this help
|
||||
EOF
|
||||
@@ -73,9 +73,9 @@ while [ $# -gt 0 ]; do
|
||||
done
|
||||
|
||||
install_dir=${install_dir:-$HOME/.local/share/chusql}
|
||||
data_dir=${data_dir:-$install_dir/data}
|
||||
data_dir=${data_dir:-${XDG_DATA_HOME:-$HOME/.local/share}/chusql/data}
|
||||
config_dir="${XDG_CONFIG_HOME:-$HOME/.config}/ChuSQL"
|
||||
config_file="$config_dir/chusql.toml"
|
||||
config_file="$config_dir/settings.toml"
|
||||
profile="$HOME/.profile"
|
||||
|
||||
if [ "$assume_yes" = 'no' ]; then
|
||||
@@ -119,7 +119,7 @@ else
|
||||
note "removed $install_dir"
|
||||
fi
|
||||
|
||||
step 'Removing chusql.toml'
|
||||
step 'Removing settings.toml'
|
||||
if [ "$keep_config" = 'yes' ]; then
|
||||
note "kept config: $config_file"
|
||||
else
|
||||
|
||||
@@ -0,0 +1,55 @@
|
||||
param([string]$Root = (Split-Path -Parent $PSScriptRoot))
|
||||
|
||||
$ErrorActionPreference = 'Stop'
|
||||
|
||||
# 统计物理行数并生成 README 统一风格的本地 SVG 徽章。
|
||||
|
||||
# 生成带文字和色块的本地徽章。
|
||||
function Write-Badge([string]$Directory, [string]$Name, [string]$Label, [string]$Value, [string]$Color, [string]$Description) {
|
||||
$leftWidth = [int]($Label.Length * 7 + 24)
|
||||
$rightWidth = [int]($Value.Length * 7 + 24)
|
||||
$width = $leftWidth + $rightWidth
|
||||
$leftCenter = $leftWidth / 2
|
||||
$rightCenter = $leftWidth + $rightWidth / 2
|
||||
$safeLabel = [Security.SecurityElement]::Escape($Label)
|
||||
$safeValue = [Security.SecurityElement]::Escape($Value)
|
||||
$safeDescription = [Security.SecurityElement]::Escape($Description)
|
||||
$svg = @"
|
||||
<svg xmlns="http://www.w3.org/2000/svg" width="$width" height="24" viewBox="0 0 $width 24" role="img" aria-label="$safeLabel`: $safeValue">
|
||||
<title>$safeDescription</title>
|
||||
<defs><clipPath id="rounded"><rect width="$width" height="24" rx="5"/></clipPath></defs>
|
||||
<g clip-path="url(#rounded)"><rect width="$width" height="24" fill="#1e293b"/><rect x="$leftWidth" width="$rightWidth" height="24" fill="$Color"/></g>
|
||||
<g fill="#fff" text-anchor="middle" font-family="Verdana,DejaVu Sans,sans-serif" font-size="11"><text x="$leftCenter" y="16">$safeLabel</text><text x="$rightCenter" y="16">$safeValue</text></g>
|
||||
</svg>
|
||||
"@
|
||||
Set-Content -LiteralPath (Join-Path $Directory "$Name.svg") -Value $svg -Encoding utf8
|
||||
}
|
||||
|
||||
Push-Location -LiteralPath $Root
|
||||
try {
|
||||
$paths = @(& git ls-files --cached --others --exclude-standard)
|
||||
if ($LASTEXITCODE -ne 0) { throw 'git ls-files failed' }
|
||||
$lines = 0
|
||||
$files = 0
|
||||
foreach ($path in ($paths | Sort-Object -Unique)) {
|
||||
if ($path -notmatch '\.(hs|rs|js|css|html|ps1|sh)$') { continue }
|
||||
if (-not (Test-Path -LiteralPath $path -PathType Leaf)) { continue }
|
||||
$lines += @(Get-Content -LiteralPath $path).Count
|
||||
$files++
|
||||
}
|
||||
$label = $lines.ToString('N0', [Globalization.CultureInfo]::InvariantCulture)
|
||||
$badgeDir = Join-Path $Root 'docs/badges'
|
||||
[IO.Directory]::CreateDirectory($badgeDir) | Out-Null
|
||||
$revision = & git rev-parse --short HEAD
|
||||
if ($LASTEXITCODE -ne 0) { throw 'git rev-parse failed' }
|
||||
Write-Badge $badgeDir 'lines' 'source lines' $label '#0369a1' 'Physical source lines; includes tests, comments and blank lines.'
|
||||
Write-Badge $badgeDir 'release' 'release' 'browse' '#6d28d9' 'Open GitHub releases to view published versions.'
|
||||
Write-Badge $badgeDir 'commit' 'commit' $revision '#475569' 'Local HEAD snapshot when the badges were generated; open commit history for latest updates.'
|
||||
Write-Badge $badgeDir 'languages' 'languages' 'Haskell + Rust' '#6d28d9' 'ChuSQL implementation languages: Haskell and Rust.'
|
||||
Write-Badge $badgeDir 'build' 'build' 'view status' '#0369a1' 'Open the build workflow for live status; this local badge is a navigation link.'
|
||||
Write-Badge $badgeDir 'tests' 'tests' 'view status' '#0369a1' 'Open the test workflow for live status; this local badge is a navigation link.'
|
||||
Write-Badge $badgeDir 'gate' 'gate' 'manual status' '#b45309' 'Open the owner-triggered gate workflow for status; this local badge is a navigation link.'
|
||||
Write-Output "source_lines=$lines source_files=$files"
|
||||
} finally {
|
||||
Pop-Location
|
||||
}
|
||||
Reference in new issue
Block a user