Software Reinstall Script

Forum rules
Before you post please read this

Software Reinstall Script

Postby realitykid on Sat Mar 17, 2012 8:03 pm

Hello! I wrote a small script that would help me to reinstall my programs when I move to the next Mint release, and to remove the ones that usually comes preinstalled that I don't want. If you have any better ideas for a reinstall script, or ways to improve this, let me know. Thanks!

Code: Select all
echo "Installing Applications"
echo
apt-get install audacity devede xsensors pithos deluge dropbox openshot xvidcap cheese
echo
echo "Detecting Sensors (for xsensors) - Answer All Questions with 'YES'."
sensors-detect
echo
echo "Removing Unwanted Application"
echo
apt-get purge transmission-gtk libreoffice-core
apt-get autoremove
apt-get autoclean
apt-get clean
echo
echo "Installation and Uninstallation Complete"
echo
echo "Enjoy Linux Mint!"
echo
Read my full signature, it's too long for this forum:

https://dl.dropboxusercontent.com/u/113 ... nature.txt
realitykid
Level 3
Level 3
 
Posts: 180
Joined: Mon Jan 24, 2011 10:43 pm

Linux Mint is funded by ads and donations.
 

Re: Software Reinstall Script

Postby xenopeek on Sun Mar 18, 2012 5:43 am

Moved here by moderator

I'd make a few changes, to make it do steps without confirmation and to fully remove packages (including now unneeded dependencies). Perhaps include script header that automatically makes the script run from the terminal if not started from there (and it pauses after completion before closing the terminal). Now all it is missing is a way to check if the script was started as root (else it won't do anything of course).
Code: Select all
#!/bin/bash

# if the script was not launched from a terminal, restart it from a terminal
if [[ ! -t 0 ]] && [[ -x /usr/bin/x-terminal-emulator ]]; then
   /usr/bin/x-terminal-emulator -e "bash -c \"$0 $*; read -s -p 'Press enter to continue...'\""
   exit
fi

echo "Installing Applications"
echo
apt-get --assume-yes install audacity devede xsensors pithos deluge dropbox openshot xvidcap cheese
echo
echo "Detecting Sensors (for xsensors) - Answer All Questions with 'YES'."
sensors-detect
echo
echo "Removing Unwanted Application"
echo
apt-get --assume-yes --purge autoremove transmission-gtk libreoffice-core
apt-get --assume-yes --purge autoremove
apt-get autoclean
apt-get clean
echo
echo "Installation and Uninstallation Complete"
echo
echo "Enjoy Linux Mint!"
echo
Forum Rules | IRC Channel Rules
Image
Arch Linux / 64-bit / Gnome Shell
User avatar
xenopeek
Level 21
Level 21
 
Posts: 13692
Joined: Wed Jul 06, 2011 3:58 am
Location: The Netherlands

Re: Software Reinstall Script

Postby Pilosopong Tasyo on Fri Mar 23, 2012 1:35 am

Vincent Vermeulen wrote:Now all it is missing is a way to check if the script was started as root (else it won't do anything of course).

Code: Select all
...
if [ `whoami` = "root" ]
then
  ...
else
  echo "Run me as as root."
fi
...
Image
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].
User avatar
Pilosopong Tasyo
Level 5
Level 5
 
Posts: 999
Joined: Mon Jun 22, 2009 3:26 am
Location: Philippines

Re: Software Reinstall Script

Postby wei2912 on Tue Apr 17, 2012 10:55 am

Vincent Vermeulen wrote:Moved here by moderator

I'd make a few changes, to make it do steps without confirmation and to fully remove packages (including now unneeded dependencies). Perhaps include script header that automatically makes the script run from the terminal if not started from there (and it pauses after completion before closing the terminal). Now all it is missing is a way to check if the script was started as root (else it won't do anything of course).
Code: Select all
#!/bin/bash

# if the script was not launched from a terminal, restart it from a terminal
if [[ ! -t 0 ]] && [[ -x /usr/bin/x-terminal-emulator ]]; then
   /usr/bin/x-terminal-emulator -e "bash -c \"$0 $*; read -s -p 'Press enter to continue...'\""
   exit
fi

