|
Linux Script Compatibility Checker
|
|
Topic Started: Monday, 17. May 2010, 00:56 (241 Views)
|
|
Ferus Grim
|
Monday, 17. May 2010, 00:56
Post #1
|
" Ego sum aeternam"
- Posts:
- 9,345
- Group:
- Retired Staff
- Member
- #405
- Joined:
- Apr 22, 2008
- Skype
- ferusgrim
|
Well, a lot of scripts in the linux world are just to install programs... Many times, the programs fail because something is running that shouldn't be, the arch is wrong, there isn't an internet connection, etc. Soooo, I made a script that you would put before your actual program that would check for those things... Here it is!
(I know most of you won't have a use for this, or even understand it, but I'm sure there are a few Linux users on this forum who would know what it is..)
Spoiler: click to toggle - Code:
-
RED="\033[0;31m" BLUE="\033[1;34m" ERROR="\033[0;41m" GREEN="\033[1;32m" ENDCOLOR="\033[0m" ARCHITECTURE=`uname -m` ## ## Clearing Screen clear ## ## Checking System Compatability. echo -e $BLUE"Running compatability checks..."$ENDCOLOR if [ $ARCHITECTURE != "i686" ] then echo -e $ERROR"Arch - Not Supported!"$ENDCOLOR exit 1 else echo -e $GREEN"Arch - Supported!"$ENDCOLOR fi testconnection=`wget --tries=3 --timeout=15 www.google.com -O /tmp/testinternet &>/dev/null 2>&1` if [ $? != 0 ] then echo -e $ERROR"You are not connected to the Internet. Please check your Internet connection and try again."$ENDCOLOR exit 1 else echo -e $GREEN"Internet - Connected!"$ENDCOLOR fi if [ -e /usr/bin/zenity ] then echo -e $GREEN"Zenity - Installed!"$ENDCOLOR else echo -e $ERROR"Zenity - Not Installed!"$ENDCOLOR echo -e $RED"Zenity is needed for this script to run properly. This script will now try to install it. If this is a problem, press 'CTRL + C'." sleep 5 sudo aptitude install zenity sudo apt-get update clear echo -e $BLUE"Running compatability checks..."$ENDCOLOR echo -e $GREEN"Arch - Supported!"$ENDCOLOR echo -e $GREEN"Internet - Connected!"$ENDCOLOR echo -e $GREEN"Zenity - Installed!"$ENDCOLOR fi echo -e $BLUE"You must be running with sudo. This script may ask for your password..."$ENDCOLOR sudo touch ~/Desktop/mksudo if [ $? -eq 0 ] then sudo rm ~/Desktop/mksudo else echo -e $ERROR"Please, run Blinding Edge with sudo, and try again!"$ENDCOLOR exit 1 fi echo -e $BLUE"Checking for running programs that may cause problems..."$ENDCOLOR if ps -e | grep "synaptic" | grep -v grep > /dev/null; then echo -e $ERROR"Synaptic - RUNNING!"$ENDCOLOR zenity --question --title="Warning!" --text="Synaptic is running!\n\nSynaptic can interfere with this script, making it unstable. In order to continue running this script, you must kill this program. This script can close the program for you, however, that may be unsafe.\n\nShould I close the Synaptic program?" if [ $? == 0 ] then sudo killall synaptic else exit 1 fi else echo -e $GREEN"Synaptic - Not Running!"$ENDCOLOR fi if ps -e | grep "update-manager" | grep -v grep > /dev/null; then echo -e $ERROR"Update Manager - RUNNING!"$ENDCOLOR zenity --question --title="Warning!" --text="The Update Manager is running!\n\nThe UM can interfere with this script, making it unstable. In order to continue running this script, you must kill this program. This script can close the program for you, however, that may be unsafe.\n\nShould I close the Update Manager?" if [ $? == 0 ] then sudo killall update-manager else exit 1 fi else echo -e $GREEN"Update Manager - Not Running!"$ENDCOLOR fi if ps -e | grep "software-center" | grep -v grep > /dev/null; then echo -e $ERROR"Software Center - RUNNING!"$ENDCOLOR zenity --question --title="Warning!" --text="The Ubuntu Software Center is running!\n\nThe USC can interfere with this script, making it unstable. In order to continue running this script, you must kill this program. This script can close the program for you, however, that may be unsafe.\n\nShould I close the Ubuntu Software Center?" if [ $? == 0 ] then sudo killall software-center else exit 1 fi else echo -e $GREEN"Software Center - Not Running!"$ENDCOLOR fi if ps -e | grep "apt-get" | grep -v grep > /dev/null; then echo -e $ERROR"apt-get - RUNNING!"$ENDCOLOR zenity --question --title="Warning!" --text="apt-get is running!\n\nThe apt-get program can interfere with this script, making it unstable. In order to continue running this script, you must kill this program. This script can close the program for you, however, that may be unsafe.\n\nShould I close apt-get?" if [ $? == 0 ] then sudo killall apt-get else exit 1 fi else echo -e $GREEN"apt-get - Not Running!"$ENDCOLOR fi if ps -e | grep "dpkg" | grep -v grep > /dev/null; then echo -e $ERROR"DPKG - RUNNING!"$ENDCOLOR zenity --question --title="Warning!" --text="DPKG is running!\n\nThe DRPKG program can interfere with this script, making it unstable. In order to continue running this script, you must kill this program. This script can close the program for you, however, that may be unsafe.\n\nShould I close DPKG?" if [ $? == 0 ] then sudo killall dpkg else exit 1 fi else echo -e $GREEN"DPKG - Not Running!"$ENDCOLOR fi unset ARCHITECTURE unset GREEN unset BLUE unset ERROR unset RED
|
|
| |
|
Ferus Grim
|
Monday, 17. May 2010, 04:06
Post #2
|
" Ego sum aeternam"
- Posts:
- 9,345
- Group:
- Retired Staff
- Member
- #405
- Joined:
- Apr 22, 2008
- Skype
- ferusgrim
|
Whole script.
blindingedge_v_0_1.shSpoiler: click to toggle - Code:
-
############################ ## ## ## Blinding Edge v0.1 ## ## ## ############################ ######################################################## ## ## ## This script was created by Nicholas Badger. ## ## Copyright under GPLv3, Open-Source intentions. ## ## http://www.gnu.org/licenses/gpl-3.0.html ## ## ## ######################################################## ################################################################################### ## ## ## While it is not necessary under Open Source or GPL to give recognition to ## ## inspirations or codes that you *cough* copy and pasted from, I would ## ## like to give credit to Paul Fedele, the author of Bleeding Edge, ## ## from which 80% of this scripts original code was edited, changed, ## ## or just copy and pasted. "http://sourceforge.net/projects/bleedingedge/" ## ## ## ################################################################################### #################################################################################################### ## ## ## If you are seeing this, you're most likely confused as to what is going on! ## ## To use this script, please open a terminal and use the following commands. ## ## ## ## 'cd ~/Downloads/' - This will take you to the Downloads directory. ## ## 'chmod a+x blindingedge_v_0_1.sh' - This will make the program executable. ## ## 'sudo ./blindingedge_v_0_1.sh' - This will run the program with administrative privelages. ## ## ## #################################################################################################### ########################################################################## ## ## ## If you need any help, I can always be reached through my email. ## ## On a similar note, I'm always looking for suggestions! Email me! ## ## ## ## Email: ## ## nichob [at] dreamrp [dot] com ## ## ## ########################################################################## #################################################################################################### ## ## ## Blinding Edge was designed under and for Ubuntu 10.04. You must have a 32bit Operating ## ## System, as well as have an active Internet Connection. Please be aware that this script ## ## will find and install programs that are not under the authors control. The author cannot ## ## be held responsible for errors in other program that may be installed or downloaded in the ## ## process of running Blinding Edge. Thank you for understanding, and your cooperation. ## ## Thank you for choosing Blinding Edge. ## ## ## #################################################################################################### ## ## ## ## ## ## ## ## ## ## ## ## Setting Variables RED="\033[0;31m" BLUE="\033[1;34m" ERROR="\033[0;41m" GREEN="\033[1;32m" ENDCOLOR="\033[0m" ARCHITECTURE=`uname -m` ## ## Clearing Screen clear ## ## Checking System Compatability. echo -e $BLUE"Running compatability checks..."$ENDCOLOR if [ $ARCHITECTURE != "i686" ] then echo -e $ERROR"Arch - Not Supported!"$ENDCOLOR exit 1 else echo -e $GREEN"Arch - Supported!"$ENDCOLOR fi testconnection=`wget --tries=3 --timeout=15 www.google.com -O /tmp/testinternet &>/dev/null 2>&1` if [ $? != 0 ] then echo -e $ERROR"You are not connected to the Internet. Please check your Internet connection and try again."$ENDCOLOR exit 1 else echo -e $GREEN"Internet - Connected!"$ENDCOLOR fi if [ -e /usr/bin/zenity ] then echo -e $GREEN"Zenity - Installed!"$ENDCOLOR else echo -e $ERROR"Zenity - Not Installed!"$ENDCOLOR echo -e $RED"Zenity is needed for this script to run properly. This script will now try to install it. If this is a problem, press 'CTRL + C'." sleep 5 sudo aptitude install zenity sudo apt-get update clear echo -e $BLUE"Running compatability checks..."$ENDCOLOR echo -e $GREEN"Arch - Supported!"$ENDCOLOR echo -e $GREEN"Internet - Connected!"$ENDCOLOR echo -e $GREEN"Zenity - Installed!"$ENDCOLOR fi echo -e $BLUE"You must be running with sudo. This script may ask for your password..."$ENDCOLOR sudo touch ~/Desktop/mksudo if [ $? -eq 0 ] then sudo rm ~/Desktop/mksudo else echo -e $ERROR"Please, run Blinding Edge with sudo, and try again!"$ENDCOLOR exit 1 fi echo -e $BLUE"Checking for running programs that may cause problems..."$ENDCOLOR if ps -e | grep "synaptic" | grep -v grep > /dev/null; then echo -e $ERROR"Synaptic - RUNNING!"$ENDCOLOR zenity --question --title="Warning!" --text="Synaptic is running!\n\nSynaptic can interfere with this script, making it unstable. In order to continue running this script, you must kill this program. This script can close the program for you, however, that may be unsafe.\n\nShould I close the Synaptic program?" if [ $? == 0 ] then sudo killall synaptic else exit 1 fi else echo -e $GREEN"Synaptic - Not Running!"$ENDCOLOR fi if ps -e | grep "update-manager" | grep -v grep > /dev/null; then echo -e $ERROR"Update Manager - RUNNING!"$ENDCOLOR zenity --question --title="Warning!" --text="The Update Manager is running!\n\nThe UM can interfere with this script, making it unstable. In order to continue running this script, you must kill this program. This script can close the program for you, however, that may be unsafe.\n\nShould I close the Update Manager?" if [ $? == 0 ] then sudo killall update-manager else exit 1 fi else echo -e $GREEN"Update Manager - Not Running!"$ENDCOLOR fi if ps -e | grep "software-center" | grep -v grep > /dev/null; then echo -e $ERROR"Software Center - RUNNING!"$ENDCOLOR zenity --question --title="Warning!" --text="The Ubuntu Software Center is running!\n\nThe USC can interfere with this script, making it unstable. In order to continue running this script, you must kill this program. This script can close the program for you, however, that may be unsafe.\n\nShould I close the Ubuntu Software Center?" if [ $? == 0 ] then sudo killall software-center else exit 1 fi else echo -e $GREEN"Software Center - Not Running!"$ENDCOLOR fi if ps -e | grep "apt-get" | grep -v grep > /dev/null; then echo -e $ERROR"apt-get - RUNNING!"$ENDCOLOR zenity --question --title="Warning!" --text="apt-get is running!\n\nThe apt-get program can interfere with this script, making it unstable. In order to continue running this script, you must kill this program. This script can close the program for you, however, that may be unsafe.\n\nShould I close apt-get?" if [ $? == 0 ] then sudo killall apt-get else exit 1 fi else echo -e $GREEN"apt-get - Not Running!"$ENDCOLOR fi if ps -e | grep "dpkg" | grep -v grep > /dev/null; then echo -e $ERROR"DPKG - RUNNING!"$ENDCOLOR zenity --question --title="Warning!" --text="DPKG is running!\n\nThe DRPKG program can interfere with this script, making it unstable. In order to continue running this script, you must kill this program. This script can close the program for you, however, that may be unsafe.\n\nShould I close DPKG?" if [ $? == 0 ] then sudo killall dpkg else exit 1 fi else echo -e $GREEN"DPKG - Not Running!"$ENDCOLOR fi zenity --question --title="Update?" --text="Do you want me to run a computer update?" if [ $? == 0 ] then echo -e $BLUE"Updating... This may take a while..."$ENDCOLOR sudo apt-get -y update > /dev/null; echo -e $GREEN"Update Complete!"$ENDCOLOR else echo -e $BLUE"Skipping update..."$ENDCOLOR fi zenity --question --text="Would you like me to tidy your computer up? This may free space and make your system move faster.\n\nThis may install localepurge onto your computer, if it isn't already." if [ $? == 0 ] then echo -e $BLUE"Running Computer Cleaner... This may take a while..."$ENDCOLOR if [ -f /usr/sbin/localepurge ] then echo -e $ERROR"Running localepurge..."$ENDCOLOR sudo localepurge > /dev/null else echo -e $ERROR"Installing localepurge..."$ENDCOLOR sudo aptitude install -y localepurge > /dev/null echo -e $ERROR"Running localepurge..."$ENDCOLOR sudo localepurge > /dev/null fi echo -e $ERROR"Purging packages..."$ENDCOLOR sudo apt-get autoremove --purge > /dev/null echo -e $ERROR"Cleaning packages..."$ENDCOLOR sudo apt-get clean > /dev/null echo -e $ERROR"Running updatedb..."$ENDCOLOR sudo updatedb > /dev/null OLDCONF=$(dpkg -l|grep "^rc"|awk '{print $2}') CURKERNEL=$(uname -r|sed 's/-*[a-z]//g'|sed 's/-386//g') LINUXPKG="linux-(image|headers|ubuntu-modules|restricted-modules)" METALINUXPKG="linux-(image|headers|restricted-modules)-(generic|i386|server|common|rt|xen)" OLDKERNELS=$(dpkg -l|awk '{print $2}'|grep -E $LINUXPKG |grep -vE $METALINUXPKG|grep -v $CURKERNEL) echo -e $ERROR"Cleaning apt cache..."$ENDCOLOR sudo aptitude clean > /dev/null echo -e $ERROR"Removing old config files..."$ENDCOLOR sudo aptitude purge $OLDCONF > /dev/null echo -e $ERROR"Removing old kernels..."$ENDCOLOR sudo aptitude purge $OLDKERNELS > /dev/null echo -e $ERROR"Emptying the trash..."$ENDCOLOR rm -rf /home/*/.local/share/Trash/*/** &> /dev/null rm -rf /root/.local/share/Trash/*/** &> /dev/null else echo -e $BLUE"Not running Ubuntu Cleaner..."$ENDCOLOR fi unset OLDKERNELS unset METALINUXPKG unset LINUXPKG unset CURKERNEL unset OLDCONF unset ARCHITECTURE unset GREEN unset BLUE unset ERROR unset RED echo ""
Lines:237 Note: I mean whole script as in everything that is done. The script isn't completely finished.
Edited by Ferus Grim, Monday, 17. May 2010, 04:08.
|
|
| |
| 1 user reading this topic (1 Guest and 0 Anonymous)
|