Just made this script: UPS

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

Just made this script: UPS

Post#1 by normalGuy » 30 Sep 2016, 15:15

Using the Porteus update-scripts I just made this UPS script (Updating by Porteus Scripts)
Maybe some expert can improve it,
thanks.
porteus rc5 64bits xfce

Code: Select all

#! /bin/bash
#based on an alip script

# COLORS {{{
Bold=$(tput bold)
Underline=$(tput sgr 0 1)
Reset=$(tput sgr0)
# Regular Colors
Red=$(tput setaf 1)
Green=$(tput setaf 2)
Yellow=$(tput setaf 3)
Blue=$(tput setaf 4)
Purple=$(tput setaf 5)
Cyan=$(tput setaf 6)
White=$(tput setaf 7)
# Bold
BRed=${Bold}$(tput setaf 1)
BGreen=${Bold}$(tput setaf 2)
BYellow=${Bold}$(tput setaf 3)
BBlue=${Bold}$(tput setaf 4)
BPurple=${Bold}$(tput setaf 5)
BCyan=${Bold}$(tput setaf 6)
BWhite=${Bold}$(tput setaf 7)

print_line() {
  printf "%$(tput cols)s\n"|tr ' ' '-'
}
print_title() {
  #clear
  print_line
  echo -e "# ${BPurple}$1${Reset}"
  print_line
  echo ""
}
print_question(){
  T_COLS=`tput cols`
  echo -n "${BBlue}$1${Reset}"
}

print_msg(){
  T_COLS=`tput cols`
  echo -e "${BGreen}$1${Reset}"
  sleep 2
}

print_info() {
  #Console width number
  T_COLS=`tput cols`
  echo -e "${Bold}$1${Reset}\n" | fold -sw $(( $T_COLS - 18 )) | sed 's/^/\t    /'
}
print_warning() {
  T_COLS=`tput cols`
  echo -e "${BYellow}$1${Reset}\n" | fold -sw $(( $T_COLS - 1 ))
  sleep 4
}

# check for root
#[[ ${EUID} -ne 0 ]] && echo "This script must be run as root." && exit 1

txtbld=$(tput bold)               # Bold
txtred=${txtbld}$(tput setaf 1)   # Red
rst=$(tput sgr0)                  # Reset

function redpswd() {
  echo -e "$1" $txtred 
}

if [ `whoami` != "root" ]; then
    redpswd "Enter root's password"
    su -c "sh $0 $1"
    exit
fi
echo $rst


print_title 'Updating by Porteus Scripts' 

ups_chrome(){
  print_msg "Update google-chrome"
  print_question "Do you want to Update Google-Chrome? [Y|n]"
  read yn
  yn=${yn:-y}
  if [ "$yn" == "y" ]; then
     /opt/porteus-scripts/update-chrome
     print_msg '... Finished!'
     ups_menu
  fi
}

ups_firefox(){
  print_msg "Update Firefox"
  print_question "Do you want to Update Firefox? [Y|n] "
  read yn
  yn=${yn:-y}
  if [ "$yn" == "y" ]; then
     /opt/porteus-scripts/update-firefox
     print_msg '... Finished!'
     ups_menu
  fi
}

ups_flash(){
  print_msg "Update Flash"
  print_question "Do you want to Update Flash? [Y|n] "
  read yn
  yn=${yn:-y}
  if [ "$yn" == "y" ]; then
     /opt/porteus-scripts/update-flash
     print_msg '... Finished!'
     ups_menu
  fi
}

ups_libreoffice(){
  print_msg "Update Libreoffice"
  print_question "Do you want to Libreoffice? [Y|n] "
  read yn
  yn=${yn:-y}
  if [ "$yn" == "y" ]; then
    /opt/porteus-scripts/update-libreoffice
    print_msg '... Finished!'
    ups_menu
  fi
}

ups_opera(){
  print_msg "Update Opera"
  print_question "Do you want to Update Opera? [Y|n] "
  read yn
  yn=${yn:-y}
  if [ "$yn" == "y" ]; then
     /opt/porteus-scripts/update-opera
     print_msg '... Finished!'
     ups_menu
  fi
}

