-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrepository.sh
87 lines (70 loc) · 2.54 KB
/
repository.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
#!/bin/sh
SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null && pwd )"
# Remove trailing slash from arguments
repo_path="${1%/}"
env_path="${2%/}"
display_usage() {
cat << USAGE
Usage: sh `basename $0` WHAT WHERE
Link dotfiles from repository into given environment.
Main purpose of this script is to manages dependencies. Recursively links other
dotfiles which must be added into environment.
WHAT
One of subdirectory (config set) from repository directory.
WHERE
One from subdirectory from environment directory.
COMMAND
-h|--help Display this message.
Example
sh `basename $0` repository/bashrc environment/mrogacki@homepc
sh `basename $0` -h
USAGE
}
for arg in "$@"; do
if [ "$arg" = "-h" -o "$arg" = "--help" ]; then
display_usage
exit
fi
done
repo_full_path="$SCRIPT_DIR/$repo_path"
if [ ! -d "$repo_full_path" ]; then
>&2 echo "Not existing repository. Directory does not exists $repo_full_path"
exit 1
fi
env_full_path="$SCRIPT_DIR/$env"
if [ ! -d "$env_full_path" ]; then
>&2 echo "Not existing environment. Directory does not exists $env_full_path"
exit 1
fi
link_repository() {
arg_repo_path="$1"
arg_env_path="$2"
arg_prefix="$3"
arg_repo_full_path="$SCRIPT_DIR/$arg_repo_path"
arg_env_full_path="$SCRIPT_DIR/$arg_env_path"
# easier than check if already exists with same link
unlink "$arg_env_full_path/`basename $arg_repo_path`" 2>/dev/null
echo "${arg_prefix}Install `basename $arg_repo_path` in `basename $arg_env_path`"
ln -s ../../"$arg_repo_path" $arg_env_path
# cd "$env_dir";
# easier than check if already exists with same link
# dotfile=`basename "$repository"`
# unlink "$dotfile" 2>/dev/null
# echo "Install $dotfile in $env_dir"
# ln -s ../../"$repository"
dependency_repo_path=$arg_repo_path/dotfiles.dep
dependency_repo_full_path="$SCRIPT_DIR/$dependency_repo_path"
if [ ! -f "$dependency_repo_full_path" ]; then
exit 0;
fi
for dependency_repo_name in `cat "$dependency_repo_full_path"`; do
dependency_repo_path="repository/$dependency_repo_name"
dependency_repo_full_path="$SCRIPT_DIR/$dependency_repo_path"
if [ -d "$dependency_repo_full_path" ]; then
link_repository "$dependency_repo_path" "$arg_env_path" "$arg_prefix "
else
>&2 echo "Not existing dependency repository. Directory does not exists: $dependency_repo_full_path. Dependency file: $dependency_repo_path"
fi
done
}
link_repository "$repo_path" "$env_path"