mirror of
https://github.com/johndoe6345789/SparkOS.git
synced 2026-04-25 05:55:01 +00:00
149 lines
3.7 KiB
Bash
Executable File
149 lines
3.7 KiB
Bash
Executable File
#!/bin/bash
|
|
# SparkOS Setup Script
|
|
# Sets up a minimal rootfs with bash and essential utilities
|
|
|
|
set -e
|
|
|
|
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
|
PROJECT_ROOT="$(cd "$SCRIPT_DIR/.." && pwd)"
|
|
ROOTFS_DIR="$PROJECT_ROOT/rootfs"
|
|
|
|
echo "SparkOS Root Filesystem Setup"
|
|
echo "=============================="
|
|
echo ""
|
|
|
|
# Create directory structure
|
|
echo "Creating directory structure..."
|
|
mkdir -p "$ROOTFS_DIR"/{bin,sbin,etc,proc,sys,dev,tmp,usr/{bin,sbin,lib,lib64},var,root,home}
|
|
mkdir -p "$ROOTFS_DIR/etc"/{init.d,network}
|
|
mkdir -p "$ROOTFS_DIR/var"/{log,run}
|
|
|
|
# Set permissions
|
|
chmod 1777 "$ROOTFS_DIR/tmp"
|
|
chmod 700 "$ROOTFS_DIR/root"
|
|
|
|
# Create basic config files
|
|
echo "Creating configuration files..."
|
|
|
|
# /etc/hostname
|
|
echo "sparkos" > "$ROOTFS_DIR/etc/hostname"
|
|
|
|
# /etc/hosts
|
|
cat > "$ROOTFS_DIR/etc/hosts" << 'EOF'
|
|
127.0.0.1 localhost
|
|
127.0.1.1 sparkos
|
|
::1 localhost ip6-localhost ip6-loopback
|
|
EOF
|
|
|
|
# /etc/passwd
|
|
cat > "$ROOTFS_DIR/etc/passwd" << 'EOF'
|
|
root:x:0:0:root:/root:/bin/bash
|
|
EOF
|
|
|
|
# /etc/group
|
|
cat > "$ROOTFS_DIR/etc/group" << 'EOF'
|
|
root:x:0:
|
|
EOF
|
|
|
|
# /etc/fstab
|
|
cat > "$ROOTFS_DIR/etc/fstab" << 'EOF'
|
|
# <file system> <mount point> <type> <options> <dump> <pass>
|
|
proc /proc proc defaults 0 0
|
|
sysfs /sys sysfs defaults 0 0
|
|
devtmpfs /dev devtmpfs defaults 0 0
|
|
tmpfs /tmp tmpfs defaults 0 0
|
|
EOF
|
|
|
|
# /etc/profile
|
|
cat > "$ROOTFS_DIR/etc/profile" << 'EOF'
|
|
# SparkOS System Profile
|
|
|
|
export PATH=/bin:/sbin:/usr/bin:/usr/sbin
|
|
export PS1='SparkOS:\w\$ '
|
|
export HOME=/root
|
|
export TERM=linux
|
|
|
|
# Welcome message
|
|
echo "Welcome to SparkOS!"
|
|
echo "Type 'help' for available commands"
|
|
echo ""
|
|
EOF
|
|
|
|
# Create .bashrc for root
|
|
cat > "$ROOTFS_DIR/root/.bashrc" << 'EOF'
|
|
# SparkOS Root Bash Configuration
|
|
|
|
# Set prompt
|
|
PS1='SparkOS:\w# '
|
|
|
|
# Aliases
|
|
alias ls='ls --color=auto'
|
|
alias ll='ls -lah'
|
|
alias ..='cd ..'
|
|
|
|
# Environment
|
|
export EDITOR=vi
|
|
export PAGER=less
|
|
EOF
|
|
|
|
# Create a simple help script
|
|
cat > "$ROOTFS_DIR/bin/sparkos-help" << 'EOF'
|
|
#!/bin/sh
|
|
cat << 'HELP'
|
|
SparkOS - Minimal Linux Distribution
|
|
====================================
|
|
|
|
Available commands:
|
|
ls, cd, pwd - Navigate filesystem
|
|
cat, less - View files
|
|
mkdir, rm, cp - File operations
|
|
mount, umount - Mount filesystems
|
|
poweroff, reboot - System control
|
|
help - Show this help
|
|
|
|
This is a minimal system. To extend functionality:
|
|
1. Mount additional filesystems
|
|
2. Install packages (if package manager available)
|
|
3. Build from source
|
|
|
|
For more information: https://github.com/johndoe6345789/SparkOS
|
|
HELP
|
|
EOF
|
|
|
|
chmod +x "$ROOTFS_DIR/bin/sparkos-help"
|
|
ln -sf sparkos-help "$ROOTFS_DIR/bin/help"
|
|
|
|
# Create README
|
|
cat > "$ROOTFS_DIR/README.txt" << 'EOF'
|
|
SparkOS Root Filesystem
|
|
=======================
|
|
|
|
This is the root filesystem for SparkOS, a minimal Linux distribution.
|
|
|
|
Directory Structure:
|
|
/bin, /sbin - Essential binaries
|
|
/etc - Configuration files
|
|
/proc, /sys, /dev - Kernel interfaces
|
|
/tmp - Temporary files
|
|
/usr - User programs
|
|
/var - Variable data
|
|
/root - Root home directory
|
|
/home - User home directories
|
|
|
|
Note: This is a minimal system. You'll need to populate /bin and /usr/bin
|
|
with actual binaries (bash, coreutils, etc.) from a proper Linux system
|
|
or by cross-compiling.
|
|
EOF
|
|
|
|
echo ""
|
|
echo "Root filesystem structure created at: $ROOTFS_DIR"
|
|
echo ""
|
|
echo "Next steps:"
|
|
echo " 1. Build init: make init"
|
|
echo " 2. Install init: make install"
|
|
echo " 3. Copy bash and essential binaries to rootfs/bin/"
|
|
echo " 4. Create bootable image: sudo make image"
|
|
echo ""
|
|
echo "Note: You'll need to populate the rootfs with actual binaries"
|
|
echo " before creating a bootable image."
|