Interactive Linux upgrade script - Follow-up #1











up vote
1
down vote

favorite












One year ago I asked for a yearly revision of my Interactive Linux upgrade script.



There is nothing new to the conditions, therefore please read the original question before you decide to comment and / or vote to close as unclear.



Additional notes:




  • The script will always run interactively as I want to have full control.


  • The script will be placed on 3 machines only, so I don't need much of generalization.


  • As my POSIX shell scripting abilities get better, I would very much like to get further incentives.





#!/bin/sh

set -o nounset

# friendly computer description
readonly computer_description='Vlasta, Laptop, Mint 19'

# color definitions
readonly bold=$(tput bold)
readonly bold_red=${bold}$(tput setaf 1)
readonly bold_green=${bold}$(tput setaf 2)
readonly bold_yellow=${bold}$(tput setaf 3)
readonly bold_blue=${bold}$(tput setaf 4)
readonly bold_white=${bold}$(tput setaf 7)
readonly nocolor=$(tput sgr0)
readonly block_separator='----------------------------------------'

print_error_and_exit()
{
printf '%snn' "${bold_red}An error occurred.${nocolor}"
exit 1
}

step_number=0
execute_jobs()
{
# process the given arguments as pairs
while [ "${#}" -gt 1 ]
do
# increase and print the step number along with description
step_number=$((step_number + 1))
echo "Step #${step_number}: ${bold_green}${1}${nocolor}"

# print the command to be run
echo "Command: ${bold_yellow}${2}${nocolor}"

echo "${bold_white}${block_separator}${nocolor}"

# run the actual command
# ShellCheck mistakenly things we should double quote the parameter
# if we did, it would become a string and we'd get command not found
# shellcheck disable=SC2086
if sudo ${2}
then
echo
else
print_error_and_exit
fi

# move to another pair of arguments
shift 2
done
}

hostname=$(cat /etc/hostname)
printf 'n%sn' "${bold_white}${block_separator}${nocolor}"
echo "Computer: ${bold_blue}${computer_description}${nocolor}"
echo "Hostname: ${bold_blue}${hostname}${nocolor}"
printf '%snn' "${bold_white}${block_separator}${nocolor}"


# the sudo password request shall proceed AFTER computer / hostname
# this is because the same script will always run in sequence on 3 computers

[ "$(id --user)" -eq 0 ] || sudo sh -c ":"

execute_jobs
'configure packages' 'dpkg --configure --pending'
'fix broken dependencies' 'apt-get --fix-broken install'
'update cache' 'apt-get update'
'upgrade packages' 'apt-get upgrade'
'upgrade packages with possible removals' 'apt-get dist-upgrade'
'remove unused packages' 'apt-get --purge autoremove'
'clean up old packages' 'apt-get autoclean'









