xboxscene.org forums

Author Topic: Lud Internals  (Read 205 times)

ldotsfan

  • Archived User
  • Hero Member
  • *
  • Posts: 2072
Lud Internals
« on: April 25, 2011, 04:38:00 AM »

CODE

#!/bin/sh
TMP=/tmp/lpart.tmp$$

TMPHDD=/tmp/hddsizeconfig.tmp$$
NUMBERS=""
get_numbers () {
    dialog --cancel-label "Finish"  --default-item "$2" --menu "$1" 0 60 0 "1" "" "2" "" "3" "" "4" "" "5" "" "6" "" "7" "" "8" "" "9" "" "0" "" "Backspace" "" 2>"$TMP"
    [ "$?" != 0 ] && { NUMBERS="$1"; return 0; }
    local ANSWER=`cat "$TMP"`
    case $ANSWER in
        Backspace)
            get_numbers "${1%[!:]}" "$ANSWER";;;
        *)
            get_numbers "$1$ANSWER" "$ANSWER";;;
    esac
    return 0
}

valid_size () {
        [ -n "$1" ] || return 1
        [ -n "$2" ] || return 1
        echo "$1" | grep -q "^[1-9][0-9]**$" || return 1
        [ "$1" -ge 0 -a "$1" -le "$2" ] || return 1
        
        return 0
}

get_size() {
totalsize=`cat /proc/ide/hda/capacity`
(( totalsize = totalsize*512 - 8*1024*1024*1024 ))
(( totalsize = `echo $totalsize | awk '{ printf ("%8d",$1/1024/1024/1024) }'`))
get_numbers "F Partition Size(MAX $totalsize GB) :" "1"
desiredsize=`echo "$NUMBERS" | cut -d ':' -f 2`
valid_size "$desiredsize" "$totalsize" || { dialog --msgbox "Invalid size. Using $totalsize instead." 0 0; desiredsize="$totalsize"; }
clear
return 0
rm -f "$TMPHDD"
}

choose_partitionsizes() {
i=10
totalsize=`cat /proc/ide/hda/capacity`
(( totalsize = totalsize*512 - 8*1024*1024*1024 ))
(( sizeincrement = totalsize/10 ))
(( fsize=i*sizeincrement/100 ))
(( gsize=totalsize-i*sizeincrement/100 ))
clear
while [ $i -lt 110 ]
do
(
(( fsizedisp = fsize/1024/1024 ))
(( gsizedisp = gsize/1024/1024 ))
cat << EOF
XXX
$i
Estimated F partition size:$fsizedisp MB
Estimated G partition size:$gsizedisp MB
Press Right arrow to increase size.
Press Left arrow to decrease size.
XXX
EOF
) | dialog \
        --title "Choose Partition Sizes" \
        --gauge "Choose Size" 10 80 0
sleep 1
  read -sn1 a
  if [[ "$a" == "" ]]
  then    
    break
  fi     
  test "$a" == `echo -en "\e"` || continue
  read -sn1 a
  test "$a" == "[" || continue
  read -sn1 a
  case "$a" in
    A)  break;;
    B) ;;
    C)  (( i = i + 10 ))
    (( fsize = i*sizeincrement/100 ))
    (( gsize = totalsize-i*sizeincrement/100 ));;
    D)  (( i = i - 10 ))
    (( fsize = i*sizeincrement/100 ))
    (( gsize = totalsize-i*sizeincrement/100 ));;
esac
done
}
main_menu(){
dialog --cancel-label "Quit"  --title "ldotsfan hdd partitioner" --menu "Choose an option" 0 0 0\
        1 "F is capped at 137GB" \
        2 "F occupies all available space" \
        3 "G occupies space beyond 137GB" \
        4 "F and G splits space evenly" \
        5 "Custom F size, G gets the rest" \
        6 "List partitions" \
        7 "exit to main menu" 2> "$TMP"
local choice=`cat "$TMP"`
(( i -= 10 ))
case $choice in
  *1* ) dialog --defaultno --yesno "Confirm format?" 6 24; test $? -eq 0 && /usr/bin/xboxdumper preparefg /dev/hda 0 ;;
  *2* ) dialog --defaultno --yesno "Confirm format?" 6 24; test $? -eq 0 && /usr/bin/xboxdumper preparefg /dev/hda 1 ;;
  *3* ) dialog --defaultno --yesno "Confirm format?" 6 24; test $? -eq 0 && /usr/bin/xboxdumper preparefg /dev/hda 2 ;;
  *4* ) dialog --defaultno --yesno "Confirm format?" 6 24; test $? -eq 0 && /usr/bin/xboxdumper preparefg /dev/hda 3 ;;
  *5* ) get_size; dialog --defaultno --yesno "Confirm format?" 6 24; test $? -eq 0 && /usr/bin/xboxdumper customfg /dev/hda $desiredsize ;;
  *6* ) dialog --msgbox "`/usr/bin/xboxdumper listpartitions /dev/hda`" 0 0;;
  exit ) return;;
  *);;
esac
}
main_menu
rm -f "$TMP"


The main menu of LUD.
CODE

#!/bin/sh
TMP=/tmp/xbox-menu.tmp$$
main_menu() {
    dialog --no-cancel --menu "Make your choice" 0 0 0 1 "Network Settings" 2 "Xbox Info" 3 "Partition Info" 4 "Format Extended Partitions" 5 "Reboot" 6 "Shutdown" 7 "Start a Linux shell" 2> "$TMP"
    local ANSWER=`cat "$TMP"`
    case $ANSWER in
        1)
                        network_settings_menu
                        main_menu;;;
        2)
            dialog --msgbox "`xbox-info -a`" 0 0
            main_menu;;;
        3)
            dialog --msgbox "`xboxdumper listpartitions /dev/hda`" 0 0
            main_menu;;;
        4)
            clear
            /usr/bin/lpartitioner
            main_menu;;;
        5)
            clear
            /sbin/reboot;;;
        6)
            clear
            /sbin/poweroff;;;
        7)
            dialog --inputbox "A USB keyboard is required to enter commands. Type \"ok\" to continue" 0 0 2> "$TMP"
            if [ "$?" = 0 -a "`cat "$TMP"|tr '[A-Z]' '[a-z]'`" = ok ]; then
                clear
                echo "Type exit to return to the menu"
                /bin/sh -i
            fi
            main_menu;;;
        *)
        ;;
    esac
}

network_settings_menu() {
    local IP=`ifconfig eth0 | grep 'inet addr' | cut -d ':' -f 2 | cut -d ' ' -f 1`
    if dialog --defaultno --yesno "Current IP Address: $IP\nDo you wish to reconfigure?" 0 0; then
        /usr/bin/netcardconfig
        network_settings_menu
    fi
}
ver=$(uname -r | awk {' printf ("%2.1f",$1) '})
[ $ver = 2.6 ] && /usr/bin/chimp && exit 0
main_menu
rm -f "$TMP"


Logged