Skip to content

Commit 75beb9a

Browse files
committed
fix(ci): unignore Scripts/lib for CI packaging
1 parent 43b2763 commit 75beb9a

File tree

4 files changed

+171
-0
lines changed

4 files changed

+171
-0
lines changed

.gitignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,3 +97,7 @@ Thumbs.db
9797

9898
# dont commit diff files
9999
*.diff
100+
101+
# keep SOLEN libs used by CI
102+
!Scripts/lib/
103+
!Scripts/lib/**

Scripts/lib/edit.sh

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
#!/usr/bin/env bash
2+
# Minimal editing helpers for marker-managed blocks
3+
4+
# Insert or replace a marker block in a file
5+
# usage: solen_insert_marker_block <file> <begin_marker> <end_marker> <content>
6+
solen_insert_marker_block() {
7+
local file="$1" begin="$2" end="$3" content="$4"
8+
mkdir -p "$(dirname "$file")" 2>/dev/null || true
9+
touch "$file"
10+
# Remove existing block
11+
tmpfile="${file}.tmp.$$"
12+
awk -v b="$begin" -v e="$end" '
13+
BEGIN{inblk=0}
14+
{ if(index($0,b)==1){inblk=1; next} }
15+
{ if(index($0,e)==1){inblk=0; next} }
16+
{ if(inblk==0) print $0 }
17+
' "$file" > "$tmpfile"
18+
mv "$tmpfile" "$file"
19+
# Ensure newline at EOF
20+
tail -c1 "$file" 2>/dev/null | read -r _ || echo >> "$file"
21+
{
22+
echo "$begin"
23+
printf "%s\n" "$content"
24+
echo "$end"
25+
} >> "$file"
26+
}
27+
28+
# Remove a marker block from a file (no error if absent)
29+
solen_remove_marker_block() {
30+
local file="$1" begin="$2" end="$3"
31+
[ -f "$file" ] || return 0
32+
tmpfile="${file}.tmp.$$"
33+
awk -v b="$begin" -v e="$end" '
34+
BEGIN{inblk=0}
35+
{ if(index($0,b)==1){inblk=1; next} }
36+
{ if(index($0,e)==1){inblk=0; next} }
37+
{ if(inblk==0) print $0 }
38+
' "$file" > "$tmpfile"
39+
mv "$tmpfile" "$file"
40+
}
41+

Scripts/lib/pm.sh

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
#!/usr/bin/env bash
2+
# Minimal cross-distro package manager helpers
3+
4+
__SOLEN_PM="unknown"
5+
6+
pm_detect() {
7+
if command -v apt-get >/dev/null 2>&1; then __SOLEN_PM=apt
8+
elif command -v dnf >/dev/null 2>&1; then __SOLEN_PM=dnf
9+
elif command -v pacman >/dev/null 2>&1; then __SOLEN_PM=pacman
10+
elif command -v zypper >/dev/null 2>&1; then __SOLEN_PM=zypper
11+
else __SOLEN_PM=unknown; fi
12+
return 0
13+
}
14+
15+
pm_name() { echo "$__SOLEN_PM"; }
16+
17+
# Return a plan string to update package metadata
18+
pm_update_plan() {
19+
case "$__SOLEN_PM" in
20+
apt) echo "sudo apt-get update -y" ;;
21+
dnf) echo "sudo dnf -y makecache" ;;
22+
pacman) echo "sudo pacman -Sy --noconfirm" ;;
23+
zypper) echo "sudo zypper -n refresh" ;;
24+
*) echo "# pm update (unsupported)" ;;
25+
esac
26+
}
27+
28+
# Return a plan string to install packages: pm_install_plan <pkgs...>
29+
pm_install_plan() {
30+
case "$__SOLEN_PM" in
31+
apt) echo "sudo apt-get install -y $*" ;;
32+
dnf) echo "sudo dnf -y install $*" ;;
33+
pacman) echo "sudo pacman -S --noconfirm $*" ;;
34+
zypper) echo "sudo zypper -n install $*" ;;
35+
*) echo "# pm install $* (unsupported)" ;;
36+
esac
37+
}
38+
39+
# Optional: count updates available (best-effort; fall back to 0)
40+
pm_check_updates_count() {
41+
case "$__SOLEN_PM" in
42+
apt)
43+
if command -v apt-get >/dev/null 2>&1; then
44+
(apt-get -s upgrade 2>/dev/null | awk '/^Inst /{c++} END{print c+0}') || echo 0
45+
else echo 0; fi ;;
46+
dnf)
47+
(dnf -q check-update 2>/dev/null | awk 'END{print NR+0}') || echo 0 ;;
48+
pacman)
49+
(checkupdates 2>/dev/null | wc -l | tr -d ' ') || echo 0 ;;
50+
zypper)
51+
(zypper -q list-updates 2>/dev/null | awk 'NR>2{c++} END{print c+0}') || echo 0 ;;
52+
*) echo 0 ;;
53+
esac
54+
}
55+

Scripts/lib/solen.sh

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
#!/usr/bin/env bash
2+
# Minimal SOLEN shared helpers for scripts
3+
4+
# Do NOT set -e/-u here; these files are sourced by scripts that manage shell opts
5+
6+
solen_ts() { date -u +"%Y-%m-%dT%H:%M:%SZ"; }
7+
solen_host() { hostname 2>/dev/null || uname -n; }
8+
9+
# Flags: default to verify-by-default, dry-run unless --yes is given
10+
solen_init_flags() {
11+
: "${SOLEN_FLAG_YES:=0}"
12+
: "${SOLEN_FLAG_JSON:=${SOLEN_JSON:-0}}"
13+
: "${SOLEN_FLAG_DRYRUN:=1}"
14+
if [ "${SOLEN_FLAG_YES}" = "1" ]; then SOLEN_FLAG_DRYRUN=0; fi
15+
}
16+
17+
# Parse a common flag; echo nothing, return 0 if handled
18+
solen_parse_common_flag() {
19+
case "$1" in
20+
--yes|-y) SOLEN_FLAG_YES=1; SOLEN_FLAG_DRYRUN=0; return 0 ;;
21+
--dry-run) SOLEN_FLAG_DRYRUN=1; return 0 ;;
22+
--json) SOLEN_FLAG_JSON=1; return 0 ;;
23+
esac
24+
return 1
25+
}
26+
27+
# Styled messages
28+
solen_info() { echo -e "\033[0;36mℹ️ $*\033[0m"; }
29+
solen_ok() { echo -e "\033[0;32m✅ $*\033[0m"; }
30+
solen_warn() { echo -e "\033[0;33m⚠️ $*\033[0m"; }
31+
solen_err() { echo -e "\033[0;31m❌ $*\033[0m" 1>&2; }
32+
33+
# Section header for human-readable output
34+
solen_head() { echo -e "\033[0;34m--- $* ---\033[0m"; }
35+
36+
# Minimal JSON string escaper
37+
solen_json_escape() { printf '%s' "$1" | sed 's/\\/\\\\/g; s/"/\\"/g'; }
38+
39+
# Emit a single JSON record with optional extra fields
40+
# Usage: solen_json_record <status> <summary> <actions_text> <extra_json_fields>
41+
solen_json_record() {
42+
local status="$1" summary="$2" actions_text="${3:-}" extra="${4:-}"
43+
# Escape JSON
44+
_esc() { printf '%s' "$1" | sed 's/\\/\\\\/g; s/"/\\"/g'; }
45+
local host; host="$(solen_host)"
46+
# Convert actions_text (newline-separated) to JSON array
47+
local actions_json="[]"
48+
if [ -n "$actions_text" ]; then
49+
actions_json="["
50+
local first=1
51+
while IFS= read -r line; do
52+
[ -z "$line" ] && continue
53+
local e; e="$(_esc "$line")"
54+
if [ $first -eq 0 ]; then actions_json+=" ,"; else first=0; fi
55+
actions_json+="\"$e\""
56+
done <<EOF
57+
${actions_text}
58+
EOF
59+
actions_json+="]"
60+
fi
61+
printf '{"status":"%s","summary":"%s","ts":"%s","host":"%s","actions":%s%s}%s' \
62+
"$(_esc "$status")" "$(_esc "$summary")" "$(solen_ts)" "$(_esc "$host")" "$actions_json" \
63+
"${extra:+,${extra}}" "\n"
64+
}
65+
66+
# Convenience: emit a JSON record with a ready-made details fragment
67+
# Usage: solen_json_record_full <status> <summary> <details_json_fragment>
68+
solen_json_record_full() {
69+
local status="$1" summary="$2" details_fragment="$3"
70+
solen_json_record "$status" "$summary" "" "$details_fragment"
71+
}

0 commit comments

Comments
 (0)