Bash Script Help


Recommended Posts

ok I'm writing this install script .. you can see I have functions that do somethings (most are not done)..

what I am having a problem with is the last 8 lines.. the if statments for the menu.. I have tried if and elif but it only takes options 1 the rest it ignores..

I have no clue why..

I now made mutiple if statments.. but still same thing..

also tried (as you can see) to change numbers for letter.. no work.

the partition (option 1) is the only one working.

thanks for any help

#!/bin/bash

#this is the start to a installation program for my linux distro

#Author: William Huskey <[email protected]>

# Some functions come from Tomas Matejicek <http://slax.linux-live.org> slax install script as noted above function.

# copywrite 2004 under the GPL www.gnu.org for a copy

#create temp variable

TMPFILE=/tmp/steve-installer-tmp

rm -f $TMPFILE

DISK="hda"

#begin with header information

clear

echo "This Program will assist you in installing Steve Linux to your hard drive."

echo "Please answer the questions and this will be a simple process."

echo "are you ready Y/n"

read a #this is just a pause to let the user read the output above

if [ "$a" = "n" ]; then

echo quit installer

exit

fi

this will start the main part of the install program

function menu()

{

clear

echo "There are severl things need to be done to install a Operating system."

echo "the following will allow you to do so"

echo "1. Partition harddrive"

echo "2. format Partition"

echo "3. IF you already have a formated partiton before starting pick me"

echo "4. install OS"

read Menu_choice

}

#This Function will format a partition for swap

function swap ()

{

mkswap /dev/$Swap

swapon /dev/$Swap

}

#This function will format the correct partition

function format ()

{

echo choose which format you will use

echo 1. reiserfs

echo 2. ext2

echo 3. ext3

read FMAT

mkfs.$FMAT /dev/$HD

}

#This is the function to partition your harddrive

function partition ()

{

/usr/sbin/cfdisk /dev/$DISK

menu

}

#this function will make the install folder and mount it

function mnt ()

{

mkdir /mnt/install

DEST="/mnt/install"

mount /dev/$HD /mnt/$DEST

}

# This function will allow you to choose what partition the user already has will be used

# this function is derived from the Slax-install script

function Usr_Pik ()

{

if [ "$1" = "" -o ! -d "$1" ]; then

ls -aA1bd /mnt/* | while read LINE;

do

MOUNT=`mount | egrep -v "\(.*bind.*\)" | egrep -v "\(.*loop.*\)" | grep -F "$LINE" | cut -d " " -f 1`

if [ ! "$MOUNT" = "" ]; then

echo -n "$LINE $MOUNT " >>$TMPFILE

fi

done

if [ "`cat $TMPFILE 2>/dev/null`" = "" ]; then error "You have to mount your partition to /mnt/something first. Try 'mntall' script."; fi

dialog --title "Steve Linux Hard Drive Chooser" --menu \

"BEFORE YOU START:\n\

Prepare your disk partition for example by using cfdisk\n\

and make ext2 or ext3 or reiserfs or xfs filesystem on it.\n\

Then mount it somewhere in /mnt/ or reboot Steve Linux\n\

to mount it automatically.\n\n\

All partitions available right now are listed below.\n\

Choose your target partition:\n" 0 0 0 `cat $TMPFILE` 2>$TMPFILE

if [ ! "$?" = 0 ]; then exit; fi

$0 `cat $TMPFILE`

rm -f $TMPFILE

exit

fi

exit

}

menu

if [ "$Menu_choice" = "1" ]; then

echo partition

partition

fi

if ["$Menu_choice" = "f" ]; then

exit #format

fi

if ["$Menu_choice" = "3" ]; then

Usr_Pik

fi

if ["$Menu_choice" = "4" ];then

exit

else

menu

fi

exit

Link to post
Share on other sites

changed to case statments now works..

Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...