diff --git a/Scripts/Bash/Functions/Verify/verify_doLinkCheck.sh b/Scripts/Bash/Functions/Verify/verify_doLinkCheck.sh new file mode 100755 index 0000000..949420c --- /dev/null +++ b/Scripts/Bash/Functions/Verify/verify_doLinkCheck.sh @@ -0,0 +1,76 @@ +#!/bin/bash +# +# verify_doLinkCheck.sh -- This function receives a list of required +# symbolic links and verifies them. This function enforces relation +# between link names and their targets (previously defined in +# verify_doLinks.sh function). +# +# Copyright (C) 2009-2010 Alain Reguera Delgado +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 2 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, but +# WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +# General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program; if not, write to the Free Software +# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 +# USA. +# +# ---------------------------------------------------------------------- +# $Id$ +# ---------------------------------------------------------------------- + +function verify_doLinkCheck { + + local -a LINKS_TARGET + local LINKS_COUNT=0 + + until [[ $LINKS_COUNT -eq ${#LINKS[*]} ]];do + + if [[ -h ${LINKS[$LINKS_COUNT]} ]]; then + + # At this point the required link does exist but we don't + # know if its target is the one it should be. Get target + # from required link in order to check it later. + LINKS_TARGET[$LINKS_COUNT]=$(stat --format='%N' ${LINKS[$LINKS_COUNT]} \ + | tr '`' ' ' | tr "'" ' ' | tr -s ' ' | cut -d' ' -f4) + + # Check required target from required link in order to + # know if it is indeed the one it should be. Otherwise add + # required link to list of missing links. + if [[ ${LINKS_TARGET[$LINKS_COUNT]} != ${TARGETS[$LINKS_COUNT]} ]] ;then + LINKS_MISSING[$LINKS_COUNT]=${LINKS[$LINKS_COUNT]} + LINKS_MISSING_ID="$LINKS_MISSING_ID $LINKS_COUNT" + fi + + else + + # At this point the required link doesn't exist at all. + # Add required link to list of missing links. + LINKS_MISSING[$LINKS_COUNT]=${LINKS[$LINKS_COUNT]} + LINKS_MISSING_ID="$LINKS_MISSING_ID $LINKS_COUNT" + + fi + + # Increase link counter. + LINKS_COUNT=$(($LINKS_COUNT + 1)) + + done + + # Stript out leading spaces from missing links ids. + LINKS_MISSING_ID=$(echo $LINKS_MISSING_ID | sed 's!^ +!!') + + # If there is no missing link, end script execution with a + # descriptive output. + if [[ ${#LINKS_MISSING[*]} -eq 0 ]];then + cli_printMessage "`gettext "The required links are already installed."`" + cli_printMessage "$(caller)" 'AsToKnowMoreLine' + fi + +} diff --git a/Scripts/Bash/Functions/Verify/verify_doLinkInstall.sh b/Scripts/Bash/Functions/Verify/verify_doLinkInstall.sh new file mode 100755 index 0000000..2c28bfa --- /dev/null +++ b/Scripts/Bash/Functions/Verify/verify_doLinkInstall.sh @@ -0,0 +1,64 @@ +#!/bin/bash +# +# verify_doLinkInstall.sh -- This function receives a list of missing +# links and installs them using `ln'. +# +# Copyright (C) 2009-2010 Alain Reguera Delgado +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 2 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, but +# WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +# General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program; if not, write to the Free Software +# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 +# USA. +# +# ---------------------------------------------------------------------- +# $Id$ +# ---------------------------------------------------------------------- + +function verify_doLinkInstall { + + local ID=0 + local LINKS_PARENT='' + local WARNING='' + + for ID in $LINKS_MISSING_ID;do + + # Verify parent directory of missing link names that have a + # file as target. If the parent directory doesn't exist, + # create it first before creating links inside it. Because + # links are not created yet, we use their targets as reference + # to determine what type of link we are creating. + if [[ -f ${TARGETS[$ID]} ]];then + LINKS_PARENT=$(dirname ${LINKS[$ID]}) + cli_checkFiles $LINKS_PARENT 'd' '' '--quiet' + if [[ $? -ne 0 ]];then + mkdir -p $LINKS_PARENT + fi + fi + + # Verify missing link that already exists as regular file. If + # a regular file exists with the same name of a required link, + # warn the user about it and continue with the next file in + # the list of missing links that need to be installed. + cli_checkFiles ${LINKS[$ID]} 'f' '' '--quiet' + if [[ $? -eq 0 ]];then + WARNING=" (`gettext "Already exists as regular file."`)" + cli_printMessage "${LINKS[$ID]}${WARNING}" 'AsResponseLine' + continue + fi + + # Create symbolic link. + ln -s ${TARGETS[$ID]} ${LINKS[$ID]} + + done + +} diff --git a/Scripts/Bash/Functions/Verify/verify_doLinkReport.sh b/Scripts/Bash/Functions/Verify/verify_doLinkReport.sh new file mode 100755 index 0000000..6c12212 --- /dev/null +++ b/Scripts/Bash/Functions/Verify/verify_doLinkReport.sh @@ -0,0 +1,48 @@ +#!/bin/bash +# +# verify_doLinkReport.sh -- This function outputs information about +# missing links that need to be installed and a confirmation question +# for users to accept the installation action. +# +# Copyright (C) 2009-2010 Alain Reguera Delgado +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 2 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, but +# WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +# General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program; if not, write to the Free Software +# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 +# USA. +# +# ---------------------------------------------------------------------- +# $Id$ +# ---------------------------------------------------------------------- + +function verify_doLinkReport { + + local LINK='' + local LINKS_MISSING_MAX=0 + + # Define max number of missing links. + LINKS_MISSING_MAX=${#LINKS_MISSING[*]} + + # Output list header. + cli_printMessage "`ngettext "The following link will be installed" \ + "The following links will be installed" "$LINKS_MISSING_MAX"`:" + + # Output list body. + for LINK in ${LINKS_MISSING[@]};do + cli_printMessage "${LINK}" 'AsResponseLine' + done + + # Request confirmation for further link installation. + cli_printMessage "`gettext "Do you want to continue"`" 'AsYesOrNoRequestLine' + +} diff --git a/Scripts/Bash/Functions/Verify/verify_doLinks.sh b/Scripts/Bash/Functions/Verify/verify_doLinks.sh new file mode 100755 index 0000000..6842241 --- /dev/null +++ b/Scripts/Bash/Functions/Verify/verify_doLinks.sh @@ -0,0 +1,61 @@ +#!/bin/bash +# +# verify_doLinks.sh -- This function verifies required links your +# workstation needs in order to run the centos-art command correctly. +# If any required link is missing, the `centos-art.sh' script asks you +# to confirm their installation. When installing links, the +# `centos-art.sh' script uses the `ln' command to achieve the task. +# +# Copyright (C) 2009-2010 Alain Reguera Delgado +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 2 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, but +# WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +# General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program; if not, write to the Free Software +# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 +# USA. +# +# ---------------------------------------------------------------------- +# $Id$ +# ---------------------------------------------------------------------- + +function verify_doLinks { + + local -a LINKS + local -a TARGETS + local -a LINKS_MISSING + local LINKS_MISSING_ID='' + + # Define link names. + LINKS[0]=/home/centos/bin/centos-art + LINKS[1]=/home/centos/.fonts/denmark.ttf + LINKS[2]=/home/centos/.inkscape/palettes/CentOS.gpl + LINKS[3]=/home/centos/.$(rpm -q gimp | cut -d. -f-2)/palettes/CentOS.gpl + LINKS[4]=/home/centos/artwork/branches/Scripts + + # Define link targets. Use array index as reference to know + # relation between link names and targets. Be sure both link names + # and link targets use the same array index value. + TARGETS[0]=/home/centos/artwork/trunk/Scripts/Bash/centos-art.sh + TARGETS[1]=/home/centos/artwork/trunk/Identity/Fonts/Ttf/denmark.ttf + TARGETS[2]=/home/centos/artwork/trunk/Identity/Colors/CentOS.gpl + TARGETS[3]=${TARGETS[2]} + TARGETS[4]=/home/centos/artwork/trunk/Scripts/ + + verify_doLinkCheck + verify_doLinkReport + verify_doLinkInstall + + # At this point all required links must be installed. To confirm + # required links installation let's verify them once more. + verify_doLinks + +} diff --git a/Scripts/Bash/Functions/Verify/verify_doPackageCheck.sh b/Scripts/Bash/Functions/Verify/verify_doPackageCheck.sh index efabbb0..3d8ebba 100755 --- a/Scripts/Bash/Functions/Verify/verify_doPackageCheck.sh +++ b/Scripts/Bash/Functions/Verify/verify_doPackageCheck.sh @@ -54,7 +54,7 @@ function verify_doPackageCheck { # In there is no missing package, end script execution with a # descriptive output. if [[ ${#PACKAGES_MISSING[*]} -eq 0 ]];then - cli_printMessage "`gettext "There are not missing packages."`" + cli_printMessage "`gettext "The required packages are already installed."`" cli_printMessage "$(caller)" 'AsToKnowMoreLine' fi diff --git a/Scripts/Bash/Functions/Verify/verify_doPackageInstall.sh b/Scripts/Bash/Functions/Verify/verify_doPackageInstall.sh index 2bd7339..b42f057 100755 --- a/Scripts/Bash/Functions/Verify/verify_doPackageInstall.sh +++ b/Scripts/Bash/Functions/Verify/verify_doPackageInstall.sh @@ -1,8 +1,7 @@ #!/bin/bash # -# verify_doPackages.sh -- This function receives a list of missing -# list of packages to install and achieve the package installation -# using `yum' command. +# verify_doPackageInstall.sh -- This function receives a list of +# missing packages and installs them using sudo yum. # # Copyright (C) 2009-2010 Alain Reguera Delgado # diff --git a/Scripts/Bash/Functions/Verify/verify_getActions.sh b/Scripts/Bash/Functions/Verify/verify_getActions.sh index 41a87cc..c021da5 100755 --- a/Scripts/Bash/Functions/Verify/verify_getActions.sh +++ b/Scripts/Bash/Functions/Verify/verify_getActions.sh @@ -32,14 +32,17 @@ function verify_getActions { ;; --links ) - verify_pathToCli - verify_pathToFonts - verify_pathToInkscape + verify_doLinks ;; --environment ) ;; + --all ) + verify_doPackages + verify_doLinks + ;; + * ) cli_printMessage "`gettext "The option provided is not valid."`" cli_printMessage "$(caller)" "AsToKnowMoreLine"