improved code quality, few bug fixes
This commit is contained in:
@@ -1,3 +1,4 @@
|
||||
#!/bin/bash
|
||||
# ------------------------------------------------------------------------------
|
||||
# File manipulation function
|
||||
# This file is part of the init.sh project
|
||||
@@ -34,7 +35,7 @@ backup_dist()
|
||||
if [[ -L ${file} ]]; then
|
||||
# With symbolik links we call again backup_dist to treat target
|
||||
prnt I "Following the symbolic link $file to do a proper backup..."
|
||||
backup_dist $(readlink -f ${file})
|
||||
backup_dist $(readlink -f "${file}")
|
||||
elif [[ -f ${file} ]]; then
|
||||
prnt I "Creating a backup of ${file} on $tmstmp..."
|
||||
cp -av $file ${file}.dist.${tmstmp}
|
||||
@@ -134,7 +135,7 @@ install_file()
|
||||
prnt E "install_file(): At least two arguments are required."
|
||||
die 11
|
||||
fi
|
||||
if [[ $(echo $@ | grep "\*\|\?") ]]; then
|
||||
if [[ -n $(echo $@ | grep "\*\|\?") ]]; then
|
||||
prnt E "install_file(): Wildcards are not authorized."
|
||||
die 7
|
||||
fi
|
||||
@@ -215,7 +216,7 @@ is_dir_empty()
|
||||
return 0
|
||||
fi
|
||||
|
||||
nbfiles=$(ls -a1 $dir | egrep -v '^.$|^..$' | wc -l)
|
||||
nbfiles=$(ls -a1 $dir | grep -Evc '^.$|^..$')
|
||||
if [[ $nbfiles -eq 0 ]]; then
|
||||
return 0
|
||||
fi
|
||||
@@ -240,7 +241,7 @@ patch_file()
|
||||
|
||||
# Create a sub-process, to avoid bash environment pollution
|
||||
(
|
||||
local varlist= pattern=
|
||||
local varlist='' pattern=''
|
||||
if [[ $# -eq 0 ]] ; then
|
||||
pattern="-e s/<\(.*\)>/\$\1\$\1/g"
|
||||
else
|
||||
@@ -249,7 +250,6 @@ patch_file()
|
||||
if ! declare -p $var >/dev/null 2>&1 ; then
|
||||
local $var=$(eval echo \$$var)
|
||||
fi
|
||||
export $var
|
||||
pattern="$pattern -e s/@$var@/\$$var/g"
|
||||
varlist=$varlist\$$var
|
||||
done
|
||||
|
||||
Reference in New Issue
Block a user