ups_palemoon(){
  print_msg "Update Palemoon"
  print_question "Do you want to Update Palemoon? [Y|n] "
  read yn
  yn=${yn:-y}
  if [ "$yn" == "y" ]; then
     /opt/porteus-scripts/update-palemoon
     print_msg '... Finished!'
     ups_menu
  fi
}

ups_vbox(){
  print_msg "Update Vbox"
  print_question "Do you want to Vbox? [Y|n] "
  read yn
  yn=${yn:-y}
  if [ "$yn" == "y" ]; then
     /opt/porteus-scripts/update-vbox
     print_msg '... Finished!'
     ups_menu
  fi
}

ups_wps(){
  print_msg "Update Wps-office"
  print_question "Do you want to Update Wps? [Y|n] "
  read yn
  yn=${yn:-y}
  if [ "$yn" == "y" ]; then
     /opt/porteus-scripts/update-wps-office
     print_msg '... Finished!'
     ups_menu
  fi
}

# END
ups_exit(){
   ps aux | grep ups | awk '{print $2}' > /tmp/end
   ups=$(cat /tmp/end)
   kill -9 $ups
   }

ups_menu(){
  while true
  do
    echo
    print_question "Choose an action:"
    echo
    echo
    action_list=("chrome" "firefox" "flash" "libreoffice" "opera" "palemoon" "vbox" "wps" "exit");
    select action in "${action_list[@]}"; do
      case "$REPLY" in
        1)
          ups_chrome
          ;;
        2)
          ups_firefox
          ;;
        3)
          ups_flash
          ;;
        4)
          ups_libreoffice
          ;;
        5)
          ups_opera
          ;;
        6)
          ups_palemoon
          ;;
        7)
          ups_vbox
          ;;
        8)
          ups_wps
          ;;
       9)
          ups_exit
          ;;
        *)
          print_warning "dommage, essaye encore ops!!"
          ;;
      esac
      [[ -n $OPT ]] && break
    done
  done
}

ups_menu
Last edited by normalGuy on 03 Oct 2016, 18:55, edited 2 times in total.

Jack
Contributor
Contributor
Posts: 1857
Joined: 09 Aug 2013, 14:25
Distribution: Porteus and Nemesis
Location: USA

Re: Just made this script: UPS

Post#2 by Jack » 30 Sep 2016, 16:10

I will give it a try. Will it work both 32 & 64 bit? There another one called pepperflash I think it will be added.
I just like Slackware because I think it teach you about Linux to build packages where Ubuntu is like Windows you just install programs you want.

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#3 by normalGuy » 02 Oct 2016, 19:30

Hello Jack
I suppose so not using it myself 32 bits, but its just a bash basic stuff. No yad or zenety or even whiptail.
If someone knows how to add a progress bar - pv ; etc... but I think this way we see if there are any errors in the end.
- Just edited the above script:
Now it's even simpler everything runs in the same place and it always return in the end to the main menu,
Script Image:
https://drive.google.com/file/d/0BxLsS7 ... sp=sharing

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

Re: Just made this script: UPS

Post#4 by Ed_P » 02 Oct 2016, 23:57

Porteus 3.2rc5 Cinnamon 64-bit

An interesting script normalGuy, thank you for posting it.

It seems to reject the 9 operand.

Code: Select all

guest@porteus:~$ ./ups.sh
This script must be run as root.
guest@porteus:~$ su
Password: 
root@porteus:/home/guest# ./ups.sh
--------------------------------------------------------------------------------
# Updating by Porteus Scripts
--------------------------------------------------------------------------------


Choose an action:

1) chrome	3) flash	5) opera	7) vbox		9) exit
2) firefox	4) libreoffice	6) palemoon	8) wps
#? 9
ups: no process found
#? 0
dommage, essaye encore ops!!

#? ^Croot@porteus:/home/guest# 
If it requires running as root you might consider adding something like this to the beginning of it.

Code: Select all

