Make spellcheck happy
This commit is contained in:
parent
9abdfb89f9
commit
01b2abba57
1 changed files with 126 additions and 65 deletions
171
src/dotinstall
171
src/dotinstall
|
@ -32,11 +32,18 @@ die ()
|
||||||
# $1 : error message before quit
|
# $1 : error message before quit
|
||||||
# $2 : exit code - default 99
|
# $2 : exit code - default 99
|
||||||
# $3 : 1 if print usage
|
# $3 : 1 if print usage
|
||||||
|
local message
|
||||||
|
local code
|
||||||
|
local usage
|
||||||
|
|
||||||
[ -z $2 ] && $2=99
|
message="$1"
|
||||||
printf "\e[31mFATAL : %s\e[0m\n" "$1"
|
code="$2"
|
||||||
[ $3 == 1 ] && usage
|
usage="$3"
|
||||||
exit $2
|
|
||||||
|
[ -z "$code" ] && code=99
|
||||||
|
printf "\e[31mFATAL : %s\e[0m\n" "$message"
|
||||||
|
[ $usage -eq 1 ] && usage
|
||||||
|
exit $code
|
||||||
}
|
}
|
||||||
|
|
||||||
error ()
|
error ()
|
||||||
|
@ -44,7 +51,9 @@ error ()
|
||||||
# print error message in red
|
# print error message in red
|
||||||
# $@ : message
|
# $@ : message
|
||||||
|
|
||||||
printf "\e[31m%s\e[0m\n" "$*"
|
local message
|
||||||
|
message="$*"
|
||||||
|
printf "\e[31m%s\e[0m\n" "$message"
|
||||||
}
|
}
|
||||||
|
|
||||||
private:get_bootstrap_path ()
|
private:get_bootstrap_path ()
|
||||||
|
@ -52,15 +61,22 @@ private:get_bootstrap_path ()
|
||||||
# this function return the absolute path of the bootstrap file
|
# this function return the absolute path of the bootstrap file
|
||||||
# $* : path of bootstrap file
|
# $* : path of bootstrap file
|
||||||
|
|
||||||
|
local path
|
||||||
|
path="$*"
|
||||||
|
|
||||||
# If the path begin with /, this is an absolute part
|
# If the path begin with /, this is an absolute part
|
||||||
if [[ "$*" =~ ^/[[:graph:]]*$ ]]
|
if [[ "$path" =~ ^/[[:graph:]]*$ ]]
|
||||||
then
|
then
|
||||||
repository="$(dirname $*)"
|
repository="$(dirname "$path")"
|
||||||
return
|
return
|
||||||
fi
|
fi
|
||||||
|
|
||||||
local relative_path="$*"
|
local relative_path
|
||||||
local current_path="$(pwd)"
|
local current_path
|
||||||
|
|
||||||
|
current_path="$(pwd)"
|
||||||
|
relative_path="$path"
|
||||||
|
|
||||||
while [[ $relative_path =~ ^../[[:graph:]]*$ ]]
|
while [[ $relative_path =~ ^../[[:graph:]]*$ ]]
|
||||||
do
|
do
|
||||||
printf "We found ..\n"
|
printf "We found ..\n"
|
||||||
|
@ -75,18 +91,21 @@ private:remove_symblink()
|
||||||
# Remove a symblink
|
# Remove a symblink
|
||||||
# $* source
|
# $* source
|
||||||
|
|
||||||
|
local source
|
||||||
|
source="$*"
|
||||||
|
|
||||||
printf " -> Remove symblink %s : " "$symblink"
|
printf " -> Remove symblink %s : " "$symblink"
|
||||||
if [ -L "$*" ]
|
if [ -L "$source" ]
|
||||||
then
|
then
|
||||||
local ret;
|
local ret;
|
||||||
ret=$(rm "$*" 2>&1)
|
ret=$(rm "$*" 2>&1)
|
||||||
[ $? -ne 0 ] && { error "can't remove : $ret"; return; }
|
[ $? -ne 0 ] && { error "can't remove : $ret"; return; }
|
||||||
elif [ ! -f "$*" ]
|
elif [ ! -f "$source" ]
|
||||||
then
|
then
|
||||||
error "$* not exist"
|
error "$source not exist"
|
||||||
return
|
return
|
||||||
else
|
else
|
||||||
error "$* is not a symblink"
|
error "$source is not a symblink"
|
||||||
fi
|
fi
|
||||||
printf "\e[32mdone\e[0m\n"
|
printf "\e[32mdone\e[0m\n"
|
||||||
}
|
}
|
||||||
|
@ -97,8 +116,11 @@ private:create_symblink ()
|
||||||
# $1: source
|
# $1: source
|
||||||
# $2: destination
|
# $2: destination
|
||||||
|
|
||||||
local source="$1"
|
local source
|
||||||
local dest="$2"
|
local dest
|
||||||
|
|
||||||
|
source="$1"
|
||||||
|
dest="$2"
|
||||||
|
|
||||||
printf " -> Create a symblink from %s : " "$source"
|
printf " -> Create a symblink from %s : " "$source"
|
||||||
|
|
||||||
|
@ -116,9 +138,9 @@ private:create_symblink ()
|
||||||
error "can't overwrite destination"
|
error "can't overwrite destination"
|
||||||
return
|
return
|
||||||
else
|
else
|
||||||
rm -rf $dest
|
rm -rf "$dest"
|
||||||
fi
|
fi
|
||||||
elif [ -e $dest ]
|
elif [ -e "$dest" ]
|
||||||
then
|
then
|
||||||
error "destin ation exist but is not a directory"
|
error "destin ation exist but is not a directory"
|
||||||
return
|
return
|
||||||
|
@ -154,8 +176,14 @@ private:clone_repository ()
|
||||||
# $2 local repository
|
# $2 local repository
|
||||||
# return : local directory
|
# return : local directory
|
||||||
|
|
||||||
|
local url
|
||||||
|
local repo
|
||||||
local ret
|
local ret
|
||||||
ret=$(git clone -q "$1" "${2}" 2>&1)
|
|
||||||
|
url="$1"
|
||||||
|
repo="$2"
|
||||||
|
|
||||||
|
ret=$(git clone -q "$url" "$repo" 2>&1)
|
||||||
[[ $? -ne 0 ]] && die "Can't clone_repository : $ret" 20 0
|
[[ $? -ne 0 ]] && die "Can't clone_repository : $ret" 20 0
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -164,12 +192,21 @@ private:update_repository ()
|
||||||
# Update a git repository
|
# Update a git repository
|
||||||
# $1 : local repository
|
# $1 : local repository
|
||||||
|
|
||||||
[ ! -d "$1" ] && die "Git update : directory $1 does not exist" 25 0
|
local repo
|
||||||
local current_dir=$(pwd)
|
repo="$1"
|
||||||
|
|
||||||
|
[ ! -d "$repo" ] && die "Git update : directory $1 does not exist" 25 0
|
||||||
|
|
||||||
|
local current_dir
|
||||||
local ret
|
local ret
|
||||||
cd "$1"
|
|
||||||
|
current_dir=$(pwd)
|
||||||
|
|
||||||
|
cd "$repo" || die "Can't go to directory ${repo}"
|
||||||
ret=$(git pull 2>&1)
|
ret=$(git pull 2>&1)
|
||||||
[[ $? -ne 0 ]] && die "Can't update repository : $ret" 24 0
|
[[ $? -ne 0 ]] && die "Can't update repository : $ret" 24 0
|
||||||
|
|
||||||
|
cd "$current_dir" || die "Can't return to directory $current_dir"
|
||||||
}
|
}
|
||||||
|
|
||||||
process_dirs () {
|
process_dirs () {
|
||||||
|
@ -180,20 +217,22 @@ process_dirs () {
|
||||||
# $1: source directory
|
# $1: source directory
|
||||||
# $2: destination directory
|
# $2: destination directory
|
||||||
|
|
||||||
local source="${repository}/$1"
|
local source
|
||||||
local dest="$2"
|
source="${repository}/$1"
|
||||||
|
local dest
|
||||||
|
dest="$2"
|
||||||
printf "\nProcess directory %s\n" "$source"
|
printf "\nProcess directory %s\n" "$source"
|
||||||
|
|
||||||
[ ! -d "$source" ] && { error " -> source is not a directory"; return; }
|
[ ! -d "$source" ] && { error " -> source is not a directory"; return; }
|
||||||
[ ! -d "$dest" ] && { error " -> destination is not a directory"; return; }
|
[ ! -d "$dest" ] && { error " -> destination is not a directory"; return; }
|
||||||
|
|
||||||
while read d
|
while read -r d
|
||||||
do
|
do
|
||||||
if [ $install -eq 1 ]
|
if [ $install -eq 1 ]
|
||||||
then
|
then
|
||||||
private:create_symblink "$d" "${dest}/$(basename "$d")"
|
private:create_symblink "$d" "${dest}/$(basename "$d")"
|
||||||
else
|
else
|
||||||
local symblink="${dest}/$(basename ${d})"
|
local symblink="${dest}/$(basename "$d")"
|
||||||
private:remove_symblink "$symblink"
|
private:remove_symblink "$symblink"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
@ -207,20 +246,25 @@ process_files () {
|
||||||
# $1: source directory
|
# $1: source directory
|
||||||
# $2: destination directory
|
# $2: destination directory
|
||||||
|
|
||||||
local source="${repository}/$1"
|
local source
|
||||||
local dest="$2"
|
local dest
|
||||||
|
|
||||||
|
dest="$2"
|
||||||
|
source="${repository}/$1"
|
||||||
|
|
||||||
printf "Process files from directory %s:\n" "$source"
|
printf "Process files from directory %s:\n" "$source"
|
||||||
|
|
||||||
[ ! -d "$source" ] && { error " -> source is not a directory"; return; }
|
[ ! -d "$source" ] && { error " -> source is not a directory"; return; }
|
||||||
[ ! -d "$dest" ] && { error " -> destination is not a directory"; return; }
|
[ ! -d "$dest" ] && { error " -> destination is not a directory"; return; }
|
||||||
|
|
||||||
while read d
|
while read -r d
|
||||||
do
|
do
|
||||||
if [ $install -eq 1 ]
|
if [ $install -eq 1 ]
|
||||||
then
|
then
|
||||||
private:create_symblink "${source}/$d" "${dest}/$(basename "$d")"
|
private:create_symblink "${source}/$d" "${dest}/$(basename "$d")"
|
||||||
else
|
else
|
||||||
local symblink="${2}/$(basename ${d})"
|
local symblink
|
||||||
|
symblink="${dest}/$(basename ${d})"
|
||||||
private:remove_symblink "$symblink"
|
private:remove_symblink "$symblink"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
@ -234,30 +278,36 @@ install_service ()
|
||||||
# $1 file
|
# $1 file
|
||||||
# $2 1 to Activate the service
|
# $2 1 to Activate the service
|
||||||
|
|
||||||
local source="${repository}/$1"
|
local source
|
||||||
|
local activate
|
||||||
|
source="${repository}/$1"
|
||||||
|
activate=$2
|
||||||
local ret
|
local ret
|
||||||
[ ! -f "$source" ] && { error "$1 not found"; return; }
|
[ ! -f "$source" ] && { error "$1 not found"; return; }
|
||||||
local basename=$(basename "$source")
|
|
||||||
|
local basename
|
||||||
|
basename=$(basename "$source")
|
||||||
|
|
||||||
if [ $install -eq 1 ]
|
if [ $install -eq 1 ]
|
||||||
then
|
then
|
||||||
printf "\nInstall service %s :\n" "$source"
|
printf "\nInstall service %s :\n" "$source"
|
||||||
private:create_symblink "$source" "${SYD_DIRECTORY}/${basename}"
|
private:create_symblink "$source" "${SYD_DIRECTORY}/${basename}"
|
||||||
|
|
||||||
# activate service
|
# activate service
|
||||||
if [ $2 ]
|
if [ $activate -eq 1 ]
|
||||||
then
|
then
|
||||||
printf " -> Activate $basename : "
|
printf " -> Activate %s :" "$basename"
|
||||||
ret=$(systemctl --user enable ${basename} 2>&1)
|
ret=$(systemctl --user enable "${basename}" 2>&1)
|
||||||
[[ $? -ne 0 || ! $(systemctl --user is-enabled $basename) ]] && { error "$ret"; return; }
|
[[ $? -ne 0 || ! $(systemctl --user is-enabled "$basename") ]] && { error "$ret"; return; }
|
||||||
printf "\e[32mdone\e[0m\n"
|
printf "\e[32mdone\e[0m\n"
|
||||||
fi
|
fi
|
||||||
else
|
else
|
||||||
printf "\nUninstall service %s :\n" "$source"
|
printf "\nUninstall service %s :\n" "$source"
|
||||||
#Deactivate service
|
#Deactivate service
|
||||||
if [ $1 ]
|
if [ $activate -eq 1 ]
|
||||||
then
|
then
|
||||||
printf " -> Deactivate $basename : "
|
printf " -> Deactivate %s : " "$basename"
|
||||||
ret=$(systemctl --user disable ${basename} 2>&1)
|
ret=$(systemctl --user disable "${basename}" 2>&1)
|
||||||
[[ $? -ne 0 ]] && { error "$ret"; return; }
|
[[ $? -ne 0 ]] && { error "$ret"; return; }
|
||||||
printf "\e[32mdone\e[0m\n"
|
printf "\e[32mdone\e[0m\n"
|
||||||
fi
|
fi
|
||||||
|
@ -270,13 +320,16 @@ required_commands ()
|
||||||
# Check if an executable exist
|
# Check if an executable exist
|
||||||
# $1 executables separated with spaces
|
# $1 executables separated with spaces
|
||||||
|
|
||||||
|
local bins
|
||||||
|
bins="$*"
|
||||||
|
|
||||||
# if uninstall, we don't need to process required commands.
|
# if uninstall, we don't need to process required commands.
|
||||||
[ $install -eq 0 ] && return
|
[ $install -eq 0 ] && return
|
||||||
printf "Checking required programs :\n"
|
printf "Checking required programs :\n"
|
||||||
for p in $1
|
for bin in $bins
|
||||||
do
|
do
|
||||||
printf " -> %s:" "$p"
|
printf " -> %s:" "$bin"
|
||||||
command -v $p >/dev/null 2>&1 || die "not found" 128
|
command -v "$bin" >/dev/null 2>&1 || die "not found" 128
|
||||||
printf " \e[32mfound\e[0m\n"
|
printf " \e[32mfound\e[0m\n"
|
||||||
done
|
done
|
||||||
}
|
}
|
||||||
|
@ -287,8 +340,10 @@ install_bin ()
|
||||||
# Via a symbolic link
|
# Via a symbolic link
|
||||||
# $1 : path to script
|
# $1 : path to script
|
||||||
|
|
||||||
local source="${repository}/${1}"
|
local source
|
||||||
local dest="${BIN_DIRECTORY}/$(basename $1)"
|
source="${repository}/${1}"
|
||||||
|
local dest
|
||||||
|
dest="${BIN_DIRECTORY}/$(basename "$1")"
|
||||||
|
|
||||||
printf "\nProcess executable :\n"
|
printf "\nProcess executable :\n"
|
||||||
[ ! -f "$source" ] && { error "$source is not a file"; return; }
|
[ ! -f "$source" ] && { error "$source is not a file"; return; }
|
||||||
|
@ -308,21 +363,27 @@ define_env ()
|
||||||
# on uninstall mode
|
# on uninstall mode
|
||||||
# $1 variable name
|
# $1 variable name
|
||||||
# $2 value
|
# $2 value
|
||||||
|
local name
|
||||||
|
local value
|
||||||
|
|
||||||
|
name="$1"
|
||||||
|
value="$2"
|
||||||
|
|
||||||
|
[ -z "$name" ] && { error "You must define a name"; return; }
|
||||||
|
[ ! -f "$ENV_FILE" ] && touch "$ENV_FILE"
|
||||||
|
|
||||||
[ -z $1 ] && { error "You must define a name"; return; }
|
|
||||||
[ ! -f $ENV_FILE ] && touch $ENV_FILE
|
|
||||||
if [ $install -eq 1 ]
|
if [ $install -eq 1 ]
|
||||||
then
|
then
|
||||||
printf "\nCreate an environment variable %s : " "$1"
|
printf "\nCreate an environment variable %s : " "$name"
|
||||||
[ $(grep -c -m 1 $1 $ENV_FILE) -eq 1 ] && { error "already exist"; return; }
|
[ $(grep -c -m 1 "$name" "$ENV_FILE") -eq 1 ] && { error "already exist"; return; }
|
||||||
local line
|
local line
|
||||||
line="export ${1}=\"${2}\""
|
line="export ${name}=\"${value}\""
|
||||||
echo "$line" >> $ENV_FILE
|
echo "$line" >> "$ENV_FILE"
|
||||||
printf "\e[32mdone\e[0m\n"
|
printf "\e[32mdone\e[0m\n"
|
||||||
else
|
else
|
||||||
printf "\nRemove an environ ment variable %s : " "$1"
|
printf "\nRemove an environ ment variable %s : " "$1"
|
||||||
[ $(grep -c -m 1 $1 $ENV_FILE) -eq 0 ] && { error "not exist"; return; }
|
[ $(grep -c -m 1 "$1" "$ENV_FILE") -eq 0 ] && { error "not exist"; return; }
|
||||||
sed -i "/^export $1=*/d" $ENV_FILE
|
sed -i "/^export $1=*/d" "$ENV_FILE"
|
||||||
printf "\e[32mdone\e[0m\n"
|
printf "\e[32mdone\e[0m\n"
|
||||||
|
|
||||||
fi
|
fi
|
||||||
|
@ -354,7 +415,7 @@ then
|
||||||
required_commands "git"
|
required_commands "git"
|
||||||
|
|
||||||
# Check
|
# Check
|
||||||
localrepo="${DOTREPO}/$(basename $* .git)"
|
localrepo="${DOTREPO}/$(basename "$*" .git)"
|
||||||
if [ $update -eq 1 ]
|
if [ $update -eq 1 ]
|
||||||
then
|
then
|
||||||
private:update_repository "$localrepo"
|
private:update_repository "$localrepo"
|
||||||
|
@ -372,7 +433,7 @@ fi
|
||||||
[ ! -f "$bootstrap_file" ] && die "$bootstrap_file does not exist" 2 1
|
[ ! -f "$bootstrap_file" ] && die "$bootstrap_file does not exist" 2 1
|
||||||
|
|
||||||
private:get_bootstrap_path "$bootstrap_file"
|
private:get_bootstrap_path "$bootstrap_file"
|
||||||
cache_file="${CACHE_DIR}/$(echo $repository | tr '/' '_')"
|
cache_file="${CACHE_DIR}/$(echo "$repository" | tr '/' '_')"
|
||||||
|
|
||||||
if [ $update -eq 1 ]
|
if [ $update -eq 1 ]
|
||||||
then
|
then
|
||||||
|
@ -405,8 +466,8 @@ source "$bootstrap_file"
|
||||||
if [ $install -eq 0 ]
|
if [ $install -eq 0 ]
|
||||||
then
|
then
|
||||||
printf "\nRemove files for complete uninstall\n"
|
printf "\nRemove files for complete uninstall\n"
|
||||||
rm $cache_file
|
rm "$cache_file"
|
||||||
rm -rf $repository
|
rm -rf "$repository"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
exit 0
|
exit 0
|
||||||
|
|
Reference in a new issue