share|improve this question




























    up vote
    1
    down vote

    favorite












    One year ago I asked for a yearly revision of my Interactive Linux upgrade script.



    There is nothing new to the conditions, therefore please read the original question before you decide to comment and / or vote to close as unclear.



    Additional notes:




    • The script will always run interactively as I want to have full control.


    • The script will be placed on 3 machines only, so I don't need much of generalization.


    • As my POSIX shell scripting abilities get better, I would very much like to get further incentives.





    #!/bin/sh

    set -o nounset

    # friendly computer description
    readonly computer_description='Vlasta, Laptop, Mint 19'

    # color definitions
    readonly bold=$(tput bold)
    readonly bold_red=${bold}$(tput setaf 1)
    readonly bold_green=${bold}$(tput setaf 2)
    readonly bold_yellow=${bold}$(tput setaf 3)
    readonly bold_blue=${bold}$(tput setaf 4)
    readonly bold_white=${bold}$(tput setaf 7)
    readonly nocolor=$(tput sgr0)
    readonly block_separator='----------------------------------------'

    print_error_and_exit()
    {
    printf '%snn' "${bold_red}An error occurred.${nocolor}"
    exit 1
    }

    step_number=0
    execute_jobs()
    {
    # process the given arguments as pairs
    while [ "${#}" -gt 1 ]
    do
    # increase and print the step number along with description
    step_number=$((step_number + 1))
    echo "Step #${step_number}: ${bold_green}${1}${nocolor}"

    # print the command to be run
    echo "Command: ${bold_yellow}${2}${nocolor}"

    echo "${bold_white}${block_separator}${nocolor}"

    # run the actual command
    # ShellCheck mistakenly things we should double quote the parameter
    # if we did, it would become a string and we'd get command not found
    # shellcheck disable=SC2086
    if sudo ${2}
    then
    echo
    else
    print_error_and_exit
    fi

    # move to another pair of arguments
    shift 2
    done
    }

    hostname=$(cat /etc/hostname)
    printf 'n%sn' "${bold_white}${block_separator}${nocolor}"
    echo "Computer: ${bold_blue}${computer_description}${nocolor}"
    echo "Hostname: ${bold_blue}${hostname}${nocolor}"
    printf '%snn' "${bold_white}${block_separator}${nocolor}"


    # the sudo password request shall proceed AFTER computer / hostname
    # this is because the same script will always run in sequence on 3 computers

    [ "$(id --user)" -eq 0 ] || sudo sh -c ":"

    execute_jobs
    'configure packages' 'dpkg --configure --pending'
    'fix broken dependencies' 'apt-get --fix-broken install'
    'update cache' 'apt-get update'
    'upgrade packages' 'apt-get upgrade'
    'upgrade packages with possible removals' 'apt-get dist-upgrade'
    'remove unused packages' 'apt-get --purge autoremove'
    'clean up old packages' 'apt-get autoclean'









    share|improve this question


























      up vote
      1
      down vote

      favorite









      up vote
      1
      down vote

      favorite











      One year ago I asked for a yearly revision of my Interactive Linux upgrade script.



      There is nothing new to the conditions, therefore please read the original question before you decide to comment and / or vote to close as unclear.



      Additional notes:




      • The script will always run interactively as I want to have full control.


      • The script will be placed on 3 machines only, so I don't need much of generalization.


      • As my POSIX shell scripting abilities get better, I would very much like to get further incentives.





      #!/bin/sh

      set -o nounset

      # friendly computer description
      readonly computer_description='Vlasta, Laptop, Mint 19'

      # color definitions
      readonly bold=$(tput bold)
      readonly bold_red=${bold}$(tput setaf 1)
      readonly bold_green=${bold}$(tput setaf 2)
      readonly bold_yellow=${bold}$(tput setaf 3)
      readonly bold_blue=${bold}$(tput setaf 4)
      readonly bold_white=${bold}$(tput setaf 7)
      readonly nocolor=$(tput sgr0)
      readonly block_separator='----------------------------------------'

      print_error_and_exit()
      {
      printf '%snn' "${bold_red}An error occurred.${nocolor}"
      exit 1
      }

      step_number=0
      execute_jobs()
      {
      # process the given arguments as pairs
      while [ "${#}" -gt 1 ]
      do
      # increase and print the step number along with description
      step_number=$((step_number + 1))
      echo "Step #${step_number}: ${bold_green}${1}${nocolor}"

      # print the command to be run
      echo "Command: ${bold_yellow}${2}${nocolor}"

      echo "${bold_white}${block_separator}${nocolor}"

      # run the actual command
      # ShellCheck mistakenly things we should double quote the parameter
      # if we did, it would become a string and we'd get command not found
      # shellcheck disable=SC2086
      if sudo ${2}
      then
      echo
      else
      print_error_and_exit
      fi

      # move to another pair of arguments
      shift 2
      done
      }

      hostname=$(cat /etc/hostname)
      printf 'n%sn' "${bold_white}${block_separator}${nocolor}"
      echo "Computer: ${bold_blue}${computer_description}${nocolor}"
      echo "Hostname: ${bold_blue}${hostname}${nocolor}"
      printf '%snn' "${bold_white}${block_separator}${nocolor}"


      # the sudo password request shall proceed AFTER computer / hostname
      # this is because the same script will always run in sequence on 3 computers

      [ "$(id --user)" -eq 0 ] || sudo sh -c ":"

      execute_jobs
      'configure packages' 'dpkg --configure --pending'
      'fix broken dependencies' 'apt-get --fix-broken install'
      'update cache' 'apt-get update'
      'upgrade packages' 'apt-get upgrade'
      'upgrade packages with possible removals' 'apt-get dist-upgrade'
      'remove unused packages' 'apt-get --purge autoremove'
      'clean up old packages' 'apt-get autoclean'









      share|improve this question















      One year ago I asked for a yearly revision of my Interactive Linux upgrade script.



      There is nothing new to the conditions, therefore please read the original question before you decide to comment and / or vote to close as unclear.



      Additional notes:




      • The script will always run interactively as I want to have full control.


      • The script will be placed on 3 machines only, so I don't need much of generalization.


      • As my POSIX shell scripting abilities get better, I would very much like to get further incentives.





      #!/bin/sh

      set -o nounset

      # friendly computer description
      readonly computer_description='Vlasta, Laptop, Mint 19'

      # color definitions
      readonly bold=$(tput bold)
      readonly bold_red=${bold}$(tput setaf 1)
      readonly bold_green=${bold}$(tput setaf 2)
      readonly bold_yellow=${bold}$(tput setaf 3)
      readonly bold_blue=${bold}$(tput setaf 4)
      readonly bold_white=${bold}$(tput setaf 7)
      readonly nocolor=$(tput sgr0)
      readonly block_separator='----------------------------------------'

      print_error_and_exit()
      {
      printf '%snn' "${bold_red}An error occurred.${nocolor}"
      exit 1
      }

      step_number=0
      execute_jobs()
      {
      # process the given arguments as pairs
      while [ "${#}" -gt 1 ]
      do
      # increase and print the step number along with description
      step_number=$((step_number + 1))
      echo "Step #${step_number}: ${bold_green}${1}${nocolor}"

      # print the command to be run
      echo "Command: ${bold_yellow}${2}${nocolor}"

      echo "${bold_white}${block_separator}${nocolor}"

      # run the actual command
      # ShellCheck mistakenly things we should double quote the parameter
      # if we did, it would become a string and we'd get command not found
      # shellcheck disable=SC2086
      if sudo ${2}
      then
      echo
      else
      print_error_and_exit
      fi

      # move to another pair of arguments
      shift 2
      done
      }

      hostname=$(cat /etc/hostname)
      printf 'n%sn' "${bold_white}${block_separator}${nocolor}"
      echo "Computer: ${bold_blue}${computer_description}${nocolor}"
      echo "Hostname: ${bold_blue}${hostname}${nocolor}"
      printf '%snn' "${bold_white}${block_separator}${nocolor}"


      # the sudo password request shall proceed AFTER computer / hostname
      # this is because the same script will always run in sequence on 3 computers

      [ "$(id --user)" -eq 0 ] || sudo sh -c ":"

      execute_jobs
      'configure packages' 'dpkg --configure --pending'
      'fix broken dependencies' 'apt-get --fix-broken install'
      'update cache' 'apt-get update'
      'upgrade packages' 'apt-get upgrade'
      'upgrade packages with possible removals' 'apt-get dist-upgrade'
      'remove unused packages' 'apt-get --purge autoremove'
      'clean up old packages' 'apt-get autoclean'






      console linux sh installer






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited 2 hours ago









      200_success

      127k15148410




      127k15148410










      asked 6 hours ago









      Vlastimil

      561318




      561318



























          active

          oldest

          votes











          Your Answer





          StackExchange.ifUsing("editor", function () {
          return StackExchange.using("mathjaxEditing", function () {
          StackExchange.MarkdownEditor.creationCallbacks.add(function (editor, postfix) {
          StackExchange.mathjaxEditing.prepareWmdForMathJax(editor, postfix, [["\$", "\$"]]);
          });
          });
          }, "mathjax-editing");

          StackExchange.ifUsing("editor", function () {
          StackExchange.using("externalEditor", function () {
          StackExchange.using("snippets", function () {
          StackExchange.snippets.init();
          });
          });
          }, "code-snippets");

          StackExchange.ready(function() {
          var channelOptions = {
          tags: "".split(" "),
          id: "196"
          };
          initTagRenderer("".split(" "), "".split(" "), channelOptions);

          StackExchange.using("externalEditor", function() {
          // Have to fire editor after snippets, if snippets enabled
          if (StackExchange.settings.snippets.snippetsEnabled) {
          StackExchange.using("snippets", function() {
          createEditor();
          });
          }
          else {
          createEditor();
          }
          });

          function createEditor() {
          StackExchange.prepareEditor({
          heartbeatType: 'answer',
          convertImagesToLinks: false,
          noModals: true,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: null,
          bindNavPrevention: true,
          postfix: "",
          imageUploader: {
          brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
          contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
          allowUrls: true
          },
          onDemand: true,
          discardSelector: ".discard-answer"
          ,immediatelyShowMarkdownHelp:true
          });


          }
          });














           

          draft saved


          draft discarded


















          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fcodereview.stackexchange.com%2fquestions%2f207850%2finteractive-linux-upgrade-script-follow-up-1%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown






























          active

          oldest

          votes













          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes
















           

          draft saved


          draft discarded



















































           


          draft saved


          draft discarded














          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fcodereview.stackexchange.com%2fquestions%2f207850%2finteractive-linux-upgrade-script-follow-up-1%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown





















































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown

































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown







          Popular posts from this blog

          Costa Masnaga

          Fotorealismo

          Sidney Franklin