-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdistribute.sh
executable file
·93 lines (74 loc) · 2.27 KB
/
distribute.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
#!/bin/bash
config="./special.conf"
base=$HOME
computer=$HOSTNAME
_pwd=$PWD
# -----------------
submodules=`cat .gitmodules | grep submodule | cut -d\" -f2`
# Removing submodules folder from 'allfill' list
for i in $submodules; do
extract_folders+="-not -path \"./$i/*\" "
done
find_command="find ./home/ -type f $extract_folders"
allfil=$(eval $find_command)
# Handling config file (special.conf)
while read line
do
[[ $line == \#* ]] && continue
[[ -z $line ]] && continue
[[ $line == \[* ]] && cond=`echo $line | cut -d[ -f 2 | cut -d] -f 1` && continue
case $cond in
ignore)
# simply remove the file from find list if exist
if [ -a $base/$line ]; then
allfil=`echo "$allfil" | sed -e "s@./home/$line@@g"`
fi
;;
unique)
# remove the unique files2
allfil=`echo "$allfil" | sed -e 's|\.\/home\/'$line'--[^$ ]*||g'`
fil="/$line"
if [ ! -f ./home/$fil--$computer ]; then
echo "$line without specific version for the machine $computer."
continue
fi
cp -p ./home/$fil--$computer $base$fil
echo "cp $base$fil from $line--$computer"
;;
esac
done < $config
# Handling submodule cases
for k in $submodules; do
dir=`dirname $k | sed -e "s/^\.//" | sed -e "s/home//" | sed -e "s/$/\//"`
fil=`basename $k`
if [ ! -s $base$dir$fil ]; then
mkdir -p $base$dir
ln -s $_pwd/$k $base$dir$fil
[ $? == 0 ] && echo "[submodules] Link created: $_pwd/$k -> $base$dir$fil"
else
if [ ! -L $base$dir$fil ]; then
echo "[submodules] Conflict: The folder $base$dir$fil should be a link to $_pwd/$k"
elif [ -L $base$dir$fil ]; then
rm $base$dir$fil
ln -s $_pwd/$k $base$dir$fil
echo "[submodules] Link created: $_pwd/$k -> $base$dir$fil"
fi
fi
done
IFS=$'\n'
for k in $allfil; do
dir=`dirname $k | sed -e "s/^\.//" | sed -e "s/\/home//" | sed -e "s/$/\//"`
fil=`basename $k`
if [ ! -d $base$dir ]; then
mkdir -p $base$dir
fi
if [[ $fil == *$computer* ]]; then
echo "$dir$fil was in the [unique] case. Now, it is not. Fix it manually."
continue
fi
# if [ ./home/$dir$fil -nt $base$dir$fil ]; then # f1 is newer than f2
cp -p ./home/$dir$fil $base$dir$fil
echo "cp $base$dir$fil"
# fi
done
exit 0