-
Notifications
You must be signed in to change notification settings - Fork 0
/
link_folder_scripts
executable file
·354 lines (308 loc) · 9.85 KB
/
link_folder_scripts
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
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
#!/usr/bin/env bash
#
# @author Zeus Intuivo <[email protected]>
#
#
# set -xu -E
set -u -E
export USER_HOME
export _no_typesetg
typeset -i _no_typesetg=0
export _err
typeset -i _err=0
if ( ! command -v getent >/dev/null 2>&1; ) ; then
{
function getent () {
if [[ -n "${1-}" ]] && [[ -n "${2-}" ]] ; then
{
if [[ "${1}" == hosts ]] ; then
{
sed 's/#.*//' "/etc/${1}" | grep -w "${2}"
}
elif [[ "${2-}" == *"-"* ]] ; then
{
grep ":$2:[^:]*$" "/etc/${1}"
}
else
{
grep "^$2:" "/etc/${1}"
}
fi
}
fi
} # end getent
}
fi
# set -x
getent passwd "${USER-}"
_err=$?
if [ ${_err} -eq 0 ] && ( command -v cut >/dev/null 2>&1; ) ; then
{
typeset -rg USER_HOME=$(getent passwd "${USER-}" | cut -d: -f6)
_err=$?
if [ ${_err} -ne 0 ] ; then
{
_no_typesetg=1
typeset -r USER_HOME=$(getent passwd "${USER-}" | cut -d: -f6)
_err=$?
}
fi
}
fi
if [ ${_err} -ne 0 ] ; then
{
if [[ -n "${HOME-}" ]] ; then
{
typeset -r USER_HOME="${HOME}"
_err=$?
}
elif [[ -n "${USER-}" ]] ; then
{
if [[ -d "/Users/${USER}" ]] ; then
{
typeset -r USER_HOME="/Users/${USER}"
_err=$?
}
elif [[ -d "/home/${USER}" ]] ; then
{
typeset -r USER_HOME="/home/${USER}"
_err=$?
}
else
{
_err=1
}
fi
}
else
{
_err=1
}
fi
}
fi
if [ ${_err} -ne 0 ] ; then
{
echo "ERROR Cannot assign HOME or USER"
}
fi
if [[ -z "${USER_HOME-}" ]] ; then
{
echo "ERROR Cannot empty USER_HOME"
exit 1
}
fi
ls "${USER_HOME-}"
_err=$?
if [ ${_err} -ne 0 ] ; then
{
echo "ERROR Cannot find valid USER_HOME"
exit 1
}
fi
export DEBUG
if (( _no_typesetg )) ; then
{
typeset -rg DEBUG=0
_err=$?
if [ ${_err} -ne 0 ] ; then
{
typeset -r DEBUG=0
_err=$?
_no_typesetg=1
}
fi
}
else
{
typeset -r DEBUG=0
_err=$?
}
fi
load_execute_command(){
# : Execute "${@}"
#
# !!! ¡ ☠ Say error "${@}" and exit
#
# - Anounce "${@}"
# · • Say "${@}"
# “ Comment "${@}"
#
local URL=""
local EXECOMCLI=""
local provider=""
[[ -d "${USER_HOME-}/_/clis/execute_command_intuivo_cli/" ]] && provider="file://${USER_HOME-}/_/clis/execute_command_intuivo_cli/"
[[ ! -d "${USER_HOME-}/_/clis/execute_command_intuivo_cli/" ]] && provider="https://raw.githubusercontent.com/zeusintuivo/execute_command_intuivo_cli/master/"
local BASH_SCRIPTS="
execute_command
struct_testing
"
while read -r ONE_SCRIPT; do
# if not empty
if [[ ! -z "${ONE_SCRIPT}" ]] ; then
URL="${provider}${ONE_SCRIPT}"
EXECOMCLI=$(curl "${URL}" 2>/dev/null ) # suppress only curl download messages, but keep curl output for variable
eval """${EXECOMCLI}"""
anounce "${URL} Loaded"
fi
done <<< "${BASH_SCRIPTS}"
unset URL
unset EXECOMCLI
unset ONE_SCRIPT
unset BASH_SCRIPTS
unset provider
return 0
} # end function load_execute_command
load_execute_command
sudo echo "Starting"
remove_all_starting_with_journal_get(){
sed '/^journal_get_/d'
}
THIS_SCRIPT_NAME=`basename "$0"`
heading Reads all \#\!\/bin\/bash scripts and links it to /usr/local/bin/ as a softlink from this current folder
announce Varianten of bash hashbans
# Sample use
# Prepare .each
# ITEMS=$(find . -maxdepth 0 -type d | egrep -v "\.git")
#
# ACTIONS="echo \"Showing list for {#}\" ls -la {#} "
#
# Perform all actions in
# LIST1
# for each element in
# LIST2
# Call .each
# .each "${ACTIONS}" "${ITEMS}"
# OLD search Scripts
# \#\!/bin/bash
# \#\!/bin/zsh
# \#\!/bin/sh
# \#\!/bin/dash
# \#\!/bin/rbash
# \#\!/bin/env
# \#\!/usr/bin/env
LIST_OF_BASH_SCRIPTS=""
ITEMS="
\#\!/bin/
\#\!/usr/bin/
"
# Original Idea for Grep
# FILES_ENV_BASH=$(grep -l \#\!\/bin\/bash $(find * -maxdepth 0 -type f )) #\!/bin/env bash # get all files that have this string at the start of the contents
# FILES_ENV_BASH=$(grep -l \#\!/bin/zsh $(find * -maxdepth 0 -type f ) ) #\!/bin/env bash # get all files that have this string at the start of the contents
ACTIONS="
FILES_ENV_BASH=\$(grep -l {#} \$(find * -maxdepth 0 -type f ))
LIST_OF_BASH_SCRIPTS=\$(echo -e \"\${LIST_OF_BASH_SCRIPTS}\n\${FILES_ENV_BASH}\")
"
.each "${ACTIONS}" "${ITEMS}"
# DEBUG POINT 1. Expect a list of files names in a row: debug "$LIST_OF_BASH_SCRIPTS"
# DEBUG POINT 1. exit 0
# DEBUG POINT 1. end
if [[ "$(uname)" == "Darwin" ]] ; then
# Do something under Mac OS X platform
FILES_ALL_EXECUTABLE=$(find * -maxdepth 0 -perm +111 -type f) # version inclusive 4.5.12 and up
#FILES_ALL_EXECUTABLE=$(find * -maxdepth 0 -perm /111 -type f) # version exclusive 4.5.12 and down
LIST_OF_BASH_SCRIPTS="${LIST_OF_BASH_SCRIPTS}
${FILES_ALL_EXECUTABLE}" #Find All executable files
elif [[ "$(expr substr $(uname -s) 1 5)" == "Linux" ]] ; then
# Do something under GNU/Linux platform
# ubuntu lsb_release -i | sed 's/Distributor\ ID://g' = \tUbuntu\n
FILES_ALL_EXECUTABLE=$(find * -maxdepth 0 -executable -type f)
LIST_OF_BASH_SCRIPTS="${LIST_OF_BASH_SCRIPTS}
${FILES_ALL_EXECUTABLE}" #Find All executable files
elif [[ "$(expr substr $(uname -s) 1 10)" == "MINGW32_NT" ]] ; then
# Do something under Windows NT platform
FILES_ALL_EXECUTABLE=$(find * -maxdepth 0 -executable -type f)
LIST_OF_BASH_SCRIPTS="${LIST_OF_BASH_SCRIPTS}
${FILES_ALL_EXECUTABLE}" #Find All executable files
# nothing here
fi
FILES_ALL_L_TO_EXES=$(find * -maxdepth 0 -type l -exec test -x {} \; -print | xargs -I {} ls "{}") #Find All softlinks that point to an executable file
LIST_OF_BASH_SCRIPTS="${LIST_OF_BASH_SCRIPTS}
${FILES_ALL_L_TO_EXES}"
LIST_OF_BASH_SCRIPTS=$(echo "${LIST_OF_BASH_SCRIPTS}" | sort | uniq | remove_all_starting_with_journal_get | delete_empty_lines)
# DEBUG POINT 2. Expect a list of files names in a row: debug "$LIST_OF_BASH_SCRIPTS"
# DEBUG POINT 2. exit 0
# DEBUG POINT 2. end
get_current_folder_path_and_name
anounce Re-linking now
if [[ ! -d "/usr/local" ]]; then
{
sudo mkdir -p /usr/local
}
fi
if [[ ! -d "/usr/local/bin" ]]; then
{
sudo chown -R $USER:$USER /usr/local/bin
}
fi
if [[ ! -d "${USER_HOME}/bin/" ]] ; then
{
sudo mkdir -p "${USER_HOME}/bin"
}
fi
BLANK_SPACE="${lightpurple} +-- ${lightblue} "
while read -r SCRIPT_NAME; do
if [[ -n "${SCRIPT_NAME}" ]] && [[ ! -d "${SCRIPT_NAME}/" ]] ; then # Not empty and is not a directory
{
anounce_command chmod +x "${CURRENT_PATH}/${SCRIPT_NAME}"
target_link="/usr/local/bin/${SCRIPT_NAME}"
if [[ -e "${target_link}" ]] && [[ -L "${target_link}" ]]; then # Symlink softlink exists REF: http://stackoverflow.com/questions/5767062/how-to-check-if-symlink-exists
{
anounce_command sudo unlink "${target_link}"
}
fi
new_target_link="${USER_HOME}/bin/${SCRIPT_NAME}"
if [[ -e "${new_target_link}" ]] && [[ -L "${new_target_link}" ]]; then # Symlink softlink exists REF: http://stackoverflow.com/questions/5767062/how-to-check-if-symlink-exists
{
anounce_command sudo unlink "${new_target_link}"
}
fi
anounce_command sudo ln -sf "${CURRENT_PATH}/${SCRIPT_NAME}" "${new_target_link}"
}
fi
done <<< "${LIST_OF_BASH_SCRIPTS}"
new_target_link="${USER_HOME}/bin"
patch_utf_names(){
# Sample use
# patch_utf_names "${PROVIDED_USER}" "${BASHCRMCLI}" >/dev/null 2>&1 # suppress output
PROVIDED_USER="vagrant"
if [[ -n "${1:-}" ]] ; then
PROVIDED_USER="${1}"
fi
TARGET_DIRECTORY="/_/clis"
if [[ -n "${2:-}" ]] ; then
TARGET_DIRECTORY="${2}"
fi
[[ ! -d "${TARGET_DIRECTORY}/" ]] && return 0
[[ ! -d "/usr/local/bin/" ]] && return 0
anounce Patching UTF-8 Filenames
anounce_command sudo ln -sf "${TARGET_DIRECTORY}/loeschen_seo_nur_datei" "${new_target_link}/löschen_seo_nur_datei"
anounce_command sudo ln -sf "${TARGET_DIRECTORY}/cuet" "${new_target_link}/cüt"
anounce_command sudo ln -sf "${TARGET_DIRECTORY}/aeoe" "${new_target_link}/äö"
anounce_command sudo ln -sf "${TARGET_DIRECTORY}/oe" "${new_target_link}/ö"
anounce_command sudo ln -sf "${TARGET_DIRECTORY}/oeue" "${new_target_link}/öü"
anounce_command sudo ln -sf "${TARGET_DIRECTORY}/crossedo" "${new_target_link}/ø"
anounce_command sudo ln -sf "${TARGET_DIRECTORY}/crossequal" "${new_target_link}/≠"
anounce_command sudo ln -sf "${TARGET_DIRECTORY}/middleminidot" "${new_target_link}/•"
anounce_command sudo ln -sf "${TARGET_DIRECTORY}/ue" "${new_target_link}/ü"
anounce_command sudo ln -sf "${TARGET_DIRECTORY}/dimscreen" "${new_target_link}/€"
anounce_command sudo ln -sf "${TARGET_DIRECTORY}/doe" "${new_target_link}/dö"
anounce_command sudo unlink "${new_target_link}/loeschen_seo_nur_datei"
anounce_command sudo unlink "${new_target_link}/cuet"
anounce_command sudo unlink "${new_target_link}/aeoe"
anounce_command sudo unlink "${new_target_link}/oe"
anounce_command sudo unlink "${new_target_link}/oeue"
anounce_command sudo unlink "${new_target_link}/crossedo"
anounce_command sudo unlink "${new_target_link}/crossequal"
anounce_command sudo unlink "${new_target_link}/middleminidot"
anounce_command sudo unlink "${new_target_link}/ue"
} # end patch_utf_names
if [[ "${PWD}" == *"bash_intuivo_cli"* ]] ; then
{
if [[ -d "${PWD}/" ]] ; then
{
patch_utf_names "${USER}" "/_/clis/bash_intuivo_cli"
}
fi
}
fi