Initial commit - Arch R project structure

This commit is contained in:
Douglas Teles
2026-02-04 14:09:18 -03:00
commit 487c4f2cbd
12 changed files with 1294 additions and 0 deletions

101
scripts/first-boot.sh Normal file
View File

@@ -0,0 +1,101 @@
#!/bin/bash
#==============================================================================
# Arch R - First Boot Setup Script
#==============================================================================
# Runs on first boot to configure the system
#==============================================================================
FIRST_BOOT_FLAG="/var/lib/archr/.first-boot-done"
# Check if already ran
if [ -f "$FIRST_BOOT_FLAG" ]; then
exit 0
fi
echo "=== Arch R First Boot Setup ==="
#------------------------------------------------------------------------------
# Resize partition to fill SD card
#------------------------------------------------------------------------------
echo "Resizing root partition..."
ROOT_DEV="/dev/mmcblk0p2"
ROOT_DISK="/dev/mmcblk0"
# Get current end and max available
PART_INFO=$(parted -m "$ROOT_DISK" unit s print 2>/dev/null | grep "^2:")
CURRENT_END=$(echo "$PART_INFO" | cut -d: -f3 | tr -d 's')
DISK_SIZE=$(parted -m "$ROOT_DISK" unit s print 2>/dev/null | grep "^$ROOT_DISK" | cut -d: -f2 | tr -d 's')
MAX_END=$((DISK_SIZE - 34)) # Leave space for GPT backup
if [ "$CURRENT_END" -lt "$MAX_END" ]; then
echo " Expanding partition..."
parted -s "$ROOT_DISK" resizepart 2 100%
resize2fs "$ROOT_DEV"
echo " Partition expanded!"
else
echo " Partition already at maximum size"
fi
#------------------------------------------------------------------------------
# Generate SSH host keys
#------------------------------------------------------------------------------
echo "Generating SSH host keys..."
ssh-keygen -A 2>/dev/null || true
#------------------------------------------------------------------------------
# Set random machine-id
#------------------------------------------------------------------------------
echo "Generating machine ID..."
rm -f /etc/machine-id
systemd-machine-id-setup
#------------------------------------------------------------------------------
# Enable services
#------------------------------------------------------------------------------
echo "Enabling services..."
systemctl enable NetworkManager 2>/dev/null || true
systemctl enable bluetooth 2>/dev/null || true
#------------------------------------------------------------------------------
# Configure RetroArch
#------------------------------------------------------------------------------
echo "Configuring RetroArch..."
RA_CONFIG="/home/archr/.config/retroarch/retroarch.cfg"
mkdir -p "$(dirname "$RA_CONFIG")"
if [ ! -f "$RA_CONFIG" ]; then
cp /etc/archr/retroarch.cfg "$RA_CONFIG" 2>/dev/null || true
fi
chown -R archr:archr /home/archr/.config 2>/dev/null || true
#------------------------------------------------------------------------------
# Create ROM directories
#------------------------------------------------------------------------------
echo "Creating ROM directories..."
ROM_BASE="/home/archr/roms"
SYSTEMS=(
"gb" "gbc" "gba" "nes" "snes" "megadrive" "psx"
"n64" "psp" "dreamcast" "arcade" "mame"
)
for sys in "${SYSTEMS[@]}"; do
mkdir -p "$ROM_BASE/$sys"
done
chown -R archr:archr "$ROM_BASE"
#------------------------------------------------------------------------------
# Mark first boot complete
#------------------------------------------------------------------------------
mkdir -p "$(dirname "$FIRST_BOOT_FLAG")"
touch "$FIRST_BOOT_FLAG"
echo "=== First Boot Setup Complete ==="
echo ""
echo "System will continue booting..."

102
scripts/wifi-connect.sh Normal file
View File

@@ -0,0 +1,102 @@
#!/bin/bash
#==============================================================================
# Arch R - Wi-Fi Connection Script
#==============================================================================
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
# Colors for output
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
NC='\033[0m' # No Color
echo -e "${GREEN}=== Arch R Wi-Fi Setup ===${NC}"
echo ""
#------------------------------------------------------------------------------
# Check for Wi-Fi interface
#------------------------------------------------------------------------------
echo "Checking for Wi-Fi interface..."
IFACE=""
for iface in wlan0 wlan1 wlp1s0; do
if [ -d "/sys/class/net/$iface" ]; then
IFACE="$iface"
break
fi
done
if [ -z "$IFACE" ]; then
echo -e "${RED}No Wi-Fi interface found!${NC}"
echo ""
echo "Troubleshooting:"
echo " 1. Make sure Wi-Fi adapter is connected"
echo " 2. Check if driver is loaded: lsmod | grep aic"
echo " 3. Check dmesg for errors: dmesg | grep -i wifi"
exit 1
fi
echo -e "${GREEN}Found interface: $IFACE${NC}"
echo ""
#------------------------------------------------------------------------------
# Check NetworkManager
#------------------------------------------------------------------------------
if command -v nmcli &> /dev/null; then
# Use NetworkManager
echo "Scanning for networks..."
echo ""
nmcli device wifi rescan 2>/dev/null
sleep 2
echo "Available networks:"
nmcli device wifi list
echo ""
read -p "Enter network name (SSID): " SSID
read -sp "Enter password: " PASSWORD
echo ""
echo "Connecting to $SSID..."
nmcli device wifi connect "$SSID" password "$PASSWORD"
if [ $? -eq 0 ]; then
echo -e "${GREEN}Connected successfully!${NC}"
echo ""
echo "IP Address:"
ip -4 addr show "$IFACE" | grep inet
else
echo -e "${RED}Connection failed!${NC}"
exit 1
fi
else
# Fallback to wpa_supplicant
echo "NetworkManager not available, using wpa_supplicant..."
read -p "Enter network name (SSID): " SSID
read -sp "Enter password: " PASSWORD
echo ""
# Create wpa_supplicant config
WPA_CONF="/tmp/wpa_temp.conf"
wpa_passphrase "$SSID" "$PASSWORD" > "$WPA_CONF"
# Stop any existing wpa_supplicant
killall wpa_supplicant 2>/dev/null
# Start wpa_supplicant
wpa_supplicant -B -i "$IFACE" -c "$WPA_CONF"
sleep 2
# Get IP via DHCP
dhcpcd "$IFACE"
echo -e "${GREEN}Connection attempted!${NC}"
echo ""
echo "IP Address:"
ip -4 addr show "$IFACE" | grep inet
fi