echo "Installing Applications"
echo
apt-get --assume-yes install audacity devede xsensors pithos deluge dropbox openshot xvidcap cheese
echo
echo "Detecting Sensors (for xsensors) - Answer All Questions with 'YES'."
sensors-detect
echo
echo "Removing Unwanted Application"
echo
apt-get --assume-yes --purge autoremove transmission-gtk libreoffice-core
apt-get --assume-yes --purge autoremove
apt-get autoclean
apt-get clean
echo
echo "Installation and Uninstallation Complete"
echo
echo "Enjoy Linux Mint!"
echo


Pilosopong Tasyo wrote:
Vincent Vermeulen wrote:Now all it is missing is a way to check if the script was started as root (else it won't do anything of course).

Code: Select all
...
if [ `whoami` = "root" ]
then
  ...
else
  echo "Run me as as root."
fi
...


I personally believe in convienence. What i usually do is to ask for the password first in a script, and add sudo to each line (that might be troublesome, but it is worth the effort. More effort on scripting for your users' less effort. :D)

Also, sudo dpkg --configure -a should be used in case of interrupted installation of programs from another time.

Here's my version:
Code: Select all
#!/bin/bash

# if the script was not launched from a terminal, restart it from a terminal
if [[ ! -t 0 ]] && [[ -x /usr/bin/x-terminal-emulator ]]; then
   /usr/bin/x-terminal-emulator -e "bash -c \"$0 $*; read -s -p 'Press enter to continue...'\""
   exit
fi

echo "Installing Applications"
echo
sudo dpkg --configure -a
clear
sudo apt-get -q=1 -y install audacity devede xsensors pithos deluge dropbox openshot xvidcap cheese deborphan preload
clear
echo
echo "Detecting Sensors (for xsensors) - Answer All Questions with 'YES'."
sudo sensors-detect
echo
echo "Removing Unwanted Application"
echo
sudo apt-get -q=1 -y --purge autoremove transmission-gtk libreoffice-core brltty brltty-x11 foo2zjs gwibber gwibber-service hplip hplip-cups hplip-data hpijs min12xxw pxljr splix ttf-indic-fonts-core ttf-kacst-one ttf-khmeros-core ttf-lao ttf-punjabi-fonts ttf-unfonts-core
sudo apt-get -q=1 -y --purge autoremove
sudo apt-get -q=1 autoclean
sudo apt-get -q=1 clean
clear
echo
echo "Installation and Uninstallation Complete"
echo
echo "Cleaning starts now!"
echo

## wei2912's cleanPackages script

### Start of removing old packages ###
sudo deborphan | xargs sudo apt-get -y remove --purge
sudo apt-get -q=1 -y autoremove --purge
dpkg --list |grep "transitional" | cut -d " " -f 3 | xargs sudo dpkg --purge #Transitional packages
dpkg --list |grep "meta" | cut -d " " -f 3 | xargs sudo dpkg --purge #Meta packages
### End of removing old packages ###

### Start of removing residual config ###
dpkg --list |grep "^rc" | cut -d " " -f 3 | xargs sudo dpkg --purge
### End of removing residual config ###

### Start of removing downloaded deb files ###
sudo apt-get -q=1 autoclean
sudo aptitude -q=1 autoclean
### End of removing downloaded deb files ###

#Clean up cache
sudo apt-get -q=1 clean
sudo aptitude -q=1 clean

clear
echo "Enjoy Linux Mint!"
echo "Press enter to exit."
read enter


Feel free to remove the "#wei2912's cleanPackages script" part. If you are still going to use my cleaning script, please add me in the credits. Also, DO NOT REMOVE DEBORPHAN FROM THE INSTALLATION PART, OR ELSE MY SCRIPT WILL FAIl.

One more thing. I feel that you should register this under the GPL license.

All you need to do is to add this section to the top of your script:

Code: Select all
## COPYRIGHT
##
## These scripts are registed under the GNU General Public License v3.0.
##
## Copyright (C) <year>  <name of author>
##
##     This program is free software: you can redistribute it and/or modify
##     it under the terms of the GNU General Public License as published by
##     the Free Software Foundation, either version 3 of the License, or
##     (at your option) any later version.
##
##     This program is distributed in the hope that it will be useful,
##     but WITHOUT ANY WARRANTY; without even the implied warranty of
##     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
##     GNU General Public License for more details.
##
##     You should have received a copy of the GNU General Public License
##     along with this program.  If not, see <http://www.gnu.org/licenses/>.


And a page you might be interested in for reinstalling (but it requires the software list of the previous installation)
http://www.cyberciti.biz/tips/linux-get ... store.html
mintBackup can do the job too, but you probably don't want it to popup half-way in your script. So its better to do by commands.

Cons:
It requires a backup file.
Unneeded software which is no longer in the new release might be installed.'

Finally, here's one more of my scripts (lol) for PPAs:

Code: Select all
#!/bin/bash

sudo dpkg --configure -a
clear

while true;do
clear
echo "Please select PPAs to install by typing out the number. If you have no more PPAs to install, type 'd' and press enter."
echo "1) New overlay scrollbars."
echo "2) Gnomenu for gtk 2.0."
echo "3) Opera browser"
echo "4) Banshee (Stable) music player"
echo "5) Banshee (Unstable) music player"
echo "6) Y PPA Manager"
echo "7) Pinta painter"
echo ""
read answer
case "$answer" in

1)
   echo ""
   echo "Adding overlay scrollbars..."
   sudo apt-add-repository 'deb http://ppa.launchpad.net/ayatana-scrollbar-team/release/ubuntu oneiric main'
   echo ""
   echo "Now you can install them by typing out this command after this script finishes:"
   echo "sudo apt-get install overlay-scrollbars"
   echo "If the package is already installed, the remaining part of the script will upgrade it."
   echo ""
   echo "Press enter to proceed."
   read enter
   clear
;;

2)
   echo ""
   echo "Adding Gnomenu ppa..."
   sudo apt-add-repository 'deb http://ppa.launchpad.net/gnomenu-team/ppa/ubuntu natty main '
   echo ""
   echo "Now you can install them by typing out this command after this script finishes:"
   echo "sudo apt-get install gnomenu"
   echo "If the package is already installed, the remaining part of the script will upgrade it."
   echo ""
   echo "Press enter to proceed."
   read enter
   clear

