Update notifier – low resources script to check and install updates

Forum Forums General Tips and Tricks Update notifier – low resources script to check and install updates

  • This topic has 34 replies, 6 voices, and was last updated Feb 26-2:01 pm by Lead Farmer.
Viewing 15 posts - 16 through 30 (of 35 total)
  • Author
    Posts
  • #99850
    Member
    PPC
      Helpful
      Up
      1
      ::

      @Lead Farmer – Nice! I’m glad that you tinkered and created a solution that works for you!

      #99855
      Member
      luke22
        Helpful
        Up
        0
        ::

        PPC
        I am a new user learning to set up Antix22 to my preferences by reading forum etc. I have used linux only for 20 years, using a variety of distros.
        I like your update reminder script, and have downloaded ft10, so have the script. I don’t want to use ft10 enabled as it changes far too much and takes me away from where I’ve got to in my set up. I like iceWM.
        I want to know where I should put the script ft10-update-reminder.sh so it runs daily or when I switch on laptop. I don’t understand crontab so if that is involved, I’ll need specific instructions. I can’t find a startup folder that other linux distros have.

        #99865
        Member
        PPC
          Helpful
          Up
          1
          ::

          This is a bit off-topic, but I think the question does not merit it’s own thread so here it goes:

          Hi luke22 – welcome to antiX: I advise that you read the sticky posts on the forum, some written by me, that will help you deal better with antiX and configure it anyway you like, including how to add any application so it starts when antiX starts.
          Basically, you just need to add it to the startup file of the window manager that you use. In plain English: if you use (the default) IceWM, do this:
          – antiX Menu > Control Centre > IceWM… > “Startup” tab
          – below the first line, insert a line calling the application you want to run, ending with an &
          In this case:
          ft10-update-reminder.sh &
          – Save the change.

          The next time you start antiX, Update-reminder will run. You can configure antiX to run anything you like, at startup, doing this. There used to be a GUI for it, maybe it will be included again…

          P.

          • This reply was modified 2 months, 2 weeks ago by PPC.
          #99867
          Member
          luke22
            Helpful
            Up
            0
            ::

            Thanks PPC. That was obvious, I guess. I’ll certainly study the stickies. My problem is not remembering what I read. 🙂

            #99871
            Moderator
            caprea
              Helpful
              Up
              1
              ::

              I can’t find a startup folder

              – antiX Menu > Control Centre > IceWM… > “Startup” tab
              The startup file PPC mentioned above is the the startup file for just icewm

              To say it in detail now.
              There’s another startup file which is valid for all window managers
              menu > control-centre > session > User-Desktop-Session > startup tab

              You can also have a look at apt-notifier, which is already present in an outcommented line in the desktop-session startup file.
              It needs to be installed though.Seems you have to install python3-distutils, too.

              #99916
              Member
              Lead Farmer
                Helpful
                Up
                0
                ::

                Update: although apt-notifier update checker don’t need a sudo password, it dues require a the apt-notifier to be working in the background to not show enter password window, something that I did’t want, and defy the purpose.

                I decided to remove the sudo password requirement with the command visudo.

                the latest scrip is:

                #!/bin/bash
                
                # Set this bash scrip with crontab to check and install updates
                export DISPLAY=:0.0
                UPGRADS_NUM=$(sudo apt update | grep -P -o '^\d+')
                # Set X and Y where the massage will show on your screen
                X=1366
                Y=768
                
                if [[ $UPGRADS_NUM -gt 0 ]]; then
                	yad \
                	--borders=20 \
                	--timeout=60 \
                	--title="Update Available" \
                	--text="You can update $UPGRADS_NUM packages" \
                	--geometry=200x120+$X+$Y \
                	--button='Install:bash -c "/usr/local/bin/yad-updater"' \
                	--button="Cancel:1"
                fi
                exit 0
                • This reply was modified 2 months, 2 weeks ago by Lead Farmer.
                • This reply was modified 2 months, 2 weeks ago by Lead Farmer.
                • This reply was modified 2 months, 1 week ago by Lead Farmer.
                #100345
                Member
                Lead Farmer
                  Helpful
                  Up
                  0
                  ::

                  I update script, instated of using Antix Updater, I use “sudo apt-get -y upgrade”, because it first dues “sudo apt update”.
                  It now also will show message at the end and log the update. also the massage will close after a button press.

                  #!/bin/bash
                  
                  # Set this bash scrip with crontab to check and install updates
                  export DISPLAY=:0.0
                  UPGRADS_NUM=$(sudo apt update | grep -P -o '^\d+')
                  # Set X and Y where the massage will show on your screen
                  X=1366
                  Y=768
                  
                  if [[ $UPGRADS_NUM -gt 0 ]]; then
                  	yad \
                  	--borders=20 \
                  	--timeout=600 \
                  	--title="Update Available" \
                  	--text="You can update $UPGRADS_NUM packages" \
                  	--geometry=200x120+$X+$Y \
                  	--button="Install":2 \
                  	--button="Cancel":1 \
                  	--buttons-layout=center
                  	# Exit or updater and exit depend by the button press 
                  	SELECT=$?
                  	[[ $SELECT -eq 1 ]] && exit 0
                  	if [[ $SELECT -eq 2 ]]; then
                  		UPGRADE=$(sudo apt-get -y upgrade) 
                  		echo -e "\n\n\n$(date)\n$UPGRADE" >> "/home/oren/Documents/upgrade.log"
                  		UPGRADE_MS=$(cat "/home/oren/Documents/upgrade.log" | tail -1 | grep -P -o '\d+[a-z ]+')
                  		$(desktop-menu --write-out-global)
                  		yad \
                  		--borders=20 \
                  		--timeout=60 \
                  		--title="Update Complete" \
                  		--text="$UPGRADE_MS" \
                  		--width=250 \
                  		--height=160\
                  		--center \
                  		--button="Close":1 \
                  		--button="Log File":2 \
                  		--buttons-layout=center
                  		SELECT=$?
                  		[[ $SELECT -eq 1 ]] && exit 0
                  		if [[ $SELECT -eq 2 ]]; then
                  			$(leafpad /home/oren/Documents/upgrade.log)
                  			exit 0
                  		fi
                  	fi
                  fi
                  exit 0

                  The log file can be deleted every week with crontab.

                  If you what to use it set the path of the loge file and X and Y Where the massage will show on the screen.

                  Edit: change to sudo apt-get -y upgrade to a void selecting Yes.

                  Edit2: I add $(desktop-menu –write-out-global)

                  • This reply was modified 2 months, 1 week ago by Lead Farmer.
                  • This reply was modified 2 months, 1 week ago by Lead Farmer.
                  • This reply was modified 2 months, 1 week ago by Lead Farmer.
                  #100408
                  Member
                  PPC
                    Helpful
                    Up
                    0
                    ::

                    Hi! It’s nice to see that your script is progressing. but, like I mentioned on another tread: it can be dangerous, using “sudo apt-get -y upgrade”, because it always answers “yes” to any question the upgrade process asks, and that may not be the default answer ( this may result in config files being overwritten, etc. This means you can lose any customization you did to the menu or toolbar, among other things)

                    On my old desktop I simply had a cron job that ran a script that called antiX-updater every day, at 15h00… But that could be annoying, specially if I was typing when that window popped up. So now, I just click the antiX-updater icon on the toolbar, about once a day (sometimes more, sometimes, less). But I understand the need to create scripts to make the OS do exactly what you want- it’s what drives me, to create so many scripts for antiX – some even get officially included in the OS, over time.

                    Edit: I noticed that you script performs sudo apt update – did you manage to run apt update without the need to enter your password? If so, how did you manage to do it? I could not, it always gives me a permissions error…
                    Also, the script will only work 100% correctly for your username, since the log is in “/home/oren/”. You can change that to ~/ or $HOME/, so it will work for any user (that has a Documents folder- that folder does get localized, in pt, for example, it’s “Documentos”). You can make the script a tiny bit complex and refersto the variable with name of the folder (so it works in any language, not just English)- it’s the variable $XDG_DOCUMENTS_DIR. So, using $XDG_DOCUMENTS_DIR would probably make sure that the log works for any user, in any language (try echo $XDG_DOCUMENTS_DIR it should output /home/oren/Documents, right?)

                    P.

                    • This reply was modified 2 months, 1 week ago by PPC.
                    • This reply was modified 2 months, 1 week ago by PPC.
                    • This reply was modified 2 months, 1 week ago by PPC.
                    #100429
                    Member
                    Lead Farmer
                      Helpful
                      Up
                      0
                      ::

                      Hi! It’s nice to see that your script is progressing. but, like I mentioned on another tread: it can be dangerous, using “sudo apt-get -y upgrade”, because it always answers “yes” to any question the upgrade process asks, and that may not be the default answer ( this may result in config files being overwritten, etc. This means you can lose any customization you did to the menu or toolbar, among other things)

                      I guess I’m new to Linux, and the only time it yes or no, It’s asking for extra memory, I did saw online people suggesting to use “sudo apt-get -y upgrade” and didn’t say any thing about losing any customization atc…
                      Also in the script @RJP post here he also use “sudo apt-get -y upgrade”

                      I will do more reading about it and make a decision, If I decide to remove it I can replace second half of the script with $(roxterm -e sudo apt upgrade).

                      Edit: I noticed that you script performs sudo apt update – did you manage to run apt update without the need to enter your password? If so, how did you manage to do it? I could not, it always gives me a permissions error…

                      As I posted #99916 I used visudo to remove all passwords requirements fro my user

                      oren ALL=(ALL:ALL) NOPASSWD:ALL

                      Also, the script will only work 100% correctly for your username, since the log is in “/home/oren/”. You can change that to ~/ or $HOME/, so it will work for any user (that has a Documents folder- that folder does get localized, in pt, for example, it’s “Documentos”). You can make the script a tiny bit complex and refersto the variable with name of the folder (so it works in any language, not just English)- it’s the variable $XDG_DOCUMENTS_DIR. So, using $XDG_DOCUMENTS_DIR would probably make sure that the log works for any user, in any language (try echo $XDG_DOCUMENTS_DIR it should output /home/oren/Documents, right?)

                      I’m the only user, but it’s good to know.

                      I also add to the script to show in the end message how many times the words “error” and “warning” is showing to alert me in case of problem.

                      • This reply was modified 2 months, 1 week ago by Lead Farmer.
                      • This reply was modified 2 months, 1 week ago by Lead Farmer.
                      • This reply was modified 2 months, 1 week ago by Lead Farmer.
                      #100434
                      Member
                      PPC
                        Helpful
                        Up
                        0
                        ::

                        I used visudo to remove all passwords requirements fro my user

                        Sorry I missed that piece of info: doing that is potentially dangerous – any malicious software that runs under your user will be able to do much more harm to your System… That’s why I suggested only removing the password requirement only from “apt update”.

                        P.

                        #100440
                        Moderator
                        Brian Masinick
                          Helpful
                          Up
                          0
                          ::

                          RE: oren ALL=(ALL:ALL) NOPASSWD:ALL

                          Yeah, I’ve done that before, but only for convenience on something I did not intend to keep.

                          @PPC: is right; though this is “convenient”, it’s definitely NOT best practice; you’re opening up your system to a LOT of potential compromises. Should anyone successfully break into your system, they can obtain ANY information they want, take over anything they want, and worse, if you have any online information or accounts anywhere, they can reach them through this very insecure “convenience”.

                          If it wasn’t clear before, both PPC and I have attempted to explain to you and others why this is an unsafe practice.

                          --
                          Brian Masinick

                          #100457
                          Member
                          Lead Farmer
                            Helpful
                            Up
                            0
                            ::

                            @PPC and @Brian Masinick
                            You both right, I didn’t think about the security risk, I thought is only apply to me and not third party.

                            I changed it to

                            oren ALL=(ALL) NOPASSWD:/usr/bin/apt update, /usr/bin/apt-get -y upgrade

                            Thank you

                            Here is the latest script

                            #!/bin/bash
                            
                            # Set this bash scrip with crontab to check and install updates
                            export DISPLAY=:0.0
                            UPGRADS_NUM=$(sudo apt update | grep -P -o '^\d+')
                            # Set X and Y where the massage will show on your screen
                            X=1366
                            Y=768
                            
                            if [[ $UPGRADS_NUM -gt 0 ]]; then
                            	yad \
                            	--borders=20 \
                            	--timeout=600 \
                            	--title="Update Available" \
                            	--text="You can update $UPGRADS_NUM packages" \
                            	--geometry=200x120+$X+$Y \
                            	--button="Install":2 \
                            	--button="Cancel":1 \
                            	--buttons-layout=center
                            	# Exit or updater and exit depend by the button press 
                            	SELECT=$?
                            	[[ $SELECT -eq 1 ]] && exit 0
                            	if [[ $SELECT -eq 2 ]]; then
                            		$(rm "/home/oren/Documents/upgrade.log")
                            		UPGRADE=$(sudo apt-get -y upgrade) 
                            		echo -e "$(date)\n$UPGRADE" >> "/home/oren/Documents/upgrade.log"
                            		UPGRADE_MS=$(cat "/home/oren/Documents/upgrade.log" | tail -1 | grep -P -o '\d+ upgraded|\d+ newly installed|\d+ to remove|\d+ not upgraded')
                            		ERROR=$(grep -i -o 'error' "/home/oren/Documents/upgrade.log" | wc -l)
                            		WARNING=$(grep -i -o 'warning' "/home/oren/Documents/upgrade.log" | wc -l)
                            		$(desktop-menu --write-out-global)
                            		yad \
                            		--borders=20 \
                            		--timeout=60 \
                            		--title="Update Complete" \
                            		--text="$UPGRADE_MS\n$ERROR errors\n$WARNING warnings" \
                            		--width=250 \
                            		--height=200\
                            		--center \
                            		--button="Close":1 \
                            		--button="Log File":2 \
                            		--buttons-layout=center 
                            		SELECT=$?
                            		[[ $SELECT -eq 1 ]] && exit 0
                            		if [[ $SELECT -eq 2 ]]; then
                            			$(leafpad /home/oren/Documents/upgrade.log)
                            			exit 0
                            		fi
                            	fi
                            fi
                            exit 0
                            • This reply was modified 2 months, 1 week ago by Lead Farmer.
                            • This reply was modified 2 months, 1 week ago by Lead Farmer.
                            #100516
                            Member
                            Lead Farmer
                              Helpful
                              Up
                              0
                              ::

                              @PPC I decided to use ” sudo apt upgrade” instead of “sudo apt-get -y upgrade” because what you said but also I want so see and control the update.

                              Can you please check it out and tell me what you think. also how can I keep Roxterm open after the update is finished?

                              visudo
                              oren ALL=(ALL) NOPASSWD:/usr/bin/apt update, /usr/bin/apt upgrade

                              script
                              I will post it in a bit

                              • This reply was modified 2 months, 1 week ago by Lead Farmer.
                              • This reply was modified 2 months, 1 week ago by Lead Farmer.
                              • This reply was modified 2 months, 1 week ago by Lead Farmer.
                              #100535
                              Member
                              Lead Farmer
                                Helpful
                                Up
                                0
                                ::

                                Changing the script to ”sudo apt upgrade” with: $(roxterm -e sudo apt upgrade) Worked but the terminal is automatically closed after the command is finished, i didn’t want it so I copy the code from Antix Updater, to show a yad massage in the end.

                                The script

                                #!/bin/bash
                                #
                                # Set this bash scrip with crontab to check and install updates
                                #
                                export DISPLAY=:0.0
                                UPGRADS_NUM=$(sudo apt update | grep -P -o '^\d+')
                                # Set X and Y where the massage will show on your screen
                                X=1366
                                Y=768
                                # Set the path of the lod file
                                
                                if [[ $UPGRADS_NUM -gt 0 ]]; then
                                	yad \
                                	--borders=20 \
                                	--timeout=600 \
                                	--title="Update Available" \
                                	--text="You can update $UPGRADS_NUM packages" \
                                	--geometry=200x120+$X+$Y \
                                	--button="Install":2 \
                                	--button="Cancel":1 \
                                	--buttons-layout=center
                                	# Exit or updater and exit depend by the button press 
                                	SELECT=$?
                                	[[ $SELECT -eq 1 ]] && exit 0
                                	if [[ $SELECT -eq 2 ]]; then
                                		x-terminal-emulator -T "$title_terminal" -e /bin/bash -c "sudo apt upgrade && sleep 0.1 && yad  --center --borders=5 --width=250 --text-align=center --button=gtk-ok:1 --title='Update Complete' --buttons-layout=center"
                                	fi
                                fi
                                exit 0 
                                • This reply was modified 2 months, 1 week ago by Lead Farmer.
                                • This reply was modified 2 months, 1 week ago by Lead Farmer.
                                #100586
                                Member
                                RJP
                                  Helpful
                                  Up
                                  0
                                  ::

                                  terminal is automatically closed after the command is finished

                                  Add echo something and sleep something into your script.

                                Viewing 15 posts - 16 through 30 (of 35 total)
                                • You must be logged in to reply to this topic.