#!/bin/bash
##
## RJP 12.4.2024
# An alternative way to check, install and remove packages
# 13.4.2024 Added rpm history, active repos and all repos
# 15.4.2024 Added auto oprhans section
# 22.7.2026 edited dialogs

1=$({                                   
echo '#!/bin/bash
PROGRAM=`yad --center --width=500 --height=100 --text-align=center --title="Program status" --text="You can check program status by writing program name to text box and pressing then ok" --entry --entry-label=NAME --entry-text=""`
if [ $? = 0 ];
then
rpm -q  $PROGRAM  > /\tmp/\status.txt
urpmq -i $PROGRAM >> /\tmp/\status.txt
sleep 1
xdg-open /\tmp/\status.txt
else exit 0
fi '
} > /tmp/status)


2=$({ 
echo '#!/bin/bash
PROGRAM=`yad --center --width=700 --height=100 --text-align=center --title="Program install" --text="Program you want to install. If there has no that program, script ends" --entry --entry-label=SEARCH --entry-text=""`
if [ $? = 0 ];
then
xterm -e su -c "'urpmi '$PROGRAM''" root
yad --center --width=700 --height=100 --text-align=center --text="$PROGRAM is installed or it has not been here" --title="DONE"
else exit 0
fi '
} > /tmp/install) 


3=$({ 
echo '#!/bin/bash
PROGRAM=`yad --center --width=500 --height=100 --text-align=center --text="Program you want to remove" --title="Program remove" --entry --entry-label=is --entry-text=""`
if [ $? = 0 ];
then
xterm -e su -c "'urpme '$PROGRAM''" root
yad --center --width=700 --height=100 --text-align=center --text="$PROGRAM is removed or it has not been here" --title="DONE"
fi'
} > /tmp/remove)


4=$({ 
echo '#!/bin/bash
yad --center --width=400 --height=100 --text-align=center --text="$Update your system?" --title="Update your system?"
if [ $? = 0 ];
then
xterm -e su -c "'urpmi --auto-update'" root 
yad --center --width=400 --height=100 --text-align=center --text="System Upgraded" --title="System Upgraded"
fi'
} > /tmp/update)

5=$({ 
echo '#!/bin/bash
yad --title="Selection for package installation" --list --width=800 --height=500 --checklist \
--button="Select programs and then run Install selected packages from the main menu":0 --button=Exit:1 \
--column="Select for installation" \
--column=Package < /tmp/list > /tmp/install2 \
--print-column=2 --separator= && \
--print --filename=/tmp/install2
echo $(cat /tmp/install2) > /tmp/install3
'
} > /tmp/packages)

6=$({ 
echo '#!/bin/bash
xterm -e su -c "'urpmi '$(cat /tmp/install3)' '"root
sleep 1
xterm -e /bin/bash -c "read -p \"If some package was not available or it was installed already, so the script died from that reason. Otherwise you saw terminal windows who told you the installation process. You can close this window\"" 
'
} > /tmp/multi)

7=$({                                   
echo '#!/bin/bash
##time=$(date "+%F-%H-%M-%S")
RPMLIST=$(rpm -qa --last > /tmp/Update_history.txt)
sleep 5
cat /tmp/Update_history.txt | yad --list --title "Search Results" --width=1000 --height=500 --text "INFORMATION" --column "Search Results" --button=OK:1
'
} > /tmp/history) 

8=$({                                   
echo '#!/bin/bash
##time=$(date "+%F-%H-%M-%S")
REPOS=$(urpmq --list-media active > /tmp/activerepos.txt)
sleep 5
cat /tmp/activerepos.txt | yad --list --title "Search Results" --width=1000 --height=500 --text "INFORMATION" --column "Active repos" --button=OK:1
'
} > /tmp/repos) 

9=$({                                   
echo '#!/bin/bash
##time=$(date "+%F-%H-%M-%S")
REPOS=$(urpmq --list-url > /tmp/allrepos.txt)
sleep 5
cat /tmp/allrepos.txt | yad --list --title "Search Results" --width=1000 --height=500 --text "INFORMATION" --column "All repos" --button=OK:1
'
} > /tmp/allrepos)

10=$({ 
echo '#!/bin/bash
yad --center --width=400 --height=100 --text-align=center --text="Remove Orphan packages?" --title="Remove Orphan packages"
if [ $? = 0 ];
then
xterm -e su -c "'urpme --auto-orphans'" root 
yad --center --width=400 --height=100 --text-align=center --button="OK:0" --text="Orphans removed" --title="Orphans removed"
fi'
} > /tmp/orphans)

11=$({ 
echo 'false
chromium-browser
false
gimp
false
caja
false
pluma
false
atril
false
eom
false
engrampa
false
mate-terminal
false
caja-open-terminal
false
mate-utils
false
xterm
false
vlc
false
mpv
false
smplayer
false
audacious
false
audacity
false
sox
false
fbreader
false
galculator
false
gnome-alsamixer
false
harddrake
false
cinnamon-desktop
false
claws-mail
false
connman
false
converseen
false
rpmdrake
false
k3b
false
pdfarranger
false
geany
false
thunderbird
false
gftp
false
dillo
false
otter-browser
false
t-lasku
false
tilitin
false
xsane
false
scribus
false
redshift
false
grsync'
} > /tmp/list)

chmod +x /tmp/status
chmod +x /tmp/install
chmod +x /tmp/remove
chmod +x /tmp/update
chmod +x /tmp/packages
chmod +x /tmp/multi
chmod +x /tmp/history
chmod +x /tmp/repos
chmod +x /tmp/allrepos
chmod +x /tmp/orphans


#!/bin/bash
yad --form --columns=3 --rows=4 --width=1000 --text-align=center --title="URPMI PACKAGE HELPER" --text="URPMI PACKAGE HELPER:" \
\
--field="Program Status Checker":fbtn "/tmp/./status " \
--field="Program Installer":fbtn "/tmp/./install " \
--field="Program Remover":fbtn "/tmp/./remove " \
--field="Install Updates":fbtn "/tmp/./update " \
--field="Selection for package installation":fbtn "/tmp/./packages " \
--field="Install selected packages":fbtn "/tmp/./multi " \
--field="RPM history (this takes time)":fbtn "/tmp/./history " \
--field="Active repos (this takes time)":fbtn "/tmp/./repos " \
--field="Available repos (this takes time)":fbtn "/tmp/./allrepos " \
--field="Remove orphan packages":fbtn "/tmp/./orphans " \
--button=Exit:1