;;

3)
   echo ""
   echo "Adding Opera"
   wget -O - http://deb.opera.com/archive.key | sudo apt-key add -
   sudo add-apt-repository 'deb http://deb.opera.com/opera/ stable non-free'
   echo ""
   echo "Now you can install them by typing out this command after this script finishes:"
   echo "sudo apt-get install opera"
   echo "If the package is already installed, the remaining part of the script will upgrade it."
   echo ""
   echo "Press enter to proceed."
   read enter
   clear
;;

4)
   echo ""
   echo "Adding Banshee (Stable)"
   sudo add-apt-repository 'deb http://ppa.launchpad.net/banshee-team/ppa/ubuntu oneiric main'
   echo ""
   echo "Now you can install them by typing out this command after this script finishes:"
   echo "sudo apt-get install banshee"
   echo "If the package is already installed, the remaining part of the script will upgrade it."
   echo ""
   echo "Press enter to proceed."
   read enter
   clear
;;

5)
   echo ""
   echo "Adding Banshee (Unstable)"
   sudo add-apt-repository 'deb http://ppa.launchpad.net/banshee-team/banshee-unstable/ubuntu oneiric main '
   echo ""
   echo "Adding Banshee Extensions PPA (same as Banshee Stable ppa)"
   sudo add-apt-repository 'deb http://ppa.launchpad.net/banshee-team/ppa/ubuntu oneiric main'
   echo ""
   echo "Now you can install them by typing out this command after this script finishes:"
   echo "sudo apt-get install banshee"
   echo "Extensions can be installed by searching for banshee-extensions-<extension name>."
   echo "If the package is already installed, the remaining part of the script will upgrade it."
   echo ""
   echo "Press enter to proceed."
   read enter
   clear
;;

6)
   echo ""
   echo "Adding Y PPA Manager"
   sudo add-apt-repository 'deb http://ppa.launchpad.net/webupd8team/y-ppa-manager/ubuntu oneiric main'
   echo ""
   echo "Now you can install them by typing out this command after this script finishes:"
   echo "sudo apt-get install y-ppa-manager"
   echo "If the package is already installed, the remaining part of the script will upgrade it."
   echo ""
   echo "Press enter to proceed."
   read enter
   clear
