-
-
Notifications
You must be signed in to change notification settings - Fork 14
/
require
27 lines (26 loc) · 950 Bytes
/
require
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
#########################
# archibold.io (C) 2016 #
#########################
require() {
local pkg="$1"
local tmp=$(type -t $pkg)
if [ "$tmp" != "function" ] && [ "$tmp" != "file" ]; then
if curl --output /dev/null --silent --head --fail "https://archibold.io/utils/$pkg"; then
tmp=$(mktemp /tmp/archibold.XXXXXXXX)
curl -Lso $tmp https://archibold.io/utils/$pkg
if [[ "$(cat $tmp | grep -sn '^#!/usr/bin/env ')" =~ ^1:#* ]]; then
chmod a+x $tmp
pkg="$pkg(){ $tmp \"\$@\"; }"
tmp=$(mktemp /tmp/archibold.XXXXXXXX)
echo "$pkg" > $tmp
fi
source $tmp
elif curl --output /dev/null --silent --head --fail "https://archibold.io/install/$pkg"; then
echo -e "Installing \x1B[1m$pkg\x1B[22m"
bash <(curl -s https://archibold.io/install/$pkg)
else
echo -e "\x1B[1m\x1B[31mError\x1B[39m\x1B[22m: unable to import \x1B[1m$pkg\x1B[22m"
exit 1
fi
fi
}