#!/bin/bash
##
## RJP 30.4.2025 PACMAN HELPER for making ARCH based systems easier to use
# An alternative way to check, install and remove packages
# Made in Artix Linux with base repos, so if using extra repos, code may need to change

##aika=$(date "+%F-%H-%M")
1=$({                                   
echo '#!/bin/bash
PROGRAM=`yad --center --width=500 --height=100 --text-align=center --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
xterm -hold -e /bin/bash -c "pacman -Si $PROGRAM && yad --center --borders=5 --width=100 --button=OK:1"
else exit 0
fi '
} > /tmp/status) 

2=$({ 
echo '#!/bin/bash
PROGRAM=`yad --center --width=700 --height=100 --text-align=center --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 /bin/bash -c "sudo pacman -Syu $PROGRAM && yad --center --borders=5 --width=100 --button=OK:1"
yad --center --width=700 --height=100 --text-align=center --text="$PROGRAM is installed or if script died without OK, there has no that program as $PROGRAM "
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" --entry --entry-label=is --entry-text=""`
if [ $? = 0 ];
then
xterm -e /bin/bash -c "sudo pacman -Rs $PROGRAM "
yad --center --width=700 --height=100 --text-align=center --text="$PROGRAM is removed or it has not been here"
fi'
} > /tmp/remove)

4=$({ 
echo '#!/bin/bash
LIST=$(pacman -Qqe )
echo "$LIST" | yad --list --title "Search Results" --width=400 --height=500 --text "INFORMATION" --column "Search Results" --button=OK:1'
} > /tmp/results)

5=$({ 
echo '#!/bin/bash
yad --center --width=400 --height=100 --text-align=center --text="Update your system?"
if [ $? = 0 ];
then
xterm -e /bin/bash -c "sudo pacman -Fy && sudo pacman -Syu && sleep 3"
yad --center --width=400 --height=100 --text-align=center --text="System Upgraded"
fi'
} > /tmp/update)

6=$({ 
echo '#!/bin/bash
yad  --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/all.txt > /tmp/install2 \
--print-column=2 --separator= && \
--print --filename=/tmp/install2
echo $(cat /tmp/install2) > /tmp/install3
'
} > /tmp/packages)

7=$({ 
echo '#!/bin/bash
xterm -e "sudo pacman -Syu $(cat /tmp/install3) " 
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)

8=$({ 
echo 'If removing pacman cache or corrupted datdabase, after that must run "Install Updates" and then re-open PACMAM_HELPER so that database is on and then can use different functions like install programs, etc.
'
} > /tmp/readme.txt)

touch ~/.Xresources 

echo ' ! Use a truetype font and size. 
xterm*faceName: Monospace ' | grep -xFv -f $HOME/.Xresources >> $HOME/.Xresources

echo 'xterm*faceSize: 14 ' | grep -xFv -f $HOME/.Xresources >> $HOME/.Xresources

xrdb -merge ~/.Xresources

pacman -Ss '.' > /tmp/all.txt

sed -i 's/galaxy//g' /tmp/all.txt

sed -i 's/world//g' /tmp/all.txt

sed -i 's/system//g' /tmp/all.txt

sed -i 's/^.//' /tmp/all.txt

awk 'ORS=NR%2?FS:RS' /tmp/all.txt > /tmp/all0.txt

awk '{print $1}' /tmp/all0.txt > /tmp/all.txt

chmod +x /tmp/status
chmod +x /tmp/install
chmod +x /tmp/remove
chmod +x /tmp/results
chmod +x /tmp/update
chmod +x /tmp/available
chmod +x /tmp/packages
chmod +x /tmp/multi

#!/bin/bash
yad --form --columns=4 --rows=6 --width=1000 --title="PACMAN HELPER" --text=" PACKMAN 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="List orphan packages":fbtn "xterm -e bash -c 'pacman -Qtd ; exec bash' & " \
--field="List Audio packages":fbtn " bash -c 'pacman -Ss 'audio' > /tmp/audio.txt && xdg-open /tmp/audio.txt ; exec bash' & " \
--field="List Browser packages":fbtn " bash -c 'pacman -Ss 'browser' > /tmp/browser.txt && xdg-open /tmp/browser.txt ; exec bash' & " \
--field="List Media packages":fbtn " bash -c 'pacman -Ss 'media' > /tmp/media.txt && xdg-open /tmp/media.txt ; exec bash' & " \
--field="List Office packages":fbtn " bash -c 'pacman -Ss 'office' > /tmp/office.txt && xdg-open /tmp/office.txt ; exec bash' & " \
--field="List Picture packages":fbtn " bash -c 'pacman -Ss 'picture' > /tmp/picture.txt && xdg-open /tmp/picture.txt ; exec bash' & " \
--field="List Video packages":fbtn " bash -c 'pacman -Ss 'video' > /tmp/video.txt && xdg-open /tmp/video.txt ; exec bash' & " \
--field="List System packages":fbtn " bash -c 'pacman -Ss 'system' > /tmp/system.txt && xdg-open /tmp/system.txt ; exec bash' & " \
--field="List All packages":fbtn " bash -c 'pacman -Ss '.' > /tmp/all0.txt && xdg-open /tmp/all0.txt ; exec bash' & " \
--field="installed packages ":fbtn "/tmp/./results " \
--field="Selection for package installation":fbtn "/tmp/./packages " \
--field="Install selected packages":fbtn "/tmp/./multi " \
--field="Update history":fbtn "xterm -e bash -c 'grep -i upgraded /var/log/pacman.log; exec bash' & " \
--field="Install history":fbtn "xterm -e bash -c 'grep "install" /var/log/pacman.log; exec bash' & " \
--field="clear pacman cache":fbtn "xterm -e bash -c 'sudo pacman -Scc; exec bash' & " \
--field="re-fresh pacman":fbtn "xterm -e bash -c 'sudo pacman -Fy; exec bash' & " \
--field="remove corrupted pacman cache":fbtn "xterm -e bash -c 'sudo rm /var/lib/pacman/sync/* ; exec bash' & " \
--field="remove pacman db lock":fbtn "xterm -e bash -c 'sudo rm /var/lib/pacman/db.lck; exec bash' & " \
--field="README":fbtn "bash -c 'xdg-open /tmp/readme.txt ; exec bash' & " \
--button=Exit:1

cd /tmp && rm status install remove results update available packages multi all.txt all0.txt audio.txt browser.txt office.txt picture.txt media.txt system.txt video.txt install2 install3