;;

7)
   echo ""
   echo "Adding Pinta"
   sudo add-apt-repository ppa:nilarimogard/webupd8
   echo ""
   echo "Now you can install them by typing out this command after this script finishes:"
   echo "sudo apt-get install pinta"
   echo "If the package is already installed, the remaining part of the script will upgrade it."
   echo ""
   echo "Press enter to proceed."
   read enter
   clear
;;

d)
   clear
   sudo apt-get update
   sudo aptitude dist-upgrade
   sudo apt-get clean

   echo "Cleaning your system with the cleanPackages script... To cancel, please close the terminal window now."
   echo "If you would like to continue, press enter."
   read enter
   ./cleanPackages.sh

;;
esac
done


You can add it to the script, but remember to edit the last part so that it won't launch a non-existent script.

Hope I get to see more advancements in this script. I'm interested in using it. :D
wei2912
Level 2
Level 2
 
Posts: 79
Joined: Thu Jun 02, 2011 1:00 am

Re: Software Reinstall Script

Postby realitykid on Wed Apr 18, 2012 3:59 am

I apologize that it took me so long to get back to you on this. Been a bit busy here and there.

You all have some pretty good suggestions. I'll be sure you implement some of your ideas and give credit where credit it due. Wasn't planning on releasing this script, but if we can possibly get it working well enough, maybe I can.

I wonder if there is a way to have a script that checks for currently installed software and generates this installation script using the software installed on the user's machine instead of what is installed on my own.

Edit: I'm sorry wei2912. I'm way out of it. lol I'm looking into your suggestion too.
Read my full signature, it's too long for this forum:

https://dl.dropboxusercontent.com/u/113 ... nature.txt
realitykid
Level 3
Level 3
 
Posts: 180
Joined: Mon Jan 24, 2011 10:43 pm

Re: Software Reinstall Script

Postby realitykid on Wed Apr 18, 2012 4:38 am

Ok, so I did some mucking around with it, and here is the result thus far.

Code: Select all
## COPYRIGHT
##
## These scripts are registed under the GNU General Public License v3.0.
##
## Copyright (C) 2012  Devon Day
##
##     This program is free software: you can redistribute it and/or modify
##     it under the terms of the GNU General Public License as published by
##     the Free Software Foundation, either version 3 of the License, or
##     (at your option) any later version.
##
##     This program is distributed in the hope that it will be useful,
##     but WITHOUT ANY WARRANTY; without even the implied warranty of
##     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
##     GNU General Public License for more details.
##
##     You should have received a copy of the GNU General Public License
##     along with this program.  If not, see <http://www.gnu.org/licenses/>.



#Check Root Script Contributed By Pilosopong Tasyo
if [ `whoami` = "root" ]
then
#End Script Contributed by Pilosopong Tasyo

#"apt-get --assume-yes install" was Vincent Vermeulen's Idea
#Start Script Contributed By Vincent Vermeulen
#!/bin/bash

# if the script was not launched from a terminal, restart it from a terminal
if [[ ! -t 0 ]] && [[ -x /usr/bin/x-terminal-emulator ]]; then
   /usr/bin/x-terminal-emulator -e "bash -c \"$0 $*; read -s -p 'Press enter to continue...'\""
   exit
fi
#End Script Contributed By Vincent Vermeulen

#Install Applications using ~/installed-software.log
#Suggested by wei2912
apt-get update
echo "Installing Applications"
echo
apt-get install deselect
echo
dpkg --get-selections < ~/installed-software.log
dselect -i

#Autoclean
echo
echo "Cleaning out extra gunk."
echo
echo
apt-get --assume-yes autoremove
apt-get autoclean
apt-get clean
echo
echo
echo "Detecting Sensors (for xsensors) - Answer All Questions with 'YES'."
echo
echo
sensors-detect
echo
echo "Installation and Uninstallation Complete"
echo
echo "Enjoy Linux Mint!"
echo
reboot

