#!/bin/sh
##
## RJP 19.6.2025 PKG HELPER for making BSD based systems easier to use
# An alternative way to check, install and remove packages
# 5.7.2025 fixed update entry and package selection
##aika=$(date "+%F-%H-%M")
# packages yad, xterm and sh must be installed
# 8.7.2025 Update entry has changed by removing yad message and adding xterm message, because lost network connection causes wrong information
# 10.7.2025 more simple update section
# 12.7.2025 network check added
# 7.8.2025 More options version with category selections
# 

if ! nc -zw1 google.com 443; then 
yad --width=400 --text-align=center --center --title=$"No network connection:" --text="
     No network connection
       
    Add network connection and try again  "
fi

cd /tmp && 
pkg query '%n-%v %C' | sort > kaikki.txt 

echo emptyline > archivers.txt
cat kaikki.txt | grep archivers > archivers0.txt && sed 's/archivers//g' archivers0.txt > archivers00.txt && awk '{print $1}' archivers00.txt >> archivers.txt && rm archivers00.txt archivers0.txt

echo emptyline > audio.txt
cat kaikki.txt | grep audio > audio0.txt && sed 's/audio//g' audio0.txt > audio00.txt && awk '{print $1}' audio00.txt >> audio.txt && rm audio00.txt audio0.txt

echo emptyline > drivers.txt
cat kaikki.txt | grep kld > kld0.txt && sed 's/kld//g' kld0.txt > drivers00.txt && awk '{print $1}' drivers00.txt >> drivers.txt && rm drivers00.txt kld0.txt

echo emptyline > editors.txt
cat kaikki.txt | grep editors > editors0.txt && sed 's/editors//g' editors0.txt > editors00.txt && awk '{print $1}' editors00.txt >> editors.txt && rm editors00.txt editors0.txt

echo emptyline > filesystems.txt
cat kaikki.txt | grep filesystems > filesystems0.txt && sed 's/filesystems//g' filesystems0.txt > filesystems00.txt && awk '{print $1}' filesystems00.txt >> filesystems.txt && rm filesystems00.txt filesystems0.txt

echo emptyline > graphics.txt
cat kaikki.txt | grep graphics > graphics0.txt && sed 's/graphics//g' graphics0.txt > graphics00.txt && awk '{print $1}' graphics00.txt >> graphics.txt && rm graphics00.txt graphics0.txt

echo emptyline > multimedia.txt
cat kaikki.txt | grep multimedia > multimedia0.txt && sed 's/multimedia//g' multimedia0.txt > multimedia00.txt && awk '{print $1}' multimedia00.txt >> multimedia.txt && rm multimedia00.txt multimedia0.txt

echo emptyline > security.txt
cat kaikki.txt | grep security > security0.txt && sed 's/security//g' security0.txt > security00.txt && awk '{print $1}' security00.txt >> security.txt && rm security00.txt security0.txt

echo emptyline > www.txt
cat kaikki.txt | grep www > www0.txt && sed 's/www//g' www0.txt > www00.txt && awk '{print $1}' www00.txt >> www.txt && rm www00.txt rm www0.txt

echo emptyline > x11.txt
cat kaikki.txt | grep x11 > x110.txt && sed 's/x11//g' x110.txt > x1100.txt && awk '{print $1}' x1100.txt >> x11.txt && rm x1100.txt rm x110.txt

echo emptyline > x11-themes.txt
cat kaikki.txt | grep x11-themes > x11-themes0.txt && sed 's/x11-themes//g' x11-themes0.txt > x11-themes00.txt && awk '{print $1}' x11-themes00.txt >> x11-themes.txt && rm x11-themes00.txt x11-themes0.txt

echo emptyline > all.txt
awk '{print $1}' kaikki.txt >> all.txt 

1=$({                                   
echo '#!/bin/sh
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/sh -c "pkg search $PROGRAM && yad --center --borders=5 --width=100 --button=OK:1"
else exit 0
fi '
} > /tmp/status) 

2=$({ 
echo '#!/bin/sh
PROGRAM=`yad --center --width=500 --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/sh -c "sudo pkg install $PROGRAM && yad --center --borders=5 --width=100 --button=OK:1"
yad --center --width=500 --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/sh
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/sh -c "sudo pkg delete $PROGRAM "
yad --center --width=500 --height=100 --text-align=center --text="$PROGRAM is removed or it has not been here"
fi'
} > /tmp/remove)

4=$({ 
echo '#!/bin/sh
LIST=$(pkg info --all )
echo "$LIST" | yad --list --title "Search Results" --width=600 --height=500 --text "INFORMATION" --column "Search Results" --button=OK:1'
} > /tmp/results)

5=$({ 
echo '#!/bin/sh
yad --center --width=400 --height=100 --text-align=center --text="Update your system?"
if [ $? = 0 ];
then
xterm -hold -e /bin/sh -c "sudo pkg update -f && sudo pkg upgrade "

fi'
} > /tmp/update)

6=$({ 
echo '#!/bin/sh
yad  --list --width=700 --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/sh
xterm -e "sudo pkg install $(cat /tmp/install3) " 
sleep 1
yad --center --width=300 --height=100 --text-align=center --title="QUESTION" --text=" 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 '#!/bin/sh
yad  --list --width=700 --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/archivers.txt > /tmp/install2arch \
--print-column=2 --separator= && \
--print --filename=/tmp/install2arch
echo $(cat /tmp/install2arch) > /tmp/install3arch
'
} > /tmp/archivers)

9=$({ 
echo '#!/bin/sh
xterm -e "sudo pkg install $(cat /tmp/install3arch) " 
sleep 1
yad --center --width=300 --height=100 --text-align=center --title="INFORMATION" --text=" 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/archivers-install)

10=$({ 
echo '#!/bin/sh
yad  --list --width=700 --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/audio.txt > /tmp/install2audio \
--print-column=2 --separator= && \
--print --filename=/tmp/install2adio
echo $(cat /tmp/install2audio) > /tmp/install3audio
'
} > /tmp/audio)

11=$({ 
echo '#!/bin/sh
xterm -e "sudo pkg install $(cat /tmp/install3audio) " 
sleep 1
yad --center --width=300 --height=100 --text-align=center --title="INFORMATION" --text=" 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/audio-install)


12=$({ 
echo '#!/bin/sh
yad  --list --width=700 --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/drivers.txt > /tmp/install2drivers \
--print-column=2 --separator= && \
--print --filename=/tmp/install2drivers
echo $(cat /tmp/install2drivers) > /tmp/install3drivers
'
} > /tmp/drivers)

13=$({ 
echo '#!/bin/sh
xterm -e "sudo pkg install $(cat /tmp/install3drivers) " 
sleep 1
yad --center --width=300 --height=100 --text-align=center --title="INFORMATION" --text=" 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/drivers-install)

14=$({ 
echo '#!/bin/sh
yad  --list --width=700 --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/editors.txt > /tmp/install2editors \
--print-column=2 --separator= && \
--print --filename=/tmp/install2editors
echo $(cat /tmp/install2editors) > /tmp/install3editors
'
} > /tmp/editors)

15=$({ 
echo '#!/bin/sh
xterm -e "sudo pkg install $(cat /tmp/install3editors) " 
sleep 1
yad --center --width=300 --height=100 --text-align=center --title="INFORMATION" --text=" 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/editors-install)

16=$({ 
echo '#!/bin/sh
yad  --list --width=700 --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/filesystems.txt > /tmp/install2filesystems \
--print-column=2 --separator= && \
--print --filename=/tmp/install2filesystems
echo $(cat /tmp/install2filesystems) > /tmp/install3filesystems
'
} > /tmp/filesystems)

17=$({ 
echo '#!/bin/sh
xterm -e "sudo pkg install $(cat /tmp/install3filesystems) " 
sleep 1
yad --center --width=300 --height=100 --text-align=center --title="INFORMATION" --text=" 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/filesystems-install)

18=$({ 
echo '#!/bin/sh
yad  --list --width=700 --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/graphics.txt > /tmp/install2graphics \
--print-column=2 --separator= && \
--print --filename=/tmp/install2graphics
echo $(cat /tmp/install2graphics) > /tmp/install3graphics
'
} > /tmp/graphics)

19=$({ 
echo '#!/bin/sh
xterm -e "sudo pkg install $(cat /tmp/install3graphics) " 
sleep 1
yad --center --width=300 --height=100 --text-align=center --title="INFORMATION" --text=" 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/graphics-install)

20=$({ 
echo '#!/bin/sh
yad  --list --width=700 --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/multimedia.txt > /tmp/install2multimedia \
--print-column=2 --separator= && \
--print --filename=/tmp/install2multimedia
echo $(cat /tmp/install2multimedia) > /tmp/install3multimedia
'
} > /tmp/multimedia)

21=$({ 
echo '#!/bin/sh
xterm -e "sudo pkg install $(cat /tmp/install3multimedia) " 
sleep 1
yad --center --width=300 --height=100 --text-align=center --title="INFORMATION" --text=" 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/multimedia-install)

22=$({ 
echo '#!/bin/sh
yad  --list --width=700 --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/security.txt > /tmp/install2security \
--print-column=2 --separator= && \
--print --filename=/tmp/install2security
echo $(cat /tmp/install2security) > /tmp/install3security
'
} > /tmp/security)

23=$({ 
echo '#!/bin/sh
xterm -e "sudo pkg install $(cat /tmp/install3security) " 
sleep 1
yad --center --width=300 --height=100 --text-align=center --title="INFORMATION" --text=" 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/security-install)

24=$({ 
echo '#!/bin/sh
yad  --list --width=700 --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/www.txt > /tmp/install2www \
--print-column=2 --separator= && \
--print --filename=/tmp/install2www
echo $(cat /tmp/install2www) > /tmp/install3www
'
} > /tmp/www)

25=$({ 
echo '#!/bin/sh
xterm -e "sudo pkg install $(cat /tmp/install3www) " 
sleep 1
yad --center --width=300 --height=100 --text-align=center --title="INFORMATION" --text=" 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/www-install)

26=$({ 
echo '#!/bin/sh
yad  --list --width=700 --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/x11.txt > /tmp/install2x11 \
--print-column=2 --separator= && \
--print --filename=/tmp/install2x11
echo $(cat /tmp/install2x11) > /tmp/install3x11
'
} > /tmp/x11)

27=$({ 
echo '#!/bin/sh
xterm -e "sudo pkg install $(cat /tmp/install3x11) " 
sleep 1
yad --center --width=300 --height=100 --text-align=center --title="INFORMATION" --text=" 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/x11-install)

28=$({ 
echo '#!/bin/sh
yad  --list --width=700 --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/x11-themes.txt > /tmp/install2x11-themes \
--print-column=2 --separator= && \
--print --filename=/tmp/install2x11-themes
echo $(cat /tmp/install2x11-themes) > /tmp/install3x11-themes
'
} > /tmp/x11-themes)

29=$({ 
echo '#!/bin/sh
xterm -e "sudo pkg install $(cat /tmp/install3x11-themes) " 
sleep 1
yad --center --width=300 --height=100 --text-align=center --title="INFORMATION" --text=" 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/x11-themes-install)

30=$({ 
echo '#!/bin/sh
yad  --list --width=700 --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/install2all \
--print-column=2 --separator= && \
--print --filename=/tmp/install2all
echo $(cat /tmp/install2all) > /tmp/install3all
'
} > /tmp/all)

31=$({ 
echo '#!/bin/sh
xterm -e "sudo pkg install $(cat /tmp/install3all) " 
sleep 1
yad --center --width=300 --height=100 --text-align=center --title="INFORMATION" --text=" 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/all-install)


999=$({ 
echo 'This is a graphical script or program, which can help to manage BSD system packages. Free to use and modify. Copyright RJP@2025. More info from https://puolanka.info/goto/freebsd-pkg-helper-for-managing-packages/.
'
} > /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



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/archivers-install
chmod +x /tmp/archivers
chmod +x /tmp/audio-install
chmod +x /tmp/audio
chmod +x /tmp/drivers-install
chmod +x /tmp/drivers
chmod +x /tmp/editors-install
chmod +x /tmp/editors
chmod +x /tmp/filesystems-install
chmod +x /tmp/filesystems
chmod +x /tmp/graphics-install
chmod +x /tmp/graphics
chmod +x /tmp/multimedia-install
chmod +x /tmp/multimedia
chmod +x /tmp/security-install
chmod +x /tmp/security
chmod +x /tmp/www-install
chmod +x /tmp/www
chmod +x /tmp/www-install
chmod +x /tmp/www
chmod +x /tmp/x11-install
chmod +x /tmp/x11
chmod +x /tmp/x11-install
chmod +x /tmp/x11
chmod +x /tmp/x11-themes-install
chmod +x /tmp/x11-themes
chmod +x /tmp/all-install
chmod +x /tmp/all

#!/bin/sh
yad --form --columns=2 --scroll --rows=10 --width=900 --height=600 --title="PKG HELPER PLUS" --text=" PKG HELPER PLUS:" \
\
--field="Selection for ARCHIVE package installation":fbtn "/tmp/./archivers " \
--field="Selection for AUDIO package installation":fbtn "/tmp/./audio " \
--field="Selection for DRIVER package installation":fbtn "/tmp/./drivers " \
--field="Selection for EDITOR package installation":fbtn "/tmp/./editors " \
--field="Selection for FILESYSTEM package installation":fbtn "/tmp/./filesystems " \
--field="Selection for GRAPHICK package installation":fbtn "/tmp/./graphics " \
--field="Selection for MULTIMEDIA package installation":fbtn "/tmp/./multimedia " \
--field="Selection for SECURITY package installation":fbtn "/tmp/./security " \
--field="Selection for WWW package installation":fbtn "/tmp/./www " \
--field="Selection for x11-THEME package installation":fbtn "/tmp/./x11-themes " \
--field="Selection for x11 PACKAGE installation":fbtn "/tmp/./x11 " \
--field="Selection for ALL packages installation":fbtn "/tmp/./all " \
--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="Autoremove packages":fbtn "xterm -e sh -c 'sudo pkg autoremove ; exec sh' & " \
--field="installed packages ":fbtn "/tmp/./results " \
--field="Install selected ARCHIVE packages":fbtn "/tmp/./archivers-install " \
--field="Install selected AUDIO packages":fbtn "/tmp/./audio-install " \
--field="Install selected DRIVER packages":fbtn "/tmp/./drivers-install " \
--field="Install selected EDITOR packages":fbtn "/tmp/./editors-install " \
--field="Install selected FILESYSTEM packages":fbtn "/tmp/./filesystems-install " \
--field="Install selected GRAPHICK packages":fbtn "/tmp/./graphics-install " \
--field="Install selected MULTIMEDIA packages":fbtn "/tmp/./multimedia-install " \
--field="Install selected SECURITY packages":fbtn "/tmp/./security-install " \
--field="Install selected WWW packages":fbtn "/tmp/./www-install " \
--field="Install selected x11-THEME packages":fbtn "/tmp/./x11-themes-install " \
--field="Install selected x11 PACKAGE":fbtn "/tmp/./x11-install " \
--field="Install selected ALL packages":fbtn "/tmp/./all-install " \
--field="User installed packages":fbtn "xterm -e sh -c 'pkg prime-list ; exec sh' & " \
--field="Package stats":fbtn "xterm -e sh -c 'pkg stats; exec sh' & " \
--field="clear package cache":fbtn "xterm -e sh -c 'sudo pkg clean; exec sh' & " \
--field="Auditing Installed":fbtn "xterm -e sh -c 'sudo pkg audit -F; exec sh' & " \
--field="clear full package cache":fbtn "xterm -e sh -c 'sudo pkg clean -a ; exec sh' & " \
--field="README":fbtn "sh -c 'xdg-open /tmp/readme.txt ; exec sh' & " \
--button=Exit:1

cd /tmp && rm all all.txt audio.txt all-install archivers archivers-install archivers.txt audio audio-install drivers drivers-install drivers.txt editors editors-install editors.txt filesystems filesystems-install filesystems.txt graphics graphics-install graphics.txt install2all install2arch install2audio install2drivers install2x11 install2x11-themes install3all install3arch install3audio install3drivers install3x11 install3x11-themes kaikki.txt multimedia multimedia-install multimedia.txt readme.txt security security-install security.txt www www-install www.txt x11 x11-install x11-themes x11-themes-install x11-themes.txt x11.txt packages remove results install status update multi

