-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathplugins.sh
129 lines (116 loc) · 2.81 KB
/
plugins.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
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
set -euo pipefail
: ${AWSM_PLUGINS_HOST_URL='awsm-plugins.s3-website-ap-southeast-2.amazonaws.com/plugins.json'}
function list {
curl $AWSM_PLUGINS_HOST_URL 2>/dev/null | jq -r -S 'keys | join("\n")'
}
function pad {
printf ' '
}
function fail {
local message=$1
if [ -n "$message" ]; then
echo $message
fi
exit 1
}
function install {
local plugin=$1
local source_name=awsm-$plugin
local source=$(curl $AWSM_PLUGINS_HOST_URL 2>/dev/null | jq -r -S ".\"$plugin\".source")
if [ -n "$source" ]; then
echo -e "Installing $plugin from $source"
cd $AWSM_PLUGINS_DIR
if [ -d "$source_name" ]; then
fail "Error: $plugin already installed"
else
git clone $source $source_name
echo "$plugin successfully installed"
fi
fi
}
function uninstall {
local plugin=$1
local source_name=awsm-$plugin
if [ -n "$plugin" ]; then
echo -e "Uninstalling $plugin"
cd $AWSM_PLUGINS_DIR
if [ ! -d "$source_name" ]; then
fail "Error: $plugin not installed"
else
cd $source_name && rm -rf * && cd .. && rm -rf $source_name
echo "$plugin successfully uninstalled"
fi
fi
}
function update_plugin {
local plugin_dir=$1
cd $1
git pull origin master 2>/dev/null && echo "Updated $plugin_dir"
}
function check_plugin {
local dir=$1
cd $dir
local local_rev=$(git rev-parse @)
local remove_rev=$(git rev-parse @{u})
local base_rev=$(git merge-base @ @{u})
local base=$(basename `pwd`)
local plugin=${base#awsm-}
if [ $local_rev = $remove_rev ]; then
echo "$plugin is up to date"
elif [ $local_rev = $base_rev ]; then
echo "$plugin has update available"
elif [ $remove_rev = $base_rev ]; then
echo "$plugin need to be pushed"
else
echo "$plugin has diverged"
fi
}
function check {
if [ -z "${1-}" ]; then
echo "Error: Unsupported option"
exit 1
fi
local plugin=$1
local source_name=awsm-$plugin
if [ "$plugin" == "--all" ]; then
echo "Checking all"
cd "$AWSM_PLUGINS_DIR"
for f in $AWSM_PLUGINS_DIR/*; do
if [ -d "$f" ]; then
check_plugin $f
fi
done
else
local plugin_dir="$AWSM_PLUGINS_DIR/$source_name"
if [ -d "$plugin_dir" ]; then
cd "$plugin_dir"
check_plugin "$plugin_dir"
else
echo "Error: $plugin not found"
fi
fi
}
function update {
if [ -z "${1-}" ]; then
echo "Error: Unsupported option"
exit 1
fi
local plugin=$1
if [ "$plugin" == "--all" ]; then
echo "Updating all"
cd "$AWSM_PLUGINS_DIR"
for f in $AWSM_PLUGINS_DIR/*; do
if [ -d "$f" ]; then
update_plugin $f
fi
done
else
local plugin_dir="$AWSM_PLUGINS_DIR/$plugin"
if [ -d "$plugin_dir" ]; then
cd "$plugin_dir"
update_plugin "$plugin_dir"
else
echo "Error: no such plugin $plugin"
fi
fi
}