ajout meilleur gestion symlink pour install
This commit is contained in:
40
install.sh
40
install.sh
@@ -1,4 +1,5 @@
|
|||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
|
cd $(dirname $0)
|
||||||
|
|
||||||
# COLORS
|
# COLORS
|
||||||
source ./asides/color.sh
|
source ./asides/color.sh
|
||||||
@@ -14,9 +15,10 @@ mkdir -p ~/.vim/swapfiles
|
|||||||
# receive 1 argument : absolute path to config file
|
# receive 1 argument : absolute path to config file
|
||||||
function save_bak
|
function save_bak
|
||||||
{
|
{
|
||||||
file_to="$1"
|
local file_to="$1"
|
||||||
file_name="$(basename $1)"
|
local file_name="$(basename $1)"
|
||||||
path_file_to="$(dirname $1)"
|
local path_file_to="$(dirname $1)"
|
||||||
|
|
||||||
number=0
|
number=0
|
||||||
while [ -f $file_to.hubak$number ]
|
while [ -f $file_to.hubak$number ]
|
||||||
do
|
do
|
||||||
@@ -24,9 +26,9 @@ function save_bak
|
|||||||
done
|
done
|
||||||
echo -en $YELLOW"in "
|
echo -en $YELLOW"in "
|
||||||
echo -en $CYAN"\"$path_file_to/\""
|
echo -en $CYAN"\"$path_file_to/\""
|
||||||
echo -en $YELLOW", mv "
|
echo -en $YELLOW", saving "
|
||||||
echo -en $CYAN"\"$file_name\""
|
echo -en $CYAN"\"$file_name\""
|
||||||
echo -en $YELLOW" to "
|
echo -en $YELLOW" as "
|
||||||
echo -en $CYAN"\"$file_name.hubak$number\""$ENDCO"\n"
|
echo -en $CYAN"\"$file_name.hubak$number\""$ENDCO"\n"
|
||||||
mv $file_to $file_to.hubak$number
|
mv $file_to $file_to.hubak$number
|
||||||
}
|
}
|
||||||
@@ -34,18 +36,38 @@ function save_bak
|
|||||||
# receive 1 argument : absolute path to config file
|
# receive 1 argument : absolute path to config file
|
||||||
function install
|
function install
|
||||||
{
|
{
|
||||||
file_to="$1"
|
local file_to="$1"
|
||||||
file_name="$(basename $1)"
|
local file_name="$(basename $1)"
|
||||||
path_file_to="$(dirname $1)"
|
local path_file_to="$(dirname $1)"
|
||||||
if [ -f $file_to ]
|
|
||||||
|
local create_sym=1
|
||||||
|
|
||||||
|
if [ -h $file_to ] && [ ! -e $file_to ]
|
||||||
then
|
then
|
||||||
|
echo -en $B_RED"$file_to is a broken symlink"$ENDCO"\n"
|
||||||
save_bak $file_to
|
save_bak $file_to
|
||||||
|
elif [ -e $file_to ]
|
||||||
|
then
|
||||||
|
if [ ! "$(realpath "$file_to")" = "$HERE/config_files/$file_name" ]
|
||||||
|
then
|
||||||
|
echo -en $YELLOW"$file_to exist but is not the right file"$ENDCO"\n"
|
||||||
|
save_bak $file_to
|
||||||
|
else
|
||||||
|
create_sym=0
|
||||||
|
echo -en $YELLOW"$file_to is already the right file"$ENDCO"\n"
|
||||||
fi
|
fi
|
||||||
|
else
|
||||||
|
echo -en $YELLOW"$file_to doesn't exist"$ENDCO"\n"
|
||||||
|
fi
|
||||||
|
|
||||||
|
if [ $create_sym -eq 1 ]
|
||||||
|
then
|
||||||
echo -en $YELLOW"create symlink of "
|
echo -en $YELLOW"create symlink of "
|
||||||
echo -en $CYAN"\"$file_name\""
|
echo -en $CYAN"\"$file_name\""
|
||||||
echo -en $YELLOW" in "
|
echo -en $YELLOW" in "
|
||||||
echo -en $CYAN"\"$path_file_to\""$ENDCO"\n"
|
echo -en $CYAN"\"$path_file_to\""$ENDCO"\n"
|
||||||
ln -s $HERE/$D_CONFIG_FILES/$file_name $file_to
|
ln -s $HERE/$D_CONFIG_FILES/$file_name $file_to
|
||||||
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
# argument : directory where the config file should go
|
# argument : directory where the config file should go
|
||||||
|
|||||||
Reference in New Issue
Block a user