91 lines
2.3 KiB
Bash
91 lines
2.3 KiB
Bash
#!/usr/bin/env sh
|
|
set -euo pipefail
|
|
|
|
# This script prepares and pushes local module sources to their Gitea remotes.
|
|
# It is idempotent and safe to re-run.
|
|
|
|
ROOT="/home/debian/4NK_env"
|
|
MOD_ROOT="$ROOT/4NK_modules"
|
|
|
|
GIT="/usr/bin/git"
|
|
|
|
log() { printf "%s\n" "$*"; }
|
|
|
|
ensure_dir() {
|
|
[ -d "$1" ] || mkdir -p "$1"
|
|
}
|
|
|
|
copy_if_exists() {
|
|
src="$1"; dst="$2"
|
|
if [ -d "$src" ]; then
|
|
log "[copy] $src -> $dst"
|
|
ensure_dir "$dst"
|
|
# Copy all contents (including dotfiles) without nuking existing .git
|
|
(cd "$src" && tar cf - .) | (cd "$dst" && tar xpf -)
|
|
else
|
|
log "[skip] source not found: $src"
|
|
fi
|
|
}
|
|
|
|
git_init_and_push() {
|
|
module_dir="$1" # e.g. /home/debian/4NK_env/4NK_modules/4NK_miner
|
|
remote_url="$2" # e.g. git@git.4nkweb.com:4nk/4NK_miner.git
|
|
commit_msg="$3" # commit message
|
|
|
|
ensure_dir "$module_dir"
|
|
cd "$module_dir"
|
|
|
|
if [ ! -d .git ]; then
|
|
$GIT init
|
|
fi
|
|
|
|
# Configure default branch ext
|
|
$GIT checkout -B ext
|
|
|
|
# Set remote
|
|
$GIT remote remove origin 2>/dev/null || true
|
|
$GIT remote add origin "$remote_url"
|
|
|
|
# Stage changes
|
|
$GIT add -A
|
|
|
|
# Commit if there are changes
|
|
if ! $GIT diff --cached --quiet; then
|
|
$GIT commit -m "$commit_msg"
|
|
else
|
|
log "[info] no changes to commit in $(basename "$module_dir")"
|
|
fi
|
|
|
|
# Push ext
|
|
$GIT push -u origin ext
|
|
}
|
|
|
|
main() {
|
|
# 1) Prepare module roots
|
|
ensure_dir "$MOD_ROOT/4NK_miner"
|
|
ensure_dir "$MOD_ROOT/4NK_web_status"
|
|
|
|
# 2) Copy sources from projects if present
|
|
copy_if_exists "$ROOT/projects/lecoffre/lecoffre_node/miner" "$MOD_ROOT/4NK_miner"
|
|
copy_if_exists "$ROOT/projects/lecoffre/lecoffre_node/web" "$MOD_ROOT/4NK_web_status"
|
|
|
|
# 3) Push 4NK_miner
|
|
git_init_and_push \
|
|
"$MOD_ROOT/4NK_miner" \
|
|
"git@git.4nkweb.com:4nk/4NK_miner.git" \
|
|
"chore: initial import from lecoffre_node/miner"
|
|
|
|
# 4) Push 4NK_web_status
|
|
git_init_and_push \
|
|
"$MOD_ROOT/4NK_web_status" \
|
|
"git@git.4nkweb.com:4nk/4NK_web_status.git" \
|
|
"chore: initial import from lecoffre_node/web"
|
|
|
|
log "[OK] Modules pushed. Optionally register as submodules in the root repo:"
|
|
log " cd $ROOT && git submodule add -f git@git.4nkweb.com:4nk/4NK_miner.git 4NK_modules/4NK_miner"
|
|
log " cd $ROOT && git submodule add -f git@git.4nkweb.com:4nk/4NK_web_status.git 4NK_modules/4NK_web_status"
|
|
}
|
|
|
|
main "$@"
|
|
|