Script library (need help with these scripts)

About writing shell scripts and making the most of your shell
Forum rules
Topics in this forum are automatically closed 6 months after creation.
Locked
wei2912

Script library (need help with these scripts)

Post by wei2912 »

Welcome to the script library! Go to http://db.tt/Gg4GRId to download the scripts. More scripts will be added over time.

Download the launcher script first, then download other scripts. Please try out the scripts before removing them. You are recommended to download all scripts.

HELP NEEDED:
# - A backup script
# - More... help to brainstorm.

Will be adding more stuff. Anyway, for the moment, there are 2 functions:
1. Update your programs
2. Clean up Linux Mint

Future functions:
1. Speedup (version 1.3)
2. Backup (unknown...)

Changelog:

# Version 1.0
###### Config.sh ######
# Added update and clean function

# Version 1.1
###### Config.sh ######
# Added update grub to update function
# Added an infinite loop
# Cleaner interface (for editing)
# Commands from apt-get commands are still not removed, sorry. I tried using xenopeek's command but it failed.
# Attempted sudo startup failed - trash cleanup did not work as the user was recongnised as root.

# Version 1.2
###### Config.sh ######
# clean function moved to Cleaner.sh
# apt-get commands are finally removed! Thanks to xenopeek for providing the parameter.

###### Cleaner.sh ######
# Clean function added
# apt-get commands are finally removed! Thanks to xenopeek for providing the parameter.

###### All ######
# Info option for scripts is added.
# Terminal screen is made clearer.

#Version 1.3 - Future version
###### Cleaner.sh ######
# Added speedup function

Please try these scripts and if you find any bug in them or a function you would like to include, please make a post in this topic.
Last edited by wei2912 on Thu Sep 01, 2011 2:50 am, edited 8 times in total.
User avatar
xenopeek
Level 25
Level 25
Posts: 29504
Joined: Wed Jul 06, 2011 3:58 am

Re: A script to update and clean up your OS and more (need h

Post by xenopeek »

I suggest you force the user of the script to run it as root or with sudo, so you don't have to litter your script with sudos:

Code: Select all

if [ `whoami` != root ]; then
    echo Please run this script as root or using sudo
    exit
fi
Infinite loop:

Code: Select all

updatefunc() {
# update code goes here
}
cleanfunc() {
# cleaning code goes here
}
while true; do
  echo
  echo "Choose your option. Type the number of your selection."
  echo "  1. Update my programs."
  echo "  2. Clean up my Linux Mint installation."
  echo "  0. Exit"

  read ans
  case $ans in
    1)
    updatefunc
    ;;
    2)
    cleanfunc
    ;;
    0)
    exit
    ;;
  esac
done
Shoving all output into the black hole:

Code: Select all

some_command > /dev/null 2>&1
But I suggest you replace > /dev/null with >> logfile, so you can read that if something borks. And if you are hiding the output, I suggest you check the exit status of the commands (in variable $?) in your script, so you can alert the user if something didn't work.
Image
wei2912

Re: A script to update and clean up your OS and more (need h

Post by wei2912 »

Thanks. Updated the script, however i could not make the script run as root as if i did so, the user will be recognized as root. Also, the command you gave me did not work for me - the apt-get output still appeared.
User avatar
xenopeek
Level 25
Level 25
Posts: 29504
Joined: Wed Jul 06, 2011 3:58 am

Re: A script to update and clean up your OS and more (need h

Post by xenopeek »

wei2912 wrote:Thanks. Updated the script, however i could not make the script run as root as if i did so, the user will be recognized as root. Also, the command you gave me did not work for me - the apt-get output still appeared.
Well, I use the "check for root" lines regularly. You then run the script with sudo instead of normally, else it gives the error. I should put it at the top with the #!/bin/bash line. Never failed on me...

If > /dev/null 2>&1 doesn't work, read the manpage of apt-get (or other command) to see how to silence it. For apt-get:
-q, --quiet
Quiet; produces output suitable for logging, omitting progress
indicators. More q's will produce more quiet up to a maximum of 2.
You can also use -q=# to set the quiet level, overriding the
configuration file. Note that quiet level 2 implies -y, you should
never use -qq without a no-action modifier such as -d, --print-uris
or -s as APT may decided to do something you did not expect.
Image
wei2912

Re: Scripts to help your OS (need help)

Post by wei2912 »

Thanks, it worked for me. Just released version 1.2
User avatar
Pilosopong Tasyo
Level 6
Level 6
Posts: 1432
Joined: Mon Jun 22, 2009 3:26 am
Location: Philippines

Re: Script library (need help with these scripts)

Post by Pilosopong Tasyo »

Cleaner.sh, GetScripts.sh and PackagesConfig.sh
lines 9-12:

Code: Select all

case $response in
	*)
	;; #End
esac
Remove the above block. It doesn't serve any useful purpose. AKA dead code.
o Give a man a fish and he will eat for a day. Teach him how to fish and he will eat for a lifetime!
o If an issue has been fixed, please edit your first post and add the word [SOLVED].
wei2912

Re: Script library (need help with these scripts)

Post by wei2912 »

Sorry, i abandoned the scripts. I am currently working on a Java cleaner, so if you are interested in cleaning your OS, give me a PM and i will respond.

*** Administrators, can you help to lock this thread? Thanks. ***
rich_roast

Re: Script library (need help with these scripts)

Post by rich_roast »

Op's wish followed.
Locked

Return to “Scripts & Bash”