#Stop Script if not in Root - Pilosopong Tasyo
else
  echo "Run me as as root."
fi
#End Script Contributed by Pilosopong Tasyo


Now, the GPL part of it probably wasn't necessary, but if this ends up anywhere, I'd like it to be ready. lol

Of course, in order for this to work, "dpkg --get-selections > ~/installed-software.log" needs to be run. I didn't include that in the script, although I probably should have.

Also, I am thinking of removing "sensors-detect".
Read my full signature, it's too long for this forum:

https://dl.dropboxusercontent.com/u/113 ... nature.txt
realitykid
Level 3
Level 3
 
Posts: 180
Joined: Mon Jan 24, 2011 10:43 pm

Re: Software Reinstall Script

Postby wei2912 on Wed Apr 18, 2012 7:54 am

realitykid wrote:Ok, so I did some mucking around with it, and here is the result thus far.

Code: Select all
## COPYRIGHT
##
## These scripts are registed under the GNU General Public License v3.0.
##
## Copyright (C) 2012  Devon Day
##
##     This program is free software: you can redistribute it and/or modify
##     it under the terms of the GNU General Public License as published by
##     the Free Software Foundation, either version 3 of the License, or
##     (at your option) any later version.
##
##     This program is distributed in the hope that it will be useful,
##     but WITHOUT ANY WARRANTY; without even the implied warranty of
##     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
##     GNU General Public License for more details.
##
##     You should have received a copy of the GNU General Public License
##     along with this program.  If not, see <http://www.gnu.org/licenses/>.



#Check Root Script Contributed By Pilosopong Tasyo
if [ `whoami` = "root" ]
then
#End Script Contributed by Pilosopong Tasyo

#"apt-get --assume-yes install" was Vincent Vermeulen's Idea
#Start Script Contributed By Vincent Vermeulen
#!/bin/bash

# if the script was not launched from a terminal, restart it from a terminal
if [[ ! -t 0 ]] && [[ -x /usr/bin/x-terminal-emulator ]]; then
   /usr/bin/x-terminal-emulator -e "bash -c \"$0 $*; read -s -p 'Press enter to continue...'\""
   exit
fi
#End Script Contributed By Vincent Vermeulen

#Install Applications using ~/installed-software.log
#Suggested by wei2912
apt-get update
echo "Installing Applications"
echo
apt-get install deselect
echo
dpkg --get-selections < ~/installed-software.log
dselect -i

#Autoclean
echo
echo "Cleaning out extra gunk."
echo
echo
apt-get --assume-yes autoremove
apt-get autoclean
apt-get clean
echo
echo
echo "Detecting Sensors (for xsensors) - Answer All Questions with 'YES'."
echo
echo
sensors-detect
echo
echo "Installation and Uninstallation Complete"
echo
echo "Enjoy Linux Mint!"
echo
reboot

#Stop Script if not in Root - Pilosopong Tasyo
else
  echo "Run me as as root."
fi
#End Script Contributed by Pilosopong Tasyo


Now, the GPL part of it probably wasn't necessary, but if this ends up anywhere, I'd like it to be ready. lol

Of course, in order for this to work, "dpkg --get-selections > ~/installed-software.log" needs to be run. I didn't include that in the script, although I probably should have.

Also, I am thinking of removing "sensors-detect".


Looks good. :) Just to note, what about making another script for backup, and use this script as restore? You can throw in any good backup script. Maybe you can also backup the config? Its all in the users' home folder and the /etc/skel directory.

Maybe you didn't notice the flags I added to the scripts. You can add -q=1 (clears most information that may be confusing to the user) to apt-get (apt-get -q=1 ...). Also, adding dpkg --configure -a helps to restore interrupted installs. Adding on, apt-get -f install will help to fix broken packages.

I apologize for the overload. lol.

(OFF TOPIC: DOES ANYONE HAVE IDEAS ON OPTIMIZING YOUR COMPUTER SPEED? WE CAN ALSO ADD IT TO THE SCRIPT)
wei2912
Level 2
Level 2
 
Posts: 79
Joined: Thu Jun 02, 2011 1:00 am

Re: Software Reinstall Script

Postby realitykid on Wed Apr 18, 2012 5:43 pm