# Color definitions
txtbld=$(tput bold)               # Bold
txtred=${txtbld}$(tput setaf 1)   # Red
rst=$(tput sgr0)                  # Reset

function redpswd() {
  echo -e "$1" $txtred  
}

if [ `whoami` != "root" ]; then
    redpswd "Enter root's password"
    su -c "sh $0 $1"
    exit
fi
echo $rst
Or simply this:

Code: Select all

if [ `whoami` != "root" ]; then
   ktsuss "$0 $1"
   exit
fi
Ed

Bogomips
Full of knowledge
Full of knowledge
Posts: 2564
Joined: 25 Jun 2014, 15:21
Distribution: 3.2.2 Cinnamon & KDE5
Location: London

Re: Just made this script: UPS

Post#5 by Bogomips » 02 Oct 2016, 23:59

* This is great. Someone with a lot of memory and a fast machine just has to run the script and put the modules up on a file sharing site for the rest of us. Do remember to change either permission or user on the end module so as to facilitate uploading.
Linux porteus 4.4.0-porteus #3 SMP PREEMPT Sat Jan 23 07:01:55 UTC 2016 i686 AMD Sempron(tm) 140 Processor AuthenticAMD GNU/Linux
NVIDIA Corporation C61 [GeForce 6150SE nForce 430] (rev a2) MemTotal: 901760 kB MemFree: 66752 kB

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#6 by normalGuy » 03 Oct 2016, 19:14

Hi
Bogomips you change ups to ups.sh and the script is killing by name killall ups;, need to change booth of them.
New script it just added above with changes:
Name:ups.sh.
Ed_P above password code.
New end/kill add (ugly stuff but not an expert), now it kills process with name ups on it:

Code: Select all

# END
ups_exit(){
   ps aux | grep ups | awk '{print $2}' > /tmp/end
   ups=$(cat /tmp/end)
   kill -9 $ups
   }
The first ideia was to create a launcher.desktop an exec command like gsku someterminal -e /path/to/ups file.
The original ups file its here just in case:
https://drive.google.com/file/d/0BxLsS7 ... sp=sharing


So thanks all for the input.
Last edited by normalGuy on 09 Oct 2016, 20:50, edited 2 times in total.

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#7 by brokenman » 04 Oct 2016, 02:00

Nice stuff normalGuy.

I have a script here that includes all the update files in one, but I was never happy with it and didn't include it. People will find this handy.

EDIT:
For people interested in scripting please take a look at /usr/share/porteus/porteus-functions
It is a library of useful functions to make scripting easier. So the above script could look something like ...

Code: Select all

## Source the library
. /usr/share/porteus/porteus-functions

## Import the colors
get_colors

## Build an array with the name of the update file
for a in `ls -1 /opt/porteus-scripts/update-* | awk -F/ '!/update-module/{print$NF}'`; do
	RESULT+=( $a )
done

titletxt=`green "Porteus updater"`
menu_from_array "$titletxt" "Select an item from the menu." $RESULT
$CHOICE
Obviously you would need to add some of your checks in there but the library contains some of those too.
is_root
is_king
is_online_url
get_user_list
How do i become super user?
Wear your underpants on the outside and put on a cape.

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

Re: Just made this script: UPS

Post#8 by Ed_P » 04 Oct 2016, 04:44

normalGuy wrote:So thanks all for the input.
I tested the new version and got this:

Code: Select all

guest@porteus:~$ ./ups.sh
Enter root's password 
Password: 

--------------------------------------------------------------------------------
# Updating by Porteus Scripts
--------------------------------------------------------------------------------


Choose an action:

1) chrome	3) flash	5) opera	7) vbox		9) exit
2) firefox	4) libreoffice	6) palemoon	8) wps
#? 9
./ups.sh: line 72:  2754 Killed                  su -c "sh $0 $1"
guest@porteus:~$ 
The root signon worked as did the 9 exit but got very strange error msg. One I have never seen before. (not saying much)
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#9 by brokenman » 04 Oct 2016, 05:16

