Just made this script: UPS

Non release banter
User avatar
brokenman
Site Admin
Site Admin
Posts: 6105
Joined: 27 Dec 2010, 03:50
Distribution: Porteus v4 all desktops
Location: Brazil

Re: Just made this script: UPS

Post#16 by brokenman » 06 Oct 2016, 01:36

The initial line of a script is always the interpreter directive. It should be like this for bash scripts in Porteus.

#!/bin/bash

or

#!/bin/sh
How do i become super user?
Wear your underpants on the outside and put on a cape.

User avatar
Ed_P
Contributor
Contributor
Posts: 8343
Joined: 06 Feb 2013, 22:12
Distribution: Cinnamon 5.01 ISO
Location: Western NY, USA

Re: Just made this script: UPS

Post#17 by Ed_P » 06 Oct 2016, 04:13

normalGuy wrote: but if you put the url after:

Code: Select all

#! /bin/bash
#https://forum.porteus.org/viewtopic.php?f=48&t=6258&p=49194#p49194
it works with me.
For me too. :Yahoo!:
brokenman wrote:The initial line of a script is always the interpreter directive. It should be like this for bash scripts in Porteus.

#!/bin/bash

or

#!/bin/sh
I would have thought a comment line, ie a line starting with a #, wouldn't have mattered. :pardon: Learned something new. :good:

:beer:
Ed

User avatar
brokenman
Site Admin
Site Admin
Posts: 6105
Joined: 27 Dec 2010, 03:50
Distribution: Porteus v4 all desktops
Location: Brazil

Re: Just made this script: UPS

Post#18 by brokenman » 07 Oct 2016, 02:02

I would have thought a comment line, ie a line starting with a #, wouldn't have mattered.

The # of the first line isn't a comment. It's to tell the interpreter which language the script is written in. It's called a 'shebang'.
How do i become super user?
Wear your underpants on the outside and put on a cape.

User avatar
normalGuy
Black ninja
Black ninja
Posts: 52
Joined: 06 Nov 2015, 23:36
Distribution: porteus 3.2 xfce archBang
Location: uk & portugal

Re: Just made this script: UPS

Post#19 by normalGuy » 09 Oct 2016, 21:14

Hello again!

zups.sh - ups with zenity.

Auto-Upload every new-script: brokenman comment thanks.
Needs to work:
- zenity.xzm by usm
- location of the sripts: /opt/porteus-scripts/
- Structure of the name: update-this update-that

zups.sh:
https://drive.google.com/file/d/0BxLsS7 ... sp=sharing

New version: 15 Oct 2016

Code: Select all

#!/bin/bash
#-----------------------------------------------------------------------
# Upate by Porteus Scripts - gui/zenity version (zups.sh)
# By normalGuy (ptrin)
# Date: Oct 9th, 2016
#-----------------------------------------------------------------------

## Porteus functions - thanks to Brokenman porteus linux ##

. /usr/share/porteus/porteus-functions
. /usr/share/porteus/gtkdialog-functions

zty=`command -pv zenity`
if [ "$?" = "0" ]
then
is_root || { gksu $0; exit; }
else 
gtk_message1 "=> Zenity does not exist...install with USM" 
gksu usmgui
exit 0
fi


# Selecting app names to updatelist ------------------------------------
ulist=$(ls -1 /opt/porteus-scripts/update-* | awk -F/ '!/update-module/{print$NF}' | awk -F/ '!/update-porteus/{print$NF}' > /tmp/zups1
cat /tmp/zups1)

# Selecting app names to radiolist -------------------------------------
rlst=$(cat /tmp/zups1 | sed -e 's/update-//' -e 's/^/FALSE /' > /tmp/zups2
cat /tmp/zups2)

# Selecting app single names to list -----------------------------------
slst=$(cat /tmp/zups1 | sed -e 's/update-//' > /tmp/zups3
cat /tmp/zups3)
    
# Status to the final list----------------------------------------------------
for app in $slst; do 
(if ls /var/log/packages | grep $app; then
         echo "Installed"
         else
         echo "not_Installed"
        fi); done > /tmp/z3
        