wei2912 wrote:
Looks good. :) Just to note, what about making another script for backup, and use this script as restore? You can throw in any good backup script. Maybe you can also backup the config? Its all in the users' home folder and the /etc/skel directory.

Maybe you didn't notice the flags I added to the scripts. You can add -q=1 (clears most information that may be confusing to the user) to apt-get (apt-get -q=1 ...). Also, adding dpkg --configure -a helps to restore interrupted installs. Adding on, apt-get -f install will help to fix broken packages.

I apologize for the overload. lol.

(OFF TOPIC: DOES ANYONE HAVE IDEAS ON OPTIMIZING YOUR COMPUTER SPEED? WE CAN ALSO ADD IT TO THE SCRIPT)


If you want to try making a backup script capable of doing such, go for it. I'll look at the -q=1 when I have more time. If you'd like to, add it yourself. The script is all there. :) Any more suggestions, just add to the script so we can take a look at it.
Read my full signature, it's too long for this forum:

https://dl.dropboxusercontent.com/u/113 ... nature.txt
realitykid
Level 3
Level 3
 
Posts: 180
Joined: Mon Jan 24, 2011 10:43 pm

Re: Software Reinstall Script

Postby Pilosopong Tasyo on Wed Apr 18, 2012 10:50 pm

Further refinement:

In lieu of putting the lengthy code block between the then...else statement, you can use the following instead:

Code: Select all
if [ `whoami` != "root" ]
then
  sudo $0 $*
  exit
fi

# Put the rest of the script here.

Put the above fragment after Vincent Vermeulen's post. Here's an example:

Code: Select all
#! /bin/bash

# The following code fragment aims to (1) automate the following:
#   (a) the script runs in a terminal window
#   (b) the script runs as root (sudo)
# and (2) group them at the beginning of the script.  It lessens code complexity
# and bugs due to possible mismatched/lengthy/nested if-then-else-fi codeblocks.
# Put the code fragment at the beginning of the script.

# First checkpoint - the script should be running in a terminal window
tty -s
if [ $? -ne 0 ]
then
  gnome-terminal --command="$0 $*"
  exit
fi

# Second checkpoint - the script should be running as root (sudo)
if [ `whoami` != "root" ]
then
  sudo $0 $*
  sudo -k  # Drop privileges, optional
  exit  # Required, otherwise the rest of the script will run as regular user
fi

# The rest of the script goes here
echo "Current user - `whoami`"
echo "Number of parameters - $#"
echo "Parameter list - $*"
read -p "Press enter to close..."

HTH.
Image
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].
User avatar
Pilosopong Tasyo
Level 5
Level 5
 
Posts: 999
Joined: Mon Jun 22, 2009 3:26 am
Location: Philippines

Re: Software Reinstall Script

Postby wei2912 on Thu Apr 19, 2012 7:55 am

Optimization code:
Code: Select all
echo "Please answer the following questions in order to give you the best experience."
echo "If you are unable to answer the questions, press enter for the default (marked by *)."
echo "Example: Red, Green,* Yellow (Yellow is the default)"
echo ""
echo "Press enter to continue."
read enter

echo "Question 1: Do you NOT have a lot of RAM (about below 8GB)? [* Y/N]"
read answer
case "$answer" in
y*|Y*)
   sudo add-apt-repository ppa:shnatsel/zram #Zram
   sudo apt-get -q=1 update

   sudo apt-get -q=1 -y install zramswap-enabler #Helps with swap management by compressing swap into RAM.
   sudo echo "vm/swappiness=90" >> /etc/sysctl.conf #Uses swap more -> Added a line configuring swappiness by default.
;;

*)
   sudo echo "vm/swappiness=0" >> /etc/sysctl.conf #Doesn't use swap at all -> Added a line configuring swappiness by default.
;;
esac
echo ""
echo ""

echo "Question 2: Is your computer modern (less than 4 years old)? [* Y/N]"
read answer
case "$answer" in
y*|Y*)
   sudo apt-get -q=1 -y install preload
;;
esac
echo ""
echo ""
   
echo "Thanks for taking your time in answering the questions."
echo ""


