Initial ForgeOS project

This commit is contained in:
joe committed 2026-06-16 14:07:52 -04:00
commit 7db7cf1540
42 files changed
+3308

No files matched your search

+9
View File
@@ -0,0 +1,9 @@
root:x:0:
tty:x:5:
disk:x:6:
utmp:x:43:
messagebus:x:81:
systemd-journal:x:190:
systemd-network:x:192:
systemd-resolve:x:193:
nobody:x:65534:
+1
View File
@@ -0,0 +1 @@
forgeos
+1
View File
@@ -0,0 +1 @@
ForgeOS \r (\m)
+3
View File
@@ -0,0 +1,3 @@
# ForgeOS ships a small BusyBox-compatible neofetch implementation.
# Keep this distro name available for tools that read neofetch-style config.
ascii_distro="forgeos"
+3
View File
@@ -0,0 +1,3 @@
NAME=ForgeOS
ID=forgeos
PRETTY_NAME="ForgeOS"
+5
View File
@@ -0,0 +1,5 @@
root::0:0:root:/root:/bin/sh
systemd-network:x:192:192:systemd Network Management:/:/bin/sh
systemd-resolve:x:193:193:systemd Resolver:/:/bin/sh
messagebus:x:81:81:System Message Bus:/:/bin/sh
nobody:x:65534:65534:nobody:/:/bin/sh
+9
View File
@@ -0,0 +1,9 @@
PATH=/bin:/sbin:/usr/bin:/usr/sbin
export PATH
PS1='[forgeos \w]# '
export PS1
alias ll='ls -alF'
alias la='ls -A'
alias l='ls -CF'
@@ -0,0 +1,6 @@
[Match]
Name=en* eth*
[Network]
DHCP=yes
IPv6AcceptRA=yes
@@ -0,0 +1,15 @@
disable *
enable forgeos-shell@tty1.service
enable forgeos-shell@ttyS0.service
enable forgeos-bootdiag.service
enable forgeos-console-banner.service
enable dbus.service
enable dbus.socket
enable systemd-networkd.service
enable systemd-networkd.socket
enable systemd-resolved.service
enable systemd-resolved-monitor.socket
enable systemd-resolved-varlink.socket
enable systemd-udevd.service
enable systemd-udevd-control.socket
enable systemd-udevd-kernel.socket
@@ -0,0 +1,12 @@
[Unit]
Description=Record ForgeOS boot diagnostics
Documentation=man:systemd.service(5)
After=local-fs.target systemd-udevd.service
ConditionPathExists=/sbin/forgeos-bootdiag
[Service]
Type=oneshot
ExecStart=/sbin/forgeos-bootdiag systemd
[Install]
WantedBy=multi-user.target
@@ -0,0 +1,12 @@
[Unit]
Description=Print ForgeOS console banner
Documentation=man:systemd.service(5)
After=systemd-user-sessions.service
ConditionPathExists=/sbin/forgeos-console-banner
[Service]
Type=oneshot
ExecStart=/sbin/forgeos-console-banner
[Install]
WantedBy=multi-user.target
@@ -0,0 +1,24 @@
[Unit]
Description=ForgeOS root shell on %I
Documentation=man:systemd.service(5)
After=systemd-user-sessions.service
Before=getty.target
IgnoreOnIsolate=yes
[Service]
Type=simple
ExecStart=-/bin/sh -l
Restart=always
RestartSec=0
StandardInput=tty
StandardOutput=tty
StandardError=tty
TTYPath=/dev/%I
TTYReset=yes
TTYVHangup=yes
KillMode=process
IgnoreSIGPIPE=no
SendSIGHUP=yes
[Install]
WantedBy=getty.target
+16
View File
@@ -0,0 +1,16 @@
#!/bin/sh
PATH=/bin:/sbin:/usr/bin:/usr/sbin
export PATH
mkdir -p /proc /sys /dev /run
mount -t proc proc /proc 2>/dev/null || true
mount -t sysfs sysfs /sys 2>/dev/null || true
mount -t devtmpfs devtmpfs /dev 2>/dev/null || true
mount -t tmpfs tmpfs /run 2>/dev/null || true
if grep -qw 'forgeos.switch_root=1' /proc/cmdline 2>/dev/null; then
exec /sbin/forgeos-switch-root
fi
exec /sbin/init
+2
View File
@@ -0,0 +1,2 @@
cd /root
exec /bin/sh
+176
View File
@@ -0,0 +1,176 @@
#!/bin/sh
PATH=/bin:/sbin:/usr/bin:/usr/sbin
export PATH
STAGE=${1:-userspace}
ESP_MOUNT=/mnt/esp
MARKER_DIR=$ESP_MOUNT/EFI/BOOT/diag
MARKER_FILE=$MARKER_DIR/boot.log
MOUNTED_ESP=0
try_beep() {
command -v beep >/dev/null 2>&1 || return 0
beep -f 880 -l 120 -d 80 -r 2 >/dev/null 2>&1 || true
}
try_led_blink() {
local led
local i
local found=0
for led in /sys/class/leds/*capslock* /sys/class/leds/*numlock*; do
[ -w "$led/brightness" ] || continue
found=1
for i in 1 2 3; do
echo 1 > "$led/brightness" 2>/dev/null || true
sleep 0.15
echo 0 > "$led/brightness" 2>/dev/null || true
sleep 0.15
done
done
[ "$found" -eq 1 ] || return 0
}
try_backlight_on() {
local backlight
local max
for backlight in /sys/class/backlight/*; do
[ -w "$backlight/brightness" ] || continue
max=$(cat "$backlight/max_brightness" 2>/dev/null || true)
case "$max" in
''|*[!0-9]*|0)
continue
;;
esac
echo "$max" > "$backlight/brightness" 2>/dev/null || true
done
}
mount_esp() {
local dev
mkdir -p "$ESP_MOUNT"
MOUNTED_ESP=0
if grep -q " $ESP_MOUNT " /proc/mounts 2>/dev/null; then
return 0
fi
for dev in \
/dev/disk/by-label/FORGE_EFI \
/dev/sd[a-z][0-9] \
/dev/vd[a-z][0-9] \
/dev/nvme[0-9]n[0-9]p[0-9] \
/dev/mmcblk[0-9]p[0-9]; do
[ -b "$dev" ] || continue
mount -t vfat -o rw "$dev" "$ESP_MOUNT" 2>/dev/null || continue
if [ -f "$ESP_MOUNT/EFI/BOOT/FORGEOS.EFI" ]; then
MOUNTED_ESP=1
return 0
fi
umount "$ESP_MOUNT" 2>/dev/null || true
done
return 1
}
print_file() {
local title=$1
local path=$2
echo "--- $title ---"
if [ -r "$path" ]; then
cat "$path" 2>/dev/null || true
else
echo "unavailable: $path"
fi
echo
}
print_cmd() {
local title=$1
shift
echo "--- $title ---"
"$@" 2>/dev/null || true
echo
}
print_framebuffers() {
local fb
local attr
local found=0
echo "--- framebuffer devices ---"
ls -l /dev/fb* 2>/dev/null || true
for fb in /sys/class/graphics/fb*; do
[ -e "$fb" ] || continue
found=1
echo "${fb##*/}:"
for attr in name mode modes virtual_size bits_per_pixel blank state; do
[ -r "$fb/$attr" ] || continue
printf ' %s=' "$attr"
cat "$fb/$attr" 2>/dev/null || true
done
done
[ "$found" -eq 1 ] || echo "no /sys/class/graphics/fb* entries"
echo
}
print_drm_connectors() {
local status
local found=0
echo "--- drm connectors ---"
for status in /sys/class/drm/card*-*/status; do
[ -r "$status" ] || continue
found=1
printf '%s=' "${status%/status}"
cat "$status" 2>/dev/null || true
done
[ "$found" -eq 1 ] || echo "no connector status entries"
echo
}
write_marker() {
mount_esp || return 0
mkdir -p "$MARKER_DIR"
{
echo "=== ForgeOS boot diagnostic ==="
echo "stage=$STAGE"
echo "date=$(date 2>/dev/null || true)"
echo "uname=$(uname -a 2>/dev/null || true)"
echo "cmdline=$(cat /proc/cmdline 2>/dev/null || true)"
echo
print_file "proc consoles" /proc/consoles
print_file "active console" /sys/class/tty/console/active
print_cmd "foreground vt" fgconsole
print_cmd "tty devices" ls -l /dev/console /dev/tty /dev/tty0 /dev/tty1 /dev/ttyS0
print_cmd "block devices" ls -l /dev/sd* /dev/vd* /dev/nvme* /dev/mmcblk*
print_cmd "disk labels" ls -l /dev/disk/by-label /dev/disk/by-partlabel
print_cmd "blkid" blkid
print_cmd "mounts" cat /proc/mounts
print_cmd "drm devices" ls -l /sys/class/drm
print_drm_connectors
print_framebuffers
echo "--- dmesg tail ---"
dmesg 2>/dev/null | tail -n 180 || true
echo
} >> "$MARKER_FILE"
sync
if [ "$MOUNTED_ESP" -eq 1 ]; then
umount "$ESP_MOUNT" 2>/dev/null || true
fi
}
try_beep
try_led_blink
try_backlight_on
write_marker
exit 0
+14
View File
@@ -0,0 +1,14 @@
#!/bin/sh
PATH=/bin:/sbin:/usr/bin:/usr/sbin
export PATH
for tty in /dev/tty0 /dev/tty1 /dev/ttyS0 /dev/console; do
[ -w "$tty" ] || continue
{
echo
echo "ForgeOS boot complete: $(uname -r) on $(uname -m)"
echo "Root shell is available on tty1 and ttyS0."
echo
} > "$tty" 2>/dev/null || true
done
+133
View File
@@ -0,0 +1,133 @@
#!/bin/sh
PATH=/bin:/sbin:/usr/bin:/usr/sbin
export PATH
NEWROOT=/newroot
ROOT_TIMEOUT=${FORGEOS_ROOT_TIMEOUT:-20}
root_fs_type() {
awk '$2 == "/" { print $3; exit }' /proc/mounts 2>/dev/null
}
in_initramfs() {
case "$(root_fs_type)" in
rootfs|tmpfs)
return 0
;;
*)
return 1
;;
esac
}
console_note() {
local tty
for tty in /dev/tty0 /dev/tty1 /dev/console; do
[ -w "$tty" ] || continue
printf '%s\n' "$*" > "$tty" 2>/dev/null || true
done
}
find_root_device() {
local dev
local info
for dev in /dev/disk/by-partlabel/root /dev/disk/by-label/FORGE_ROOT; do
[ -b "$dev" ] || continue
printf '%s\n' "$dev"
return 0
done
for dev in \
/dev/nvme[0-9]n[0-9]p[0-9] \
/dev/sd[a-z][0-9] \
/dev/mmcblk[0-9]p[0-9] \
/dev/vd[a-z][0-9]; do
[ -b "$dev" ] || continue
info=$(blkid "$dev" 2>/dev/null || true)
case "$info" in
*' PARTLABEL="root"'*|*' LABEL="FORGE_ROOT"'*)
printf '%s\n' "$dev"
return 0
;;
esac
done
return 1
}
wait_for_root_device() {
local attempt
local rootdev
for attempt in $(seq 1 "$ROOT_TIMEOUT"); do
mdev -s 2>/dev/null || true
rootdev=$(find_root_device) || true
if [ -n "$rootdev" ]; then
printf '%s\n' "$rootdev"
return 0
fi
sleep 1
done
return 1
}
is_mounted_newroot() {
grep -q " $NEWROOT " /proc/mounts 2>/dev/null
}
drop_to_rescue() {
local reason=$1
console_note "ForgeOS switch_root failed: $reason"
/sbin/forgeos-bootdiag switch-root-failed || true
if [ "$$" -eq 1 ]; then
exec /sbin/init
fi
return 1
}
if ! grep -qw 'forgeos.switch_root=1' /proc/cmdline 2>/dev/null; then
[ "$$" -eq 1 ] && exec /sbin/init
exit 0
fi
if [ "$$" -ne 1 ]; then
console_note "ForgeOS switch_root skipped: helper is not PID 1"
exit 1
fi
in_initramfs || exec /sbin/init
/sbin/forgeos-bootdiag switch-root-start || true
console_note "ForgeOS initramfs: locating real root filesystem..."
ROOTDEV=$(wait_for_root_device) || drop_to_rescue "root partition not found" || exit 1
mkdir -p "$NEWROOT"
mount -t ext4 -o rw "$ROOTDEV" "$NEWROOT" 2>/dev/null || \
mount -t ext4 -o ro "$ROOTDEV" "$NEWROOT" 2>/dev/null || \
drop_to_rescue "could not mount $ROOTDEV" || exit 1
if ! is_mounted_newroot; then
drop_to_rescue "$NEWROOT was not mounted" || exit 1
fi
if [ ! -x "$NEWROOT/sbin/init" ]; then
umount "$NEWROOT" 2>/dev/null || true
drop_to_rescue "$ROOTDEV does not contain /sbin/init" || exit 1
fi
/sbin/forgeos-bootdiag switch-root-exec || true
console_note "ForgeOS initramfs: switching to $ROOTDEV"
for dir in dev proc sys run; do
mkdir -p "$NEWROOT/$dir"
mount --move "/$dir" "$NEWROOT/$dir" 2>/dev/null || true
done
exec switch_root -c /dev/console "$NEWROOT" /sbin/init
drop_to_rescue "switch_root exec returned"
exit 1
+124
View File
@@ -0,0 +1,124 @@
#!/bin/sh
set -u
show_help() {
cat <<'EOF'
Usage: neofetch [--help] [--version]
Print ForgeOS system information with the ForgeOS ASCII logo.
EOF
}
case "${1:-}" in
--help|-h)
show_help
exit 0
;;
--version|-V)
echo "ForgeOS neofetch 1.0"
exit 0
;;
--*)
echo "neofetch: unsupported option: $1" >&2
exit 1
;;
esac
if [ -t 1 ] && [ -z "${NO_COLOR:-}" ]; then
reset="$(printf '\033[0m')"
bold="$(printf '\033[1m')"
logo_color="$(printf '\033[36m')"
key_color="$(printf '\033[1;37m')"
else
reset=''
bold=''
logo_color=''
key_color=''
fi
os_release="${NEOFETCH_OS_RELEASE:-/etc/os-release}"
host_file="${NEOFETCH_HOSTNAME:-/etc/hostname}"
desktop_file="${NEOFETCH_DESKTOP_FILE:-/etc/forgeos-desktop}"
os_name="ForgeOS"
if [ -r "$os_release" ]; then
os_name="$(sed -n 's/^PRETTY_NAME=//p' "$os_release" | head -n 1 | sed 's/^"//;s/"$//')"
[ -n "$os_name" ] || os_name="$(sed -n 's/^NAME=//p' "$os_release" | head -n 1 | sed 's/^"//;s/"$//')"
[ -n "$os_name" ] || os_name="ForgeOS"
fi
host="$(cat "$host_file" 2>/dev/null || hostname 2>/dev/null || echo forgeos)"
kernel="$(uname -sr 2>/dev/null || echo unknown)"
arch="$(uname -m 2>/dev/null || echo unknown)"
shell_name="${SHELL:-/bin/sh}"
terminal="${TERM:-linux}"
init_name="systemd"
desktop="console"
if [ -r "$desktop_file" ]; then
desktop="$(sed -n 's/^NAME=//p' "$desktop_file" | head -n 1 | sed 's/^"//;s/"$//')"
[ -n "$desktop" ] || desktop="Openbox"
fi
uptime_text="unknown"
if [ -r /proc/uptime ]; then
uptime_seconds="$(cut -d. -f1 /proc/uptime 2>/dev/null | awk '{print $1}')"
case "$uptime_seconds" in
''|*[!0-9]*)
;;
*)
days=$((uptime_seconds / 86400))
hours=$(((uptime_seconds % 86400) / 3600))
mins=$(((uptime_seconds % 3600) / 60))
if [ "$days" -gt 0 ]; then
uptime_text="${days}d ${hours}h ${mins}m"
elif [ "$hours" -gt 0 ]; then
uptime_text="${hours}h ${mins}m"
else
uptime_text="${mins}m"
fi
;;
esac
fi
cpu="$arch"
if [ -r /proc/cpuinfo ]; then
cpu="$(sed -n 's/^model name[[:space:]]*:[[:space:]]*//p' /proc/cpuinfo | head -n 1)"
[ -n "$cpu" ] || cpu="$arch"
fi
memory="unknown"
if [ -r /proc/meminfo ]; then
mem_total="$(awk '/^MemTotal:/ {print int($2 / 1024)}' /proc/meminfo)"
mem_available="$(awk '/^MemAvailable:/ {print int($2 / 1024)}' /proc/meminfo)"
if [ -n "$mem_total" ] && [ -n "$mem_available" ]; then
mem_used=$((mem_total - mem_available))
memory="${mem_used}MiB / ${mem_total}MiB"
fi
fi
line() {
logo_line="$1"
label="$2"
value="$3"
if [ -n "$label" ]; then
printf '%b%-37s%b %b%s%b %s\n' "$logo_color" "$logo_line" "$reset" "$key_color" "$label" "$reset" "$value"
else
printf '%b%s%b\n' "$logo_color" "$logo_line" "$reset"
fi
}
printf '%b%s@%s%b\n' "$bold" "${USER:-root}" "$host" "$reset"
line ' ______ ____ _____' 'OS:' "$os_name"
line ' / ____/___ _________ ____ / __ \/ ___/' 'Host:' "$host"
line ' / /_ / __ \/ ___/ __ `/ _ \/ / / /\__ \' 'Kernel:' "$kernel"
line ' / __/ / /_/ / / / /_/ / __/ /_/ /__/ /' 'Uptime:' "$uptime_text"
line '/_/ \____/_/ \__, /\___/\____/____/' 'Shell:' "$shell_name"
line ' /____/' 'Terminal:' "$terminal"
line ' forged from source' 'Desktop:' "$desktop"
line '' 'Init:' "$init_name"
line '' 'CPU:' "$cpu"
line '' 'Memory:' "$memory"
line '' 'Packages:' 'overlay + source-built core'
@@ -0,0 +1,7 @@
______ ____ _____
/ ____/___ _________ ____ / __ \/ ___/
/ /_ / __ \/ ___/ __ `/ _ \/ / / /\__ \
/ __/ / /_/ / / / /_/ / __/ /_/ /__/ /
/_/ \____/_/ \__, /\___/\____/____/
/____/
forged from source
+24
View File
@@ -0,0 +1,24 @@
#!/bin/sh
[ -n "$interface" ] || exit 1
case "$1" in
deconfig)
ip addr flush dev "$interface" 2>/dev/null || true
ip route flush dev "$interface" 2>/dev/null || true
;;
renew|bound)
ifconfig "$interface" 0.0.0.0 2>/dev/null || true
ifconfig "$interface" "$ip" netmask "${subnet:-255.255.255.0}" up
route del default dev "$interface" 2>/dev/null || true
[ -n "${router:-}" ] && route add default gw "$router" dev "$interface" 2>/dev/null || true
[ -n "$dns" ] && {
: > /etc/resolv.conf
for server in $dns; do
echo "nameserver $server" >> /etc/resolv.conf
done
}
;;
esac
exit 0