sed '/Installed/!d' /tmp/z3 > /tmp/z9        # Only Installed info line
cat /tmp/zups1 | sed -e 's/update-//' -e 's/^/FALSE /' > /tmp/z4 
paste /tmp/z4  /tmp/z9 > /tmp/z6            # Add status to third column
flst=$(cat /tmp/z6)


# Read lines (app name to install) to update-command ------------------------------
zups_install(){
    ap2i=$(cat /tmp/zzz) 
    if [ -z != "$ap2i" ]; then
      if (zenity --question --title="$Title" --width=295 --ok-label="Yes" --cancel-label="No" \
                  --text '<span foreground="#008080" font="12">Update <b>'$ap2i'</b></span>') ; then   
           uxterm -bg black -fg orange -geometry 75x20 -title "update-$ap2i" -e 'bash -c "/opt/porteus-scripts/update-'$ap2i'; echo Enter to Close Terminal; read line"'
           return
       fi
    fi
}

# Zenity Main ----------------------------------------------------------

zups_menu(){
    Title="Updating by Porteus Scripts"
    subTxt="Select an app to <b>Install / Update</b>
Check <span color=\"blue\"><b>USM</b></span>"

main=$(zenity --list  --radiolist --width=340 --height=490 --text="$subTxt" \
             --title="$Title" --column " ✔ " --column "Application"  --column "Status" --ok-label="Install" \ $flst)
             
# Buttons --------------------------------------------------------
    bex="$?"                    # Cancel
    if [[ "$bex" != "0" ]]
    then
    rm -rf /tmp/{zups1,zups2,zups3,zzz}
    rm -rf /tmp/{z3,z6,z9,z4}
    exit 0
    elif [[ -z "$main" ]]       # Install without a choose
          then
             zenity --info --width=250 --text '<span foreground="#008080" font="12">Please <b>select</b> something</span>'
             zups_menu
    fi
       
# Install app ----------------------------------------------------------   

      echo $main | grep '[a-zA-Z0-9]' > /tmp/zzz # If anything is selected
      if [ $? = 0 ];then
      zups_install && zups_menu
      fi
     
}
## main
zups_menu
Last edited by normalGuy on 15 Oct 2016, 11:46, edited 4 times in total.

User avatar
Ed_P
Contributor
Contributor
Posts: 8343
Joined: 06 Feb 2013, 22:12
Distribution: Cinnamon 5.01 ISO
Location: Western NY, USA

Re: Just made this script: UPS

Post#20 by Ed_P » 11 Oct 2016, 01:53

normalGuy wrote:Hello again!
zups.sh - ups with zenity.
Auto-Upload every new-script: brokenman comment thanks.
Needs to work:
- zenity.xzm by usm
- location of the sripts: /opt/porteus-scripts/
- Structure of the name: update-this update-that
Bugs / my errors:
- root with gksu it needs to be cancel twice to exit...

Code: Select all

guest@porteus:~$ ./zups.sh
Gtk-Message: GtkDialog mapped without a transient parent. This is discouraged.

** (zenity:3844): WARNING **: AT-SPI: Could not obtain desktop path or name


** (zenity:3844): WARNING **: atk-bridge: GetRegisteredEvents returned message with unknown signature

** (zenity:3844): WARNING **: atk-bridge: get_device_events_reply: unknown signature

** (zenity:3844): WARNING **: atk-bridge: get_device_events_reply: unknown signature
glibtop(c=3862): [DEBUG] open.c:53 glibtop_open_l(): SIZEOF: 40 - 65648 - 248 - 65624 - 224 - 65624
glibtop(c=3862): [DEBUG] open.c:163 glibtop_open_l(): Calling sysdeps open function.
glibtop(c=3862): [DEBUG] init.c:229 glibtop_init_s(): init_s with features=0x7ffffff and flags=0
sh: /opt/zups.sh: No such file or directory
guest@porteus:~$ 
I was running it from /home/guest/ and imo it should work from there.
Ed