but got very strange error msg. One I have never seen before. (not saying much)
I don't see any error there. Just verbose output that pid 2754 was killed.
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#10 by normalGuy » 04 Oct 2016, 11:42

Hello,
Thanks all for your support.
Ed_P if I copy the file from porteus forum I also have that message, but in my pc the original file just works, the final message is Terminated (ups original) and Killed (ups.sh).
I just copy and paste the code to the forum but the functions are all over the place. Maybe I need to do it another way?

So I add a download link to the file ups.sh:
https://drive.google.com/file/d/0BxLsS7 ... sp=sharing
A download link to the original file ups:
https://drive.google.com/file/d/0BxLsS7 ... sp=sharing


Reedit post:
Ok if I run it with geany I also have that message, but them with the terminal (at least xfce-term) that message is just "killed"... :)
Last edited by normalGuy on 09 Oct 2016, 20:51, edited 2 times in total.

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

Re: Just made this script: UPS

Post#11 by Ed_P » 04 Oct 2016, 17:09

normalGuy I downloaded the sh file, ran it in terminal and exiting works. (I don't know what geany is but I suspect it's your file manager)

I compared the file I created from the forum posting that has the error with the downloaded file and except for a blank line at the end they are identical. I also tested both versions with Porteus 3.0.1 RazorQT 64-bit and they both worked. Not sure what the problem is but it's unique to 3.2rc5. :unknown:

Thank you for your efforts. :beer:

BTW You might want to consider making the exit character something other than a 9 in case brokenman adds another update script. :)
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#12 by normalGuy » 04 Oct 2016, 19:28

Hello

Ed_P thank you for your interest and effort with my little script! Glad that's working.
The exit number will always be the last one, like: 9) pepperflash 10) exit or I will try to work on other way, and I also can do it with submenus: browsers ( firefox chrome...) etc, or if I use zenety dialog list I have a window with close and install buttons, maybe in a few days, lets see...

Geany is a text editor with steroids with a button that allows you to run the script in the text editor itself.
https://pkgs.org/slackware-14.1/salix-i ... v.txz.html

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#13 by normalGuy » 05 Oct 2016, 17:58

Hello again

Final version ups.sh. Please check my above above comment for the link.
Last changes:
[*] Exit it's no longer a number, Just Type x to exit.
[*] After every update action Enter back to menu message will return you to a clean menu without all the verbose of the last operation.

That's it folks!! :beer:
Now just waiting for new update-scripts to add.
Thanks||

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

Re: Just made this script: UPS

Post#14 by Ed_P » 05 Oct 2016, 18:22

.
:good:

If I run the new download I get:

Code: Select all

guest@porteus:~$ sh ./Downloads/ups.sh
Enter root's password 
Password: 

--------------------------------------------------------------------------------
# Updating by Porteus Scripts
--------------------------------------------------------------------------------

Choose an action:  > > >
X to exit
1) chrome	3) flash	5) opera	7) vbox
2) firefox	4) libreoffice	6) palemoon	8) wps
#? x
Exit?  [Y|n]y
Killed
guest@porteus:~$ 
You might want to put a >> in front of the "X to exit" line.

If I add this comment to the top of the source:

Code: Select all

# https://forum.porteus.org/viewtopic.php?f=48&t=6258&p=49194#p49194
#! /bin/bash
Which I do for most scripts and code I copy.

When I run it I get:

Code: Select all

guest@porteus:~$ ./ups.sh
Enter root's password 
Password: 

--------------------------------------------------------------------------------
# Updating by Porteus Scripts
--------------------------------------------------------------------------------

Choose an action:  > > >
X to exit
1) chrome	3) flash	5) opera	7) vbox
2) firefox	4) libreoffice	6) palemoon	8) wps
#? x
Exit?  [Y|n]y
./ups.sh: line 87:  7447 Killed                  su -c "sh $0 $1"
guest@porteus:~$
:crazy:

I don't get it.
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#15 by normalGuy » 05 Oct 2016, 20:53

Thanks Ed_p
Ah ah also here, 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. :crazy:

Post Reply