/
functions
192 lines (163 loc) · 4.67 KB
/
functions
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
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
#!/bin/sh
ext_help()
{
modules api/help
description "BDSM extension ext management"
action "ext" "List installed ext."
action "ext known" "List extension ext that can be installed."
action_separator
action "ext install all" "Install all extension ext found on the known list."
action "ext install {name}" "Install extension {name} found on the known list."
action "ext install {name} {uri}" "Install extension {name} from the given {uri}."
action "ext add" "Shortcut for install."
action_separator
action "ext update all" "Update all extension ext using remembered uris."
action "ext update {name}" "Update extension {name} using remembered uri."
action "ext up" "Shortcut for update."
action_separator
action "ext uninstall {name}" "Remove extension {name}."
action "ext del" "Shortcut for uninstall."
action_separator
action "ext help" "Show this help."
show_help usage
}
ext_list()
{
local extensions COLUMNS=80
if __sm.extension.in "${exts_system_path}/active"
then
log "exts: #system"
echo ${found_extensions[@]} | xargs -s ${COLUMNS} | xargs -I '{}' echo " - {}"
else
log "# No single system extensions (exts) are currently installed."
fi
if [[ "${exts_system_path}" != "${exts_user_path}" ]]
then
if __sm.extension.in "${exts_user_path}/active"
then
log "exts: #user"
echo ${found_extensions[@]} | xargs -s ${COLUMNS} | xargs -I '{}' echo " - {}"
else
log "# No single user extensions (exts) are currently installed."
fi
fi
}
ext_list_known()
{
local COLUMNS=80
printf "# %18s | %s\n" "Extension name" "Repository"
while read line
do
printf "%20s %s\n" "${line/=*}" "${line/*=}"
done < "${sm_path}/core/cli/config/known_ext"
}
ext_install()
{
local _name _names="$1" _uri="$2"
shift || __sm.log.fail "No extension name was given."
_names=(${_names//,/ })
_extension_namespace="${exts_user_path#${sm_path}\/}"
_extension_namespace="${_extension_namespace#${sm_user_path}\/}"
_extension_namespace="${_extension_namespace/\/active/}"
for _name in ${_names[@]}
do
__sm.log.step "Installing ${_name} in ${_extension_namespace//\// }" \
extension install as "${_name}" ${_uri:+from} ${_uri}
done
}
ext_install_all()
{
local _ext _name _uri COLUMNS=80
while read _ext
do
[[ "${line}" != \#* ]] || continue
_name="${_ext/=*}"
_uri="${_ext/*=}"
ext_install "${_name}" "${_uri}" --on-fail true
done < "${sm_path}/core/cli/config/known_exts"
}
ext_update()
{
local _name _uri
(( $# > 0 )) ||
__sm.log.error "Cannot update extension ext without name."
for _name in "$@"
do
if [[ ! -d "${exts_user_path}/active/${_name}" ]]
then
if [[ -d "${exts_system_path}/active/${_name}" ]]
then
__sm.log.error "Extension ${_name} is in system exts and cannot be updated."
else
__sm.log.error "Extension ${_name} does not exist."
fi
fi
if [[ ! -s "${exts_user_path}/active/${_name}/.uri" ]]
then
__sm.log.warn "Extension ${_name} does not contain stored uri."
continue
fi
_uri=$( __sm.vcs.read_uri "${exts_user_path}/active/${_name}/.uri" )
if [[ -z "${_uri}" ]]
then
__sm.log.warn "Extension ${_name} does not contain stored uri."
else
ext_install "${_name}" "${_uri}"
fi
done
}
ext_update_all()
{
local _name _entries=( "${exts_user_path}"/* )
if (( ! "${#_entries[@]}" ))
then
__sm.log.error "No extensions found for update."
fi
for _name in "${_entries[@]}"
do
[[ -d "${sets_user_path}/active/${_name}" ]] || continue
ext_update "${_name##*/}"
done
}
ext_uninstall()
{
local _name="$1"
case "${_name}" in
*/*|.|..)
__sm.log.error "Please specify a valid extension name."
;;
esac
if [[ ! -d "${exts_user_path}/active/${_name}" ]]
then
if [[ -d "${exts_system_path}/active/${_name}" ]]
then
__sm.log.error "Extension ${_name} is in system exts and cannot be uninstalled."
else
__sm.log.error "Extension ${_name} does not exist."
fi
fi
versionedfs remove \
path "${exts_user_path}" name "${_name}"
}
ext_check_availability()
{
local _ext _line _args=($@)
# TODO: refactor this to take argument of uri to check instead.
# provide check_known_exts_availability or some such to wrap this.
while read _ext
do
case "$line" in
(^#)
true # Skipt comment lines
;;
(*)
while read _line
do
[[ "${_line}" == Status* ]] || continue
echo "${_ext/=*}" "${_line/*:}"
break
done < <(curl -s --head https://github.com/sm/sm_"${_ext/=*}")
;;
esac
done < "${sm_path}/core/cli/config/known_ext"
}