User avatar
normalGuy
Black ninja
Black ninja
Posts: 52
Joined: 06 Nov 2015, 23:36
Distribution: porteus 3.2 xfce archBang
Location: uk & portugal

Re: Just made this script: UPS

Post#21 by normalGuy » 11 Oct 2016, 12:57

Hello,
Ed_P I notice in your comment:

Code: Select all

sh: /opt/zups.sh: No such file or directory
The code in the forum works normaly, but the link is new so sorry about that, I changed the location because of the little bug with cancel/exit so I add in start of the script:

Code: Select all

if [[ ${EUID} -ne 0 ]]  # check as Root
then
zenity --info --width=250 --title="UPS- Updating by Porteus-Scripts" --text '<span foreground="#008080" font="12">Must be run as <b>root</b></span>'
gksu /opt/zups.sh
exit 1
fi
Thanks.
Last edited by normalGuy on 11 Oct 2016, 20:54, edited 1 time in total.

User avatar
Ed_P
Contributor
Contributor
Posts: 8343
Joined: 06 Feb 2013, 22:12
Distribution: Cinnamon 5.01 ISO
Location: Western NY, USA

Re: Just made this script: UPS

Post#22 by Ed_P » 11 Oct 2016, 13:07

Not sure what you are suggesting I do normalGuy. Do I add the code you just posted to what I downloaded? Redownload the code from your .sh link? Use the code posted that was below the link?
Ed

User avatar
normalGuy
Black ninja
Black ninja
Posts: 52
Joined: 06 Nov 2015, 23:36
Distribution: porteus 3.2 xfce archBang
Location: uk & portugal

Re: Just made this script: UPS

Post#23 by normalGuy » 11 Oct 2016, 18:27

Hi Ed_P
Please sorry about the confusion, updated both:
==>Use the code from the forum &
==> Link also changed

----------------------------------
Note:
I want to open as root, with gksu.
The root code I added in my last comment was the reason of the error in the link file.

User avatar
normalGuy
Black ninja
Black ninja
Posts: 52
Joined: 06 Nov 2015, 23:36
Distribution: porteus 3.2 xfce archBang
Location: uk & portugal

Re: Just made this script: UPS

Post#24 by normalGuy » 11 Oct 2016, 21:01

==> Again the code in forum and the links are updated.

-------------------------------------------------------

Now let me test something: :wall:
- If I had to the beginning of the one of those files to test be root:

Code: Select all

# Detects Zenity & Root

be_root(){
pth=$(find "$(cd ..; pwd)" -name "zups.sh" | awk 'NR==1{print $1}')
if [[ ${EUID} -ne 0 ]]; then
gksu "$pth"
exit 0
fi
}

zty=$(ls /var/log/packages | grep 'zenity' | sed 's/-[0-9].*//')
if [ $? != 0 ];then
zenity --info --width=250 --text '<span foreground="#008080" font="12">Install <b>zenity</b> with USM</span>' 
usmgui
else
be_root
fi
it's working, but maybe in a dirty way, is there a better and simpler way?
Thanks.

User avatar
brokenman
Site Admin
Site Admin
Posts: 6105
Joined: 27 Dec 2010, 03:50
Distribution: Porteus v4 all desktops
Location: Brazil

Re: Just made this script: UPS

Post#25 by brokenman » 12 Oct 2016, 02:29

Looks fine. If it works, it IS fine.

Here is an alternative.
. /usr/share/porteus/porteus-functions

## Check for root
is_root || { gksu $0; exit; }

## Check for zenity
zty=$(ls /var/log/packages | grep 'zenity' | sed 's/-[0-9].*//')

could be

zty=`which zenity` or perhaps
command -pv zenity || echo "Zenity does not exist ... do something here"
How do i become super user?
Wear your underpants on the outside and put on a cape.

User avatar
normalGuy
Black ninja
Black ninja
Posts: 52
Joined: 06 Nov 2015, 23:36
Distribution: porteus 3.2 xfce archBang
Location: uk & portugal

