-
Notifications
You must be signed in to change notification settings - Fork 0
/
dependencies.sh
executable file
·99 lines (88 loc) · 2.9 KB
/
dependencies.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
94
95
96
97
98
#!/bin/bash
PROJECT_ROOT=$(realpath $(dirname $0))
DEPENDENCIES_DIR="$PROJECT_ROOT/external_dependencies"
DEPENDENCIES_INCLUDE_DIR="$DEPENDENCIES_DIR/include"
DEPENDENCIES_OBJS_DIR="$DEPENDENCIES_DIR/objs"
DEPENDENCIES_LOCAL_OBJS_DIR="$DEPENDENCIES_DIR/local_objs"
DEPENDENCY_MANAGER_DIR="$PROJECT_ROOT/.assertions/dependency_manager"
DEPENDENCY_MANAGER_MODULES_DIR="$DEPENDENCY_MANAGER_DIR/modules"
mkdir -p "$DEPENDENCIES_INCLUDE_DIR"
mkdir -p "$DEPENDENCIES_OBJS_DIR"
mkdir -p "$DEPENDENCIES_LOCAL_OBJS_DIR"
############### Command Line Interface ##################
print_help () {
echo "Help:"
echo "Manage dependencies for the project"
echo
echo "Usage: ./dependencies.sh ACTION"
echo
echo "ACTION:"
echo " add: add new dependency to the project. Use './dependencies.sh add --help' for more information"
echo " remove: remove dependency from the project. Use './dependencies.sh remove --help' for more information"
echo " clean: delete all downloaded dependencies (everything inside ./external_dependencies)"
echo " install: download and configure all dependencies. Use '--ignore-local-dependencies' to not install dependencies marked as local-only"
echo " list: list all project's dependencies"
}
log_info () {
echo "Info: $1"
}
log_error () {
echo "Error: $1" 1>&2
}
freeze_args () {
echo "Info: dependency configured: $1"
}
determine_dependency_list_is_empty() {
DEPENDENCY_LIST=$(awk FNR!=1 "$DEPENDENCY_MANAGER_DIR/install.sh")
if [ "$DEPENDENCY_LIST" == "" ]; then
DEPENDENCY_LIST_IS_EMPTY=true
else
DEPENDENCY_LIST_IS_EMPTY=""
fi
}
if [ "$1" == "--help" ]; then
print_help
exit 0
elif [ "$1" == "add" ]; then
shift
source "$PROJECT_ROOT/.assertions/dependency_manager/add.sh"
touch "$DEPENDENCIES_DIR"
elif [ "$1" == "remove" ]; then
shift
source "$PROJECT_ROOT/.assertions/dependency_manager/remove.sh"
touch "$DEPENDENCIES_DIR"
elif [ "$1" == "clean" ]; then
echo "Are you sure you want to delete all downloaded dependencies? (y/n)"
read CONFIRMATION
if [ "${CONFIRMATION[0]}" == "y" ] || [ "${CONFIRMATION[1]}" == "Y" ]; then
rm -rf "$PROJECT_ROOT/external_dependencies"
echo "Info: Downloaded dependencies deleted"
else
echo "Info: Operation canceled"
fi
elif [ "$1" == "list" ]; then
determine_dependency_list_is_empty
if [ $DEPENDENCY_LIST_IS_EMPTY ]; then
echo "Info: project has no external dependencies"
else
echo "$DEPENDENCY_LIST" | sed "s/\/install\.sh//g; s/^source\s\+//g"
fi
elif [ "$1" == "install" ]; then
determine_dependency_list_is_empty
if [ $DEPENDENCY_LIST_IS_EMPTY ]; then
echo "Info: project has no external dependencies"
else
if [ "$2" == "--ignore-local-dependencies" ]; then
export IGNORE_LOCAL_DEPENDENCIES=true
fi
cd "$DEPENDENCY_MANAGER_DIR/modules"
source "$DEPENDENCY_MANAGER_DIR/install.sh"
touch "$DEPENDENCIES_DIR"
fi
else
echo "Error: unknown action '$1'"
echo
print_help
exit 1
fi
############### Command Line Interface ##################