Thanks to: Neal for all the help and icon, Leiche for the help and the progress bar, and any one who worked on the getvirtualbox script it was very helpful.I decided to make this script because I remember when I first used Linux I hated rebuilding the database.
The script rebuilds and cleans the repository database according to Texstars requirements:
http://www.pclinuxos.com/forum/index.php/topic,80839.0.htmlREQUIRES YAD Available in Synaptic
Below are all the resource to make this yourself.
repair-database (shell script) - /usr/bin
repair-database.desktop - /usr/share/applications
dbrepair.png - /usr/share/icons
yad versionUpdated as of 09/05/2011, this will be the final version unless new advances are made with the cancel button. -Thank You
#!/bin/sh
#This is a script to rebuild repos in PClinuxOS.
#This script has been converted from zenity to yad.
#Special thanks to: Neal for all the help and icon, Leiche for the help and the progress bar, and any one who worked on the getvirtualbox script it was very helpful.
#By glamdring
# variables
#==========
WICON='/usr/share/icons/dbrepair.png' && TITLE="Repair Database"
XURD='/tmp/xsurepair-database'
RXURD="/bin/rm -f $XURD"
ZEN2="yad --window-icon=$WICON"
TITLE="Repair Database"
REMOVE="rm -rf /var/lib/rpm/__db*"
REBUILD="rpm --rebuilddb"
CLEANAPT="apt-get clean"
CLEANAPT2="apt-get autoclean"
#export
#======
export TEXTDOMAIN=repair-database
export TEXTDOMAINDIR="/usr/share/locale"
#clear xurd
#==========
#$RXURD
# Check if xterm can be used
#===========================
/bin/rm -f /tmp/checkxterm.txt && XOK=0
xterm -u8 -iconic -e touch /tmp/checkxterm.txt
if [ -e /tmp/checkxterm.txt ];then XOK="1";fi
/bin/rm -f /tmp/checkxterm.txt
# check if we run a pclos kernel
#===============================
if [ -z "`uname -r |grep pclos`" ]; then
MSG="Repair Database requires a 'pclos'-kernel.\n\nExiting."
$ZEN2 --form --text="$MSG" --button="gtk-ok:0"
exit 0
fi
#login as super user
#===================
if [ ! -e $XURD ];then
if [ -r /usr/bin/gksu ]; then LGI="/usr/bin/gksu"; fi
if [ -r /usr/lib/kde4/libexec/kdesu ]; then LGI="/usr/lib/kde4/libexec/kdesu"; fi
if [ -r /usr/bin/kdesu ]; then LGI="/usr/bin/kdesu"; fi
# setup XURD
echo "#"'!/bin/bash' > $XURD
if [ "$UID" != "0" ]; then echo $LGI repair-database >> $XURD; else echo repair-database >> $XURD; fi
chmod a+x $XURD
$XURD &
exit 0
fi
#test for super user privliges
#=============================
if [ "$UID" != "0" ]; then
$ZEN2 --form --title="$TITLE" --notification --text=$" Please run this script as root. \n If this is the first time you have seen this please hit retry." \
--button="Retry:1" --button="gtk-close:2" echo $?
if [ "$?" == "1" ]; then
if [ -r /tmp/xsurepair-database ]; then $RXURD; fi
"/usr/bin/repair-database";
fi
exit 0
fi
# check internet connection
#==========================
cd /tmp
/bin/rm -f index.html inet.log
MSG="Testing your Internet connection."
( wget --timeout=15 http://www.google.com/index.html -o inet.log ) 2>&1 | $ZEN2 --title="$TITLE" --progress --text "$MSG" --pulsate --auto-close
if [ ! -f /tmp/index.html ]; then
MSG="No Internet connection found.\n\nExiting."
$ZEN2 --form --text "$MSG" --button="gtk-ok:1"
$RXURD
exit 1
fi
#repair database?
#================
MSG="Do you want to repair the Synaptic databse?"
MSG2="No changes were made to your system."
$ZEN2 --form --title="$TITLE" --text="$MSG" --button="gtk-yes:0" --button="gtk-no:1" --sticky --fixed ret=$?
if [ "$?" = "1" ]; then
$ZEN2 --title="$TITLE" --form --notification --text="$MSG2" --button="gtk-close:0" --sticky --fixed --on-top
$RXURD
exit 0
fi
#remove corrupted database
#==========================
rm -rf /var/lib/rpm/__db*
#rebuild rpm database
#=====================
MSG="Rebuilding database, This can take some time please let it finish."
MSG2="You chose to exit. The database was not repaired!"
(echo && $REBUILD) | $ZEN2 --title="$TITLE" --text="$MSG" --progress --pulsate --auto-close --auto-kill --button="gtk-cancel:1" --sticky --fixed ret=$?
if [ "$?" = "1" ]; then
$ZEN2 --title="$TITLE" --form --notification --text="$MSG2" --button="gtk-close:0" --sticky --fixed --on-top --center
$RXURD
exit 0
fi
#check for duplicate installed package
#=====================================
dupeclean
#clean out apt
#=============
$CLEANAPT
MSG="Cleaning database, please be patient."
MSG2="You chose to exit. The database was not cleaned!"
(echo && $CLEANAPT2) | $ZEN2 --progress --pulsate --auto-close --auto-close --title="$TITLE" --text="$MSG" --button="gtk-cancel:1" --sticky --fixed --center ret=$?
if [ "$?" = "1" ]; then
$ZEN2 --title="$TITLE" --form --notification --text="$MSG2" --button="gtk-close:0" --sticky --fixed --on-top --center
$RXURD
exit 0
fi
#exit
#====
MSG="Synaptic RPM database successfully repaired."
$ZEN2 --title="$TITLE" --form --notification --text="$MSG" --button="gtk-close:0" --sticky --fixed --on-top --center
$RXURD
exit 0
The icon:

The .desktop file
[Desktop Entry]
Version=0.1
Type=Application
Name=Repair Database
Exec=repair-database
Icon=dbrepair.png
Comment=Repair Database
Categories=RepairDatabase;System;X-MandrivaLinux-System-Configuration;X-MandrivaLinux-System-Configuration-Packaging;
Terminal=false
Encoding=UTF-8
StartupNotify=true
zenity versionPlease be aware that this version is not updated and is considered obsolete.#!/bin/sh
#This is a script to rebuild repos in PClinuxOS.
# variables
#==========
WICON='/usr/share/icons/dbrepair.png' && TITLE="Repair Database"
XURD='/tmp/xsurepair-database'
RXURD="/bin/rm -f $XURD"
ZEN2="zenity --window-icon=$WICON"
TITLE="Repair Database"
REMOVE="rm -rf /var/lib/rpm/__db*"
REBUILD="rpm --rebuilddb"
CLEANAPT="apt-get clean"
CLEANAPT2="apt-get autoclean"
#export
#======
export TEXTDOMAIN=repair-database
export TEXTDOMAINDIR="/usr/share/locale"
# Check if xterm can be used
#===========================
/bin/rm -f /tmp/checkxterm.txt && XOK=0
xterm -u8 -iconic -e touch /tmp/checkxterm.txt
if [ -e /tmp/checkxterm.txt ];then XOK="1";fi
/bin/rm -f /tmp/checkxterm.txt
# check if we run a pclos kernel
#===============================
if [ -z "`uname -r |grep pclos`" ]; then
MSG=$"Repair Database requires a 'pclos'-kernel.\n\nExiting."
$ZEN2 --error --text "$MSG"
$RXURD
exit 0
fi
#login as super user
#===================
if [ ! -e $XURD ];then
if [ -r /usr/bin/gksu ]; then LGI=/usr/bin/gksu; fi
if [ -r /usr/lib/kde4/libexec/kdesu ]; then LGI=/usr/lib/kde4/libexec/kdesu; fi
if [ -r /usr/bin/kdesu ]; then LGI=/usr/bin/kdesu; fi
# setup XURD
echo "#"'!/bin/bash' > $XURD
if [ "$UID" != "0" ]; then echo $LGI repair-database >> $XURD; else echo repair-database >> $XURD; fi
chmod a+x $XURD
$XURD &
exit 0
fi
#test for super user privliges
#=============================
if [ "$UID" != "0" ]; then
$ZEN2 --error --text=$"Please run this script as root."
$RXURD
exit 1
fi
# check internet connection
#==========================
cd /tmp
/bin/rm -f index.html inet.log
MSG=$"Testing your Internet connection."
( wget --timeout=15 http://www.google.com/index.html -o inet.log ) 2>&1 | $ZEN2 --title="$TITLE" --progress --text "$MSG" --pulsate --auto-close
if [ ! -f /tmp/index.html ]; then
MSG=$"No Internet connection found.\n\nExiting."
$ZEN2 --error --text "$MSG"
$RXURD
exit 1
fi
#repair database?
#================
MSG="Do you want to repair the repository databse?"
MSG2="No changes were made to your system."
zenity --question --title="$TITLE" --text="$MSG" echo $?
if [ "$?" = "1" ]; then
$ZEN2 --info --width=250 --title="$TITLE" --text="$MSG2"
$RXURD
exit 0
fi
#remove corrupted database
#==========================
rm -rf /var/lib/rpm/__db*
#rebuild rpm database
#=====================
MSG=$"Rebuilding database, This can take some time please let it finish."
MSG2=$"You chose to exit. The database was not repaired!"
(echo && $REBUILD) | $ZEN2 --progress --pulsate --width 350 --auto-close --auto-kill --title="$TITLE" --text "$MSG" echo $?
if [ "$?" = "1" ]; then
$ZEN2 --warning --width=250 --title="$TITLE" --text="$MSG2"
$RXURD
exit 0
fi
#check for duplicate installed package
#=====================================
dupeclean
#clean out apt
#=============
$CLEANAPT
MSG=$"Cleaning database."
MSG2=$"You chose to exit. The database was not cleaned!"
(echo && $CLEANAPT2) | $ZEN2 --progress --pulsate --width 350 --auto-close --auto-kill --title="$TITLE" --text "$MSG" echo $?
if [ "$?" = "1" ]; then
$ZEN2 --warning --width=350 --title="$TITLE" --text="$MSG2"
$RXURD
exit 0
fi
#exit
#====
MSG=$"Database successfully repaired."
$ZEN2 --info --width=350 --title="$TITLE" --text="$MSG"
$RXURD
exit 0
Thanks to: Neal for all the help and icon, blindschLeiche for the progress bar, and any one who worked on the getvirtualbox script it was very helpful.
Added
WICON - window icon:
01/12/2011XURD - /tmp/xsurepair-database
RXURD - removes XURD
Added --title to ZEN2export - textdomain/textdomaindir
check xterm
check kernel
messages after hitting cancel/finished
new yad version:
01/13/2011retry button for check super user (67):
01/14/2011Updated: 01/12/2011
'' marks on /tmp/xsurepair-database
Shortened the rebuild database(102) now matches cleaning database (120)
added missing $ in rebuilding database(101,6)
--title removed from ZEN2
Problems: 09/05/2011Cancel button on rebuilding database finshes current operation before stopping.
Original post:
I finished my first zenity script and I bet I'm going to get a bunch comments on what I did wrong haha. But that is good it will help me learn.
I decided to make this script because I remember when I first used Linux I hated rebuilding the database.
The script rebuilds and cleans the repository database according to Texstars requirements:
http://www.pclinuxos.com/forum/index.php/topic,80839.0.html