This is my script for optimizations, maybe we can add it to the script?
=====================================================================================
My version now:
Code: Select all
#!/bin/bash
## COPYRIGHT
##
## These scripts are registed under the GNU General Public License v3.0.
##
## Copyright (C) 2012  Devon Day
##
##     This program is free software: you can redistribute it and/or modify
##     it under the terms of the GNU General Public License as published by
##     the Free Software Foundation, either version 3 of the License, or
##     (at your option) any later version.
##
##     This program is distributed in the hope that it will be useful,
##     but WITHOUT ANY WARRANTY; without even the implied warranty of
##     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
##     GNU General Public License for more details.
##
##     You should have received a copy of the GNU General Public License
##     along with this program.  If not, see <http://www.gnu.org/licenses/>.

## This script is created with the help of realitykid (original maker), Vincent Vermeulen, Pilosopong Tasyo and wei2912 (

#! /bin/bash

# The following code fragment aims to (1) automate the following:
#   (a) the script runs in a terminal window
#   (b) the script runs as root (sudo)
# It lessens code complexity and bugs due to possible
# mismatched/lengthy/nested if-then-else-fi codeblocks.
# Put the code fragment at the beginning of the script.

# First checkpoint - the script should be running in a terminal window
tty -s
if [ $? -ne 0 ]
then
  gnome-terminal --command="$0 $*"
  exit
fi

# Second checkpoint no longer needed. (the script must run in root)

echo "Current user - `whoami`"
echo "Number of parameters - $#"
echo "Parameter list - $*"
read -p "Press enter to continue..."

echo "Installing Applications, make sure you have backup ready, or else the "
echo "terminal window might recieve an error and close."
read -p "Press enter to continue..."
echo
sudo dpkg --configure -a
sudo apt-get -f -q=1 install
clear
sudo apt-get -q=1 -y install dselect
sudo dpkg --get-selections < ~/installed-software.log
clear
echo
echo "Detecting Sensors (for xsensors) - Answer All Questions with 'YES'."
read -p "Press enter to continue..."
sudo sensors-detect
echo
echo "Removing Unwanted Application"
read -p "Press enter to continue..."
echo
sudo apt-get -q=1 -y --purge autoremove transmission-gtk libreoffice-core
sudo apt-get -q=1 -y --purge autoremove
sudo apt-get -q=1 autoclean
sudo apt-get -q=1 clean
clear
sudo dpkg --configure -a
clear
echo
echo "Please answer the following questions in order to give you the best experience."
echo "If you are unable to answer the questions, press enter for the default (marked by *)."
echo "Example: Red, Green,* Yellow (Yellow is the default)"
echo
read -p "Press enter to continue..."

echo "Question 1: Do you NOT have a lot of RAM (about below 8GB)? [* Y/N]"
read answer
case "$answer" in
y*|Y*)
   sudo add-apt-repository ppa:shnatsel/zram #Zram
   sudo apt-get -q=1 update

   sudo apt-get -q=1 -y install zramswap-enabler #Helps with swap management by compressing swap into RAM.
   sudo echo "vm/swappiness=90" >> /etc/sysctl.conf #Uses swap more -> Added a line configuring swappiness by default.
;;

*)
   sudo echo "vm/swappiness=0" >> /etc/sysctl.conf #Doesn't use swap at all -> Added a line configuring swappiness by default.
;;
esac
echo
echo

echo "Question 2: Is your computer modern (less than 4 years old)? [* Y/N]"
read answer
case "$answer" in
y*|Y*)
   sudo apt-get install preload
;;
esac
echo
echo
   
echo "Thanks for taking your time in answering the questions."
echo
echo "Installation and Uninstallation Complete"
echo
echo "Cleaning starts now!"
read -p "Press enter to continue..."
echo

## wei2912's cleanPackages script

## Installs deborphan
sudo apt-get -q=1 -y install deborphan

### Start of removing the standard unnecessary packages ###
sudo apt-get -q=1 -y purge brltty brltty-x11 foo2zjs gwibber gwibber-service hplip hplip-cups hplip-data hpijs min12xxw pxljr splix ttf-indic-fonts-core ttf-kacst-one ttf-khmeros-core ttf-lao ttf-punjabi-fonts ttf-unfonts-core
### End of removing the standard unnecessary packages ###

