-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbashly.sh
More file actions
executable file
·55 lines (46 loc) · 1.33 KB
/
bashly.sh
File metadata and controls
executable file
·55 lines (46 loc) · 1.33 KB
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
#!/usr/bin/bash
if [[ "$(basename -- "$0")" != "bashly.sh" ]]; then
>&2 echo "Cannot be run. Use source $0"
exit 1
fi
unset BASHLY_PATH
export BASHLY_PATH="$(cd "$(dirname "$0")"; pwd)/sources"
function import() {
package=$1
package=${BASHLY_PATH}/${package//:/\/}
# version greater equal
pieces=(${package//+/+ })
if [[ ${#pieces[@]} > 1 ]]; then
for i in ${!pieces[*]}; do
piece=${pieces[i]}
if [[ "${piece: -1}" != "+" ]]; then
continue
fi
version=$(basename -- ${piece:1:-1})
parent=${piece%\/*}
for folder in $(ls $parent)
do
if [[ "$folder" > "$version" || "$folder" == "$version" ]]
then
version=$folder
solution=$folder
fi
done
if [[ -z $solution ]]; then
>&2 echo "Could not resolve version"
return 1
else
pieces[$i]="$parent/$solution"
fi
done
package=$(IFS=;echo "${pieces[*]}")
fi
if [[ -f ${package}.sh ]]; then
source ${package}.sh
elif [[ -d $package ]]; then
source $package/*.sh
else
>&2 echo "Did not find $package"
fi
return 0
}