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.
Edited slightly to avoid echo
and to provide some information about the system and hardware. You can answer my original question if you are already in progress of writing it. No problem with that.
#!/bin/sh
set -o nounset
# friendly computer description
readonly computer_description='Vlasta - Laptop - Main'
# 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_magenta=${bold}$(tput setaf 5)
readonly bold_cyan=${bold}$(tput setaf 6)
readonly bold_white=${bold}$(tput setaf 7)
readonly nocolor=$(tput sgr0)
# to create clear blocks of texts, we separate them with this
readonly block_separator='----------------------------------------'
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))
printf '%sn' "Step #${step_number}: ${bold_green}${1}${nocolor}"
# print the command to be run
printf '%sn' "Command: ${bold_yellow}${2}${nocolor}"
printf '%sn' "${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
printf 'n'
else
printf '%snn' "${bold_red}An error occurred.${nocolor}"
exit 1
fi
# move to another pair of arguments
shift 2
done
}
distro_name=$(lsb_release --id | awk '{ print $3 }')
release_version=$(lsb_release --release | awk '{ print $2 }')
hostname=$(cat /etc/hostname)
printf 'n%sn' "Friendly: ${bold_magenta}${computer_description}${nocolor}"
printf '%sn' "Distro : ${bold_magenta}${distro_name} ${release_version}${nocolor}"
printf '%sn' "Hostname: ${bold_magenta}${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
if [ "$(id --user)" -ne 0 ]
then
sudo sh -c ":" || exit 1
fi
printf '%s' "${bold_cyan}"
sudo dmidecode --type 1 | grep 'System Information' --after 8
printf '%snn' "${bold_white}${block_separator}${nocolor}"
# execute all jobs in one go
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
add a comment |
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.
Edited slightly to avoid echo
and to provide some information about the system and hardware. You can answer my original question if you are already in progress of writing it. No problem with that.
#!/bin/sh
set -o nounset
# friendly computer description
readonly computer_description='Vlasta - Laptop - Main'
# 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_magenta=${bold}$(tput setaf 5)
readonly bold_cyan=${bold}$(tput setaf 6)
readonly bold_white=${bold}$(tput setaf 7)
readonly nocolor=$(tput sgr0)
# to create clear blocks of texts, we separate them with this
readonly block_separator='----------------------------------------'
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))
printf '%sn' "Step #${step_number}: ${bold_green}${1}${nocolor}"
# print the command to be run
printf '%sn' "Command: ${bold_yellow}${2}${nocolor}"
printf '%sn' "${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
printf 'n'
else
printf '%snn' "${bold_red}An error occurred.${nocolor}"
exit 1
fi
# move to another pair of arguments
shift 2
done
}
distro_name=$(lsb_release --id | awk '{ print $3 }')
release_version=$(lsb_release --release | awk '{ print $2 }')
hostname=$(cat /etc/hostname)
printf 'n%sn' "Friendly: ${bold_magenta}${computer_description}${nocolor}"
printf '%sn' "Distro : ${bold_magenta}${distro_name} ${release_version}${nocolor}"
printf '%sn' "Hostname: ${bold_magenta}${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
if [ "$(id --user)" -ne 0 ]
then
sudo sh -c ":" || exit 1
fi
printf '%s' "${bold_cyan}"
sudo dmidecode --type 1 | grep 'System Information' --after 8
printf '%snn' "${bold_white}${block_separator}${nocolor}"
# execute all jobs in one go
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
add a comment |
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.
Edited slightly to avoid echo
and to provide some information about the system and hardware. You can answer my original question if you are already in progress of writing it. No problem with that.
#!/bin/sh
set -o nounset
# friendly computer description
readonly computer_description='Vlasta - Laptop - Main'
# 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_magenta=${bold}$(tput setaf 5)
readonly bold_cyan=${bold}$(tput setaf 6)
readonly bold_white=${bold}$(tput setaf 7)
readonly nocolor=$(tput sgr0)
# to create clear blocks of texts, we separate them with this
readonly block_separator='----------------------------------------'
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))
printf '%sn' "Step #${step_number}: ${bold_green}${1}${nocolor}"
# print the command to be run
printf '%sn' "Command: ${bold_yellow}${2}${nocolor}"
printf '%sn' "${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
printf 'n'
else
printf '%snn' "${bold_red}An error occurred.${nocolor}"
exit 1
fi
# move to another pair of arguments
shift 2
done
}
distro_name=$(lsb_release --id | awk '{ print $3 }')
release_version=$(lsb_release --release | awk '{ print $2 }')
hostname=$(cat /etc/hostname)
printf 'n%sn' "Friendly: ${bold_magenta}${computer_description}${nocolor}"
printf '%sn' "Distro : ${bold_magenta}${distro_name} ${release_version}${nocolor}"
printf '%sn' "Hostname: ${bold_magenta}${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
if [ "$(id --user)" -ne 0 ]
then
sudo sh -c ":" || exit 1
fi
printf '%s' "${bold_cyan}"
sudo dmidecode --type 1 | grep 'System Information' --after 8
printf '%snn' "${bold_white}${block_separator}${nocolor}"
# execute all jobs in one go
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
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.
Edited slightly to avoid echo
and to provide some information about the system and hardware. You can answer my original question if you are already in progress of writing it. No problem with that.
#!/bin/sh
set -o nounset
# friendly computer description
readonly computer_description='Vlasta - Laptop - Main'
# 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_magenta=${bold}$(tput setaf 5)
readonly bold_cyan=${bold}$(tput setaf 6)
readonly bold_white=${bold}$(tput setaf 7)
readonly nocolor=$(tput sgr0)
# to create clear blocks of texts, we separate them with this
readonly block_separator='----------------------------------------'
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))
printf '%sn' "Step #${step_number}: ${bold_green}${1}${nocolor}"
# print the command to be run
printf '%sn' "Command: ${bold_yellow}${2}${nocolor}"
printf '%sn' "${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
printf 'n'
else
printf '%snn' "${bold_red}An error occurred.${nocolor}"
exit 1
fi
# move to another pair of arguments
shift 2
done
}
distro_name=$(lsb_release --id | awk '{ print $3 }')
release_version=$(lsb_release --release | awk '{ print $2 }')
hostname=$(cat /etc/hostname)
printf 'n%sn' "Friendly: ${bold_magenta}${computer_description}${nocolor}"
printf '%sn' "Distro : ${bold_magenta}${distro_name} ${release_version}${nocolor}"
printf '%sn' "Hostname: ${bold_magenta}${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
if [ "$(id --user)" -ne 0 ]
then
sudo sh -c ":" || exit 1
fi
printf '%s' "${bold_cyan}"
sudo dmidecode --type 1 | grep 'System Information' --after 8
printf '%snn' "${bold_white}${block_separator}${nocolor}"
# execute all jobs in one go
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
console linux sh installer
edited Nov 17 at 11:21
asked Nov 17 at 4:45
Vlastimil
568318
568318
add a comment |
add a comment |
active
oldest
votes
active
oldest
votes
active
oldest
votes
active
oldest
votes
active
oldest
votes
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
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