### Start of removing old packages ###
sudo deborphan | xargs sudo apt-get -y remove --purge
sudo apt-get -q=1 -y autoremove --purge
dpkg --list |grep "transitional" | cut -d " " -f 3 | xargs sudo dpkg --purge #Transitional packages
dpkg --list |grep "meta" | cut -d " " -f 3 | xargs sudo dpkg --purge #Meta packages
### End of removing old packages ###

### Start of removing residual config ###
dpkg --list |grep "^rc" | cut -d " " -f 3 | xargs sudo dpkg --purge
### End of removing residual config ###

### Start of removing downloaded deb files ###
sudo apt-get -q=1 autoclean
sudo aptitude -q=1 autoclean
### End of removing downloaded deb files ###

#Clean up cache
sudo apt-get -q=1 clean
sudo aptitude -q=1 clean

clear
echo "Enjoy Linux Mint!"
read -p "Press enter to close..."
wei2912
Level 2
Level 2
 
Posts: 79
Joined: Thu Jun 02, 2011 1:00 am

Re: Software Reinstall Script

Postby realitykid on Fri Apr 20, 2012 3:59 am

Sorry, I'll look at your version of the script next week. I'm going to California and leaving at around 6AM today. Sorry. If I get a chance, I'll look at it while I am in California, but, until then, please be patient with me. Feel free to add on to it even further if you come up with more ideas.
Read my full signature, it's too long for this forum:

https://dl.dropboxusercontent.com/u/113 ... nature.txt
realitykid
Level 3
Level 3
 
Posts: 180
Joined: Mon Jan 24, 2011 10:43 pm

Re: Software Reinstall Script

Postby wei2912 on Fri Apr 20, 2012 7:37 am

realitykid wrote:Sorry, I'll look at your version of the script next week. I'm going to California and leaving at around 6AM today. Sorry. If I get a chance, I'll look at it while I am in California, but, until then, please be patient with me. Feel free to add on to it even further if you come up with more ideas.


Lol, no need to look at my script unless you want to. I'm just posting it in case anyone wants it.
wei2912
Level 2
Level 2
 
Posts: 79
Joined: Thu Jun 02, 2011 1:00 am

Re: Software Reinstall Script

Postby realitykid on Sat Apr 21, 2012 12:57 am

wei2912 wrote:
Lol, no need to look at my script unless you want to. I'm just posting it in case anyone wants it.


Of course I want to see your script. :p

My only question is, what is the purpose to using sudo on almost every line that requires root privileges? Why can't the users of the script just run the script as root?

Now, if you do want to keep sudo in the script, then at least use gksudo, that way it's easier to use.
Read my full signature, it's too long for this forum:

https://dl.dropboxusercontent.com/u/113 ... nature.txt
realitykid
Level 3
Level 3
 
Posts: 180
Joined: Mon Jan 24, 2011 10:43 pm

Re: Software Reinstall Script

Postby wei2912 on Mon Apr 23, 2012 12:20 am

realitykid wrote:
wei2912 wrote:
Lol, no need to look at my script unless you want to. I'm just posting it in case anyone wants it.


Of course I want to see your script. :p

My only question is, what is the purpose to using sudo on almost every line that requires root privileges? Why can't the users of the script just run the script as root?

Now, if you do want to keep sudo in the script, then at least use gksudo, that way it's easier to use.


The purpose of doing that is for novice users. Most of them know how to run scripts, but maybe don't know what is sudo. They do know that they are administrators (probably) and that they have a password which they can use to do admin work. So by using sudo, the user is asked for his password the 1st time, and the password is no longer needed for the rest of the commands in that terminal. You can try it yourself (the 1st step requires users to open a terminal, get to that directory and run the script. the 2nd step requires the user to click on that script and type in that user's password, which afterwards the script will run without asking for a password till it is closed)

Of course, maybe gksudo is a better choice.
wei2912
Level 2
Level 2
 
Posts: 79
Joined: Thu Jun 02, 2011 1:00 am

Linux Mint is funded by ads and donations.
 

Return to Scripts & Bash

Who is online

Users browsing this forum: No registered users and 2 guests