equal
deleted
inserted
replaced
|
1 ## Compare symlink to target: |
|
2 # |
|
3 # link_check $lnk $tgt && do_link $lnk $tgt || ... |
|
4 # |
|
5 # Tests if the symlink exists, and the target matches. |
|
6 # Fails if the symlink needs updating. |
|
7 function link_check { |
|
8 local out="$1" |
|
9 local lnk="$2" |
|
10 |
|
11 [ -e "$out" ] || return 1 |
|
12 |
|
13 [ -L "$out" ] || fail "$out: is not a link" |
|
14 |
|
15 [ "$(readlink "$out")" == "$lnk" ] || return 1 |
|
16 |
|
17 return 0 |
|
18 } |
|
19 |
|
20 ## Update symlink to point to target: |
|
21 # |
|
22 # do_link $lnk $tgt |
|
23 # |
|
24 function link_apply { |
|
25 local out="$1" |
|
26 local lnk="$2" |
|
27 |
|
28 cmd ln -srf "$lnk" "$out" |
|
29 |
|
30 [ -e "$out" ] || fail "$out: given target does not exist: $lnk" |
|
31 } |
|
32 |
|
33 # Create symlink if not exists. |
|
34 function apply_link { |
|
35 local out="$1" |
|
36 local lnk="$2" |
|
37 |
|
38 if link_check "$out" "$lnk"; then |
|
39 log_skip "$out: not changed: $lnk" |
|
40 elif [ "$APPLY" = 0 ]; then |
|
41 log_noop "$out: skip link: $tgt" |
|
42 else |
|
43 log_apply "$out: $tgt..." |
|
44 |
|
45 link_apply "$out" "$lnk" |
|
46 fi |
|
47 } |