You are not logged in.

#1 2008-08-15 21:01:56

haxit
Member
From: /home/haxit
Registered: 2008-03-04
Posts: 1,247
Website

Bash script from ubuntu to arch

I wrote this bash script in ubuntu and it worked perfectly.
Now in arch, it gives me errors about the elif's. Could someone please tell me what i am doing wrong?

#!/bin/sh
#`Requiem // HaXiT
# Script for Updating, Upgrading and Cleaning
# Beta v0.4

clear

OK=" \033[1;32mOK\033[0m "
FAIL="\033[1;31mFAIL\033[0m"
VER="Beta v0.4"

if [ "$1" = "-h" ]then

    echo "Help:\n"
    echo "Ubuntu and Variants (APT):"
    echo "Update [1] will update all your repositories."
    echo  "Upgrade [2] will upgrade all your installed programs to their newest versions."
    echo "Clean [3] will clean your system of temporary files."
    echo "All [4] will preform all duties listed above."
    echo "Exit [5] will exit the script.\n"
    echo "ArchLinux (Pacman):"
    echo "Upgrade [1] will upgrade all your installed software."
    echo "Sync [2] will sync your package list with the main servers."
    echo "Clean [3] will clean your package cache.."
    echo "All [4] will sync your repositorie then upgrade it.\n"
    echo "Exit [5] will simply exit the script.\n"
    echo "Run with -h to display help."
    echo "Run with -v to display version with a treat :D\n"
    echo 'Script written by `Requiem // HaXiT. Contact me about any issues at haxit911@gmail.com\n'
    echo "Script to be used for distros with apt-get and pacman command capabilities. Also the distro should have sudo properly installed and configured.\n"
    
elif [ "$1" = "-v" ]; then

    echo "$VER\n"
    printf "//\\ \nV%2s\\ \n \\%2s\\ \n%2s\\ \033[1;33m.\`-.\n%3s|\\ \`. \`.\n%3s( \\%2s\`. \`-.%24s_,.-:\\ \n%4s\\ \\%3s\`.%2s\`-._%13s__..--' ,-';/\n%5s\\ \`.%3s\`-.%3s\`-..___..---'%3s_.--' ,'/\n%6s\`. \`.%4s\`-._%8s__..--'%4s,' /\n%8s\`. \`-_%4s \`\`--..''%6s _.-' ,'\n%10s\`-_ \`-.___%8s__,--'%3s,'\n%13s\`-.__%2s\`----'''%4s__.-'\n%18s\`--..____..--'\033[0m\n\n"

elif [ "$1" = "" ]; then

    if [ `whoami` = "root" ]; then

    DIST_ID=`sudo cat /etc/issue | colrm 5`

        if [ "$DIST_ID" = "Ubun" -o "$DIST_ID" = "Kubu" -o "$DIST_ID" = "Xubu" -o ]; then

            update()
            {
                echo "System will now update..."
                sudo apt-get update > /dev/null
                echo "\n$OK"
                exit 
            }

            upgrade()
            {
                echo "System will now upgrade..."
                sudo apt-get upgrade
                echo "\n$OK"
                exit
            }

            clean()
            {        
                echo "System will now be cleaned..."
                sudo apt-get clean
                sudo apt-get autoclean
                sudo rm -rf /var/cache/apt/archives/*.deb
                echo "\n$OK"
                exit
            }

            all()
            {    
                echo "All maintenance actions will now be taken..."
                sudo apt-get update > /dev/null
                sudo apt-get upgrade
                sudo apt-get clean
                sudo apt-get autoclean
                sudo rm -rf /var/cache/apt/archives/*.deb
                echo "\n$OK"
                exit
            }
    
            echo ">> Menu (1-5)"
                echo " 1. Update systems repositories."
                echo " 2. Upgrade system software."
                echo " 3. Clean the system for junk."
                echo " 4. Preform all duties."
                echo " 5. Exit the script."
                echo -n "\nPlease enter your choice: "
                read INPUT

                case $INPUT in
                    "1")
                        update ;;
                    "2")
                        upgrade;;
                    "3")
                        clean;;
                    "4")
                        all;;
                    "5")
                        echo "\n$OK"
                        exit;;
                    *)
                               echo "\n$FAIL"
                        echo "Sorry invaild command \"$INPUT\". Please run with -h for help."
                        exit;;
                esac

        elif [ "$DIST_ID" = "Arch" -o ]; then

            upgrade()
            {    
                echo "System will now upgrade..."
                sudo pacman -Su
                echo "\n$OK"
            }

            sync()
            {
                echo "System will now be synced..."
                sudo pacman -Sy > /dev/null 
                echo "\n$OK"
            }

            clean()
            {
                echo "System will now be cleaned..."
                sudo pacman -Scc > /dev/null
                echo "\n$OK"
            }
            
            all()
            {
                echo "All maintenace actions will now be taken..."
                sudo pacman -Su
                sudo pacman -Sy > /dev/null 
                sudo pacman -Scc > /dev/null
                echo "\n$OK"
            }
            
            echo ">> Menu (1-5)"
                echo " 1. Upgrade system software."
                echo " 2. Sync system repositories.."
                echo " 3. Clean the system for junk."
                echo " 4. Preform all duties."
                echo " 5. Exit the script."
                echo -n "\nPlease enter your choice: "
                read INPUT

                case $INPUT in
                    "1")
                        upgrade ;;
                    "2")
                        sync;;
                    "3")
                        clean;;
                    "4")
                        all;;
                    "5")
                        echo "\n$OK"
                        exit;;
                    *)
                               echo "\n$FAIL"
                        echo "Sorry invaild command \"$INPUT\". Please run with -h for help."
                        exit;;
                esac
    
        else

            echo "Sorry, however your distribution is not support yet."

        fi

    else

        echo "Please run this script as root.\nPlease run with -h for help."

    fi

else

    echo "Sorry, however \"$1\" is an invalid command.\nPlease run with -h for help."

fi

Archi686 User | Old Screenshots | Old .Configs
Vi veri universum vivus vici.

Offline

#2 2008-08-15 21:13:53

smoon
Member
Registered: 2005-08-22
Posts: 468
Website

Re: Bash script from ubuntu to arch

You have an error at line 12:

if [ "$1" = "-h" ]then

should rather be

if [ "$1" = "-h" ] ; then

Offline

#3 2008-08-15 21:21:14

haxit
Member
From: /home/haxit
Registered: 2008-03-04
Posts: 1,247
Website

Re: Bash script from ubuntu to arch

Hah, bonehead mistake. O well, i have to rewrite all my scripts anyways. thanks for the help.


Archi686 User | Old Screenshots | Old .Configs
Vi veri universum vivus vici.

Offline

#4 2008-08-15 22:53:46

freakcode
Member
From: São Paulo - Brazil
Registered: 2007-11-03
Posts: 410
Website

Re: Bash script from ubuntu to arch

haxit wrote:

I wrote this bash script in ubuntu and it worked perfectly.
Now in arch, it gives me errors about the elif's. Could someone please tell me what i am doing wrong?

#!/bin/sh
...

You didn't wrote a *bash* script. In Ubuntu, /bin/sh points to dash, not bash.

Offline

#5 2008-08-16 15:17:43

haxit
Member
From: /home/haxit
Registered: 2008-03-04
Posts: 1,247
Website

Re: Bash script from ubuntu to arch

Whats the difference, if you don't mind explaining. Because \n don't work anymore.


Archi686 User | Old Screenshots | Old .Configs
Vi veri universum vivus vici.

Offline

#6 2008-08-16 15:52:26

rson451
Member
From: Annapolis, MD USA
Registered: 2007-04-15
Posts: 1,233
Website

Re: Bash script from ubuntu to arch

They are two different shells, I'm sure there are many differences.  Rather than porting all your scripts, why not just install dash and change the bang line to point to dash instead?


archlinux - please read this and this — twice — then ask questions.
--
http://rsontech.net | http://github.com/rson

Offline

#7 2008-08-16 15:55:00

haxit
Member
From: /home/haxit
Registered: 2008-03-04
Posts: 1,247
Website

Re: Bash script from ubuntu to arch

Sounds good, Thanks a lot guys.


Archi686 User | Old Screenshots | Old .Configs
Vi veri universum vivus vici.

Offline

#8 2008-08-16 16:34:02

Acecero
Member
Registered: 2008-06-21
Posts: 1,373

Re: Bash script from ubuntu to arch

haxit wrote:

Whats the difference, if you don't mind explaining. Because \n don't work anymore.

That's just it, shells like bash or zsh don't support escape sequences like in sh and others.

EDIT: Actually I take that mostly back, I found that some commands you have to find the option for those escape sequences such as:

echo -e "blah\nblah"

will work.

Last edited by Acecero (2008-08-16 16:44:57)

Offline

#9 2008-08-16 16:44:19

haxit
Member
From: /home/haxit
Registered: 2008-03-04
Posts: 1,247
Website

Re: Bash script from ubuntu to arch

Ah, i see. THanks


Archi686 User | Old Screenshots | Old .Configs
Vi veri universum vivus vici.

Offline

#10 2008-08-16 16:46:32

Acecero
Member
Registered: 2008-06-21
Posts: 1,373

Re: Bash script from ubuntu to arch

I don't know if I made it in time, but read my edit above. ^

Offline

#11 2008-08-16 16:48:43

haxit
Member
From: /home/haxit
Registered: 2008-03-04
Posts: 1,247
Website

Re: Bash script from ubuntu to arch

That is strange ;S
But I installed dash and I made my new scripts point to dash. Thanks bro.


Archi686 User | Old Screenshots | Old .Configs
Vi veri universum vivus vici.

Offline

Board footer

Powered by FluxBB