View Single Post
Old 12-11-2023, 10:22 AM   #73
crazyren
Junior Member
crazyren began at the beginning.
 
Posts: 3
Karma: 10
Join Date: Dec 2023
Device: PW3
Lightbulb update

updated code

[I]-m for mount only [/I]

Code:
#!/bin/bash

# Flag to determine whether to mount the existing ext3 image file
MOUNT_ONLY=false

# Set the path to the local.ext3 file
LOCAL_EXT3_FILE="/mnt/us/local.ext3"

# Set the size of the ext3 image file in megabytes
EXT3_IMAGE_SIZE=500

# Function to display script usage
show_usage() {
  echo "Usage: $0 [-m]"
  echo "  -m   Mount the existing ext3 image file"
  exit 1
}

# Process command-line options
while getopts ":m" opt; do
  case $opt in
    m)
      MOUNT_ONLY=true
      ;;
    \?)
      echo "Invalid option: -$OPTARG"
      show_usage
      ;;
  esac
done

# Function to create and copy the ext3 image file
create_ext3_image() {
  dd if=/dev/zero of="$LOCAL_EXT3_FILE" bs=1M count="$EXT3_IMAGE_SIZE"
  mkfs.ext3 "$LOCAL_EXT3_FILE"
  cp "$LOCAL_EXT3_FILE" /media/Kindle
}

# Function to mount the ext3 image file
mount_ext3_image() {
  mntroot rw
  mkdir -p /mnt/loc
  mount -o loop,noatime -t ext3 "$LOCAL_EXT3_FILE" /mnt/loc
  mkdir -p /mnt/loc/opt/etc /mnt/loc/opt/share /mnt/loc/opt/lib /mnt/loc/opt/bin /mnt/loc/opt/tmp
  ln -s /mnt/loc/opt/etc /opt/etc
  ln -s /mnt/loc/opt/share /opt/share
  ln -s /mnt/loc/opt/lib /opt/lib
  ln -s /mnt/loc/opt/bin /opt/bin
  ln -s /mnt/loc/opt/tmp /opt/tmp
  mntroot ro
}

# Function to install OptWare
install_optware() {
  cd /opt/etc
  feed="http://ipkg.nslu2-linux.org/feeds/optware/cs08q1armel/cross/unstable"
  wget "${feed}/ipkg-opt_0.99.163-10_arm.ipk"
  tar -xOvzf ipkg-opt_0.99.163-10_arm.ipk ./data.tar.gz | tar -C /mnt/loc -xzvf -
  mkdir -p /opt/etc/ipkg
  echo "src cross $feed" > /opt/etc/ipkg/feeds.conf
  export PATH=$PATH:/opt/bin
  ipkg -t /opt/tmp update
}

# Main script
if [ "$MOUNT_ONLY" = false ]; then
  create_ext3_image
  mount_ext3_image
  install_optware
fi

if [ "$MOUNT_ONLY" = true ]; then
  mount_ext3_image
fi



Quote:
Originally Posted by crazyren View Post
Code:
#!/bin/bash

# Make root file system writable
mntroot rw

# Change to the /opt directory
cd /opt

# Set the Optware feed URL
feed="http://ipkg.nslu2-linux.org/feeds/optware/cs08q1armel/cross/unstable"

# Download the ipkg-opt package
wget "${feed}/ipkg-opt_0.99.163-10_arm.ipk"

# Extract the ipkg-opt package
tar -xOvzf ipkg-opt_0.99.163-10_arm.ipk ./data.tar.gz | tar -C / -xzvf -

# Create the ipkg directory
mkdir -p /opt/etc/ipkg

# Configure the Optware feed
echo "src cross $feed" > /opt/etc/ipkg/feeds.conf

# Update the package manager
export PATH=$PATH:/opt/bin
ipkg update

# Make root file system read-only
mntroot ro
crazyren is offline   Reply With Quote