Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
steve02081504 committed Jan 3, 2025
1 parent 1cfad4a commit e045034
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 12 deletions.
2 changes: 1 addition & 1 deletion dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ EXPOSE 8931
RUN chmod +x /app/*.sh

# 安装依赖并忽略错误
RUN deno install --allow-scripts --allow-all --node-modules-dir=auto --entrypoint "/app/src/server/index.mjs" || true
RUN /app/run.sh init

# 使用 run.sh 作为启动脚本,并且传递参数
ENTRYPOINT ["/app/run.sh"]
Expand Down
42 changes: 35 additions & 7 deletions path/fount.ps1
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
$FOUNT_DIR = Split-Path -Parent $PSScriptRoot
$ErrorCount = $Error.Count

# Docker 检测
$IN_DOCKER = $false

# fount 路径设置
if (!(Get-Command fount -ErrorAction SilentlyContinue)) {
$path = $env:PATH -split ';'
if ($path -notcontains "$FOUNT_DIR\path") {
Expand All @@ -10,15 +14,21 @@ if (!(Get-Command fount -ErrorAction SilentlyContinue)) {
[System.Environment]::SetEnvironmentVariable('PATH', $path, [System.EnvironmentVariableTarget]::User)
}

# Git 安装和更新
if (!(Get-Command git -ErrorAction SilentlyContinue)) {
Write-Host "Git is not installed, attempting to install..."
if (!(Get-Command winget -ErrorAction SilentlyContinue)) {
Import-Module Appx
Add-AppxPackage -RegisterByFamilyName -MainPackage Microsoft.DesktopAppInstaller_8wekyb3d8bbwe
}
if (Get-Command winget -ErrorAction SilentlyContinue) {
winget install --id Git.Git -e --source winget
}
if (!(Get-Command git -ErrorAction SilentlyContinue)) {
Write-Host "Failed to install Git, please install it manually."
}
}

if (Get-Command git -ErrorAction SilentlyContinue) {
if (!(Test-Path -Path "$FOUNT_DIR/.git")) {
Remove-Item -Path "$FOUNT_DIR/.git-clone" -Recurse -Force -ErrorAction SilentlyContinue
Expand All @@ -30,31 +40,49 @@ if (Get-Command git -ErrorAction SilentlyContinue) {
git -C "$FOUNT_DIR" reset --hard origin/master
git -C "$FOUNT_DIR" checkout origin/master
}
git -C "$FOUNT_DIR" pull -f

if ($IN_DOCKER) {
Write-Host "Skipping git pull in Docker environment"
}
else {
git -C "$FOUNT_DIR" pull -f
}
}
else {
Write-Host "Git is not installed, skipping git pull"
}

# Deno 安装
if (!(Get-Command deno -ErrorAction SilentlyContinue)) {
Write-Host "Deno missing, auto installing..."
Invoke-RestMethod https://deno.land/install.ps1 | Invoke-Expression
if (!(Get-Command deno -ErrorAction SilentlyContinue)) {
Write-Host "Deno missing, you cant run fount without deno"
exit 1
}
else {
Write-Host "Deno installed"
}
}

deno upgrade -q
# Deno 更新
if ($IN_DOCKER) {
Write-Host "Skipping deno upgrade in Docker environment"
}
else {
deno upgrade -q
}

deno -V
if (!(Test-Path -Path "$FOUNT_DIR/node_modules")) {

# 安装依赖
if (!(Test-Path -Path "$FOUNT_DIR/node_modules") -or ($args.Count -gt 0 -and $args[0] -eq 'init')) {
Write-Host "Installing dependencies..."
deno install --allow-scripts --allow-all --node-modules-dir=auto --entrypoint "$FOUNT_DIR/src/server/index.mjs"
}
if ($args.Count -gt 0 -and $args[0] -eq 'debug') {

# 执行 fount
if ($args.Count -gt 0 -and $args[0] -eq 'init') {
exit 0
}
elseif ($args.Count -gt 0 -and $args[0] -eq 'debug') {
$newargs = $args[1..$args.Count]
deno run --allow-scripts --allow-all --inspect-brk "$FOUNT_DIR/src/server/index.mjs" @newargs
}
Expand Down
20 changes: 16 additions & 4 deletions path/fount.sh
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ install_package() {
else
zypper install -y "$1"
fi
elif command -v apk &> /dev/null; then
apk add --update "$1"
else
echo "无法安装 $1"
exit 1
Expand All @@ -39,6 +41,10 @@ install_package() {

SCRIPT_DIR=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )
FOUNT_DIR=$(dirname "$SCRIPT_DIR")
IN_DOCKER=0
if [ -f "/.dockerenv" ] || grep -q 'docker\|containerd' /proc/1/cgroup 2>/dev/null; then
IN_DOCKER=1
fi

if ! command -v fount &> /dev/null; then
if ! grep -q "export PATH=\"\$PATH:$FOUNT_DIR/path\"" "$HOME/.bashrc"; then
Expand All @@ -61,7 +67,7 @@ if command -v git &> /dev/null; then
git -C "$FOUNT_DIR" reset --hard origin/master
git -C "$FOUNT_DIR" checkout origin/master
fi
if [ -f "/.dockerenv" ] || grep -q 'docker\|containerd' /proc/1/cgroup 2>/dev/null; then
if [ $IN_DOCKER -eq 1 ]; then
echo "Skipping git pull in Docker environment"
else
git -C "$FOUNT_DIR" pull -f
Expand Down Expand Up @@ -125,14 +131,20 @@ EOF
fi
fi

deno upgrade -q
if [ $IN_DOCKER -eq 1 ]; then
echo "Skipping deno upgrade in Docker environment"
else
deno upgrade -q
fi
deno -V
if [ ! -d "$FOUNT_DIR/node_modules" ]; then
if [[ ! -d "$FOUNT_DIR/node_modules" || ($# -gt 0 && $1 = 'init') ]]; then
echo "Installing dependencies..."
deno install --allow-scripts --allow-all --node-modules-dir=auto --entrypoint "$FOUNT_DIR/src/server/index.mjs"
fi

if [ $# -gt 0 -a $1 = 'debug' ]; then
if [[ $# -gt 0 && $1 = 'init' ]]; then
exit 0
elif [[ $# -gt 0 && $1 = 'debug' ]]; then
newargs=($@[1:])
deno run --allow-scripts --allow-all --inspect-brk "$FOUNT_DIR/src/server/index.mjs" @newargs
else
Expand Down

0 comments on commit e045034

Please sign in to comment.