Re: Just made this script: UPS

Post#26 by normalGuy » 12 Oct 2016, 17:12

Thanks brokenman

Replacing my last comment code with ( adding to the start of the script):

Code: Select all

## Porteus functions - thanks to Brokenman porteus linux ##

. /usr/share/porteus/porteus-functions
. /usr/share/porteus/gtkdialog-functions

zty=`command -pv zenity`
if [ "$?" = "0" ]
then
is_root || { gksu $0; exit; }
else 
gtk_message1 "=> Zenity does not exist... Install it with USM"
exit 0
fi
Now I just need to know how to bold the gtk-message dialod txt?

----------------------------------
Note:
Adding finishing touches, but the base script in the link and first comment works fine.
After I want to add a third column with Installed status but... :%)

User avatar
normalGuy
Black ninja
Black ninja
Posts: 52
Joined: 06 Nov 2015, 23:36
Distribution: porteus 3.2 xfce archBang
Location: uk & portugal

Re: Just made this script: UPS

Post#27 by normalGuy » 14 Oct 2016, 13:57

Hello,
...final touch, new piece of code to test installed status:

Code: Select all

# Status to the final list----------------------------------------------------
for app in $slst; do 
(if ls /var/log/packages | grep $app; then
         echo "Installed"
         else
         echo "not_Installed"
        fi); done > /tmp/z3
        
sed '/Installed/!d' /tmp/z3 > /tmp/z9        # Only Installed info line
cat /tmp/zups1 | sed -e 's/update-//' -e 's/^/FALSE /' > /tmp/z4 
paste /tmp/z4  /tmp/z9 > /tmp/z6            # Add status to third column
flst=$(cat /tmp/z6)
Screenshot:
https://drive.google.com/file/d/0BxLsS7 ... sp=sharing

User avatar
Ed_P
Contributor
Contributor
Posts: 8343
Joined: 06 Feb 2013, 22:12
Distribution: Cinnamon 5.01 ISO
Location: Western NY, USA

Re: Just made this script: UPS

Post#28 by Ed_P » 15 Oct 2016, 04:36

normalGuy wrote:Hello,
...final touch, new piece of code to test installed status:
New version uploaded somewhere?
Ed

User avatar
normalGuy
Black ninja
Black ninja
Posts: 52
Joined: 06 Nov 2015, 23:36
Distribution: porteus 3.2 xfce archBang
Location: uk & portugal

Re: Just made this script: UPS

Post#29 by normalGuy » 15 Oct 2016, 11:51

Hello,

Please check my above 09-Oct comment.
Just change the original forum code with the new one.
The original still with the link.

Thanks.

User avatar
normalGuy
Black ninja
Black ninja
Posts: 52
Joined: 06 Nov 2015, 23:36
Distribution: porteus 3.2 xfce archBang
Location: uk & portugal

Re: Just made this script: UPS

Post#30 by normalGuy » 18 Oct 2016, 22:32

Hello again,

Keeping the base zups code in the above comment...

... here is another version to test now more porteus alike, using an adaptation of the gtk-update-porteus function for the terminal:

Code: Select all

    #!/bin/bash
    #-----------------------------------------------------------------------
    # Upate by Porteus Scripts - gui/zenity version (zups.sh)
    # By normalGuy (ptrin)
    # Date: Oct 18, 2016
    #-----------------------------------------------------------------------


## Porteus functions - thanks to Brokenman porteus linux ##

. /usr/share/porteus/porteus-functions
. /usr/share/porteus/gtkdialog-functions

zty=`command -pv zenity`
if [ "$?" = "0" ]
then
is_root || { gksu $0; exit; }
else 
gtk_message1 "=> Zenity does not exist...install with USM" 
gksu usmgui
exit 0
fi

    # Selecting app names to updatelist ------------------------------------
    ulist=$(ls -1 /opt/porteus-scripts/update-* | awk -F/ '!/update-module/{print$NF}' | awk -F/ '!/update-porteus/{print$NF}' > /tmp/zups1
    cat /tmp/zups1)

    # Selecting app names to radiolist -------------------------------------
    rlst=$(cat /tmp/zups1 | sed -e 's/update-//' -e 's/^/FALSE /' > /tmp/zups2
    cat /tmp/zups2)

    # Selecting app single names to list -----------------------------------
    slst=$(cat /tmp/zups1 | sed -e 's/update-//' > /tmp/zups3
    cat /tmp/zups3)

# Status to the final list----------------------------------------------------
for app in $slst; do 
(if ls /var/log/packages | grep $app; then
         echo "Installed"
         else
         echo "not_Installed"
        fi); done > /tmp/z3
        
sed '/Installed/!d' /tmp/z3 > /tmp/z9        # Only Installed info line
cat /tmp/zups1 | sed -e 's/update-//' -e 's/^/FALSE /' > /tmp/z4 
paste /tmp/z4  /tmp/z9 > /tmp/z6            # Add status to third column
flst=$(cat /tmp/z6)


    # Read lines (app name to install) to update-command ------------------------------
    zups_install(){
    ap2i=$(cat /tmp/zzz) 
    if [ -z != "$ap2i" ]; then
      if (zenity --question --title="$Title" --width=295 --ok-label="Yes" --cancel-label="No" \
                  --text '<span foreground="#008080" font="12">Update <b>'$ap2i'</b></span>') ; then   
          terminal
# uxterm -bg black -fg orange -geometry 75x20 -title "update-$ap2i" -e 'bash -c "/opt/porteus-scripts/update-'$ap2i'; echo Enter to Close Terminal; read line"'
return
      fi
    fi
    
}

# Porteus gtk-update terminal adaptation from Brokenman gtk-update porteus

terminal(){
SCRIPT="$(cd "${0%/*}" 2>/dev/null; echo "$PWD"/"${0##*/}")"
ic=$(/usr/share/pixmaps/porteus/porteus128.png)
echo '
<window title="UPS - Update by Porteus Scripts" icon="system-settings">
<vbox>
<hbox>
      <pixmap icon_size="5">
        <input file stock="gtk-info"></input>
      </pixmap>
	'`txtcolor 400 darkcyan x-large normal "Updating $ap2i"`'
	'`hsep`'
</hbox>
	<frame>
		<terminal argv0="/bin/sh"
		envv0="WELCOME=Welcome to theUpdate by Porteus Scripts "
		pointer-autohide="false"
		hscrollbar-policy="2"
		vscrollbar-policy="2">
		<variable>vte1</variable>
		<input>echo "sh /opt/porteus-scripts/update-'$ap2i'"</input>
		</terminal>
	</frame>
<hbox>
	'`butok`'
</hbox>
</vbox>
</window>
'|gtkdialog -s

}

zups_menu(){
    Title="Updating by Porteus Scripts"
    subTxt="Select an app to <b>Install / Update</b>
Check <span color=\"blue\"><b>USM</b></span>"

main=$(zenity --list  --radiolist --width=340 --height=490 --text="$subTxt" \
             --title="$Title" --column " ✔ " --column "Application"  --column "Status" --ok-label="Install" \ $flst)
             
# Buttons --------------------------------------------------------
    bex="$?"                    # Cancel
    if [[ "$bex" != "0" ]]
    then
    rm -rf /tmp/{zups1,zups2,zups3,zzz}
    rm -rf /tmp/{z3,z6,z9,z4}
    exit 0
    elif [[ -z "$main" ]]       # Install without a choose
          then
             zenity --info --width=250 --text '<span foreground="#008080" font="12">Please <b>select</b> something</span>'
             zups_menu
    fi
       
# Install app ----------------------------------------------------------   

      echo $main | grep '[a-zA-Z0-9]' > /tmp/zzz # If anything is selected
      if [ $? = 0 ];then
      zups_install && zups_menu
      fi
     
}
## main
zups_menu
... uff!! I think this is it...now just bugging around!! :twisted:
Thanks for all your patience.

Post Reply