-
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathsociety
executable file
·436 lines (416 loc) · 12.2 KB
/
society
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
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
#!/usr/bin/env bash
#
# @author Ari Setiawan
# @create 12.01-2024 14:31
# @github https://github.com/hxAri/Society
#
# Society Copyright (c) 2024 - Ari Setiawan <hxari@proton.me>
# Society Licence under GNU General Public Licence v3
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# any later version.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <https://www.gnu.org/licenses/>.
#
# Society Program is not affiliated with or endorsed, endorsed at all by
# Facebook or any other party, if you use the main account to use this
# tool we as Coders and Developers are not responsible for anything,
# use it at your own risk, and this is Strictly not for SPAM.
#
# Clear terminal screen.
clear
# Target basename.
pathname=$(basename $0)
# Change current working directory.
cd $(dirname $0)
# Iterate down a (possible) chain of symlinks.
while [ -L "$pathname" ]
do
pathname=$(readlink $pathname)
cd $(dirname $pathname)
pathname=$(basename $pathname)
done
# Get the Society basepath.
basepath=$(pwd -P)
# By default the Society saves the virtual environment activation
# location in a file called .virtual in the Project directory.
virtualization="${basepath}/.virtual"
virtual=
# For compatibility system.
if [[ ! $(command -v puts) ]]; then
function puts() {
echo -e "\x1b[0m$@"
}
fi
# Handle setup python module requirements.
function modinstall() {
local envfiname=$1
read -e -p "$(puts "$envfiname: install python module requirements [Y/n] ")" installmod
if [[ "${installmod^^}" == "Y" ]]; then
source "$envfiname"
if [[ $? -eq 0 ]]; then
if [[ ! -f "${basepath}/requirements.txt" ]]; then
puts "${basepath}/requirements.txt: no such file or directory"
exit 1
fi
pip install -r "${basepath}/requirements.txt"
if [[ $? -ne 0 ]]; then
puts "${basepath}/requirements.txt: failed install module requirements"
exit 1
fi
deactivate
puts "${basepath}/requirements.txt: all module requirements installed"
puts "please re-run this programs"
exit 0
else
puts "$envfiname: failed to activate python virtual environment"
exit 1
fi
else
puts "$envfiname: aborted"
exit 1
fi
}
# Handle create python virtual environment.
function envcreate() {
local envfiname=$1
puts "$envfiname: creating virtual environment"
python3 -m venv "$envfiname"
if [[ $? -ne 0 ]]; then
puts "$envfiname: failed create virtual environment"
exit 1
fi
echo "$envfiname" > "$virtualization"
if [[ $? -ne 0 ]]; then
puts "$envfiname: failed create virtual environment"
exit 1
fi
modinstall "$envfiname"
}
if [[ ! -f $virtualization ]]; then
envfiname=
puts "input virtual environment activation: e.g /home/$(whoami)/virtual/bin/activate"
while [[ ! -f $virtualization ]]; do
read -e -p "$(puts pathname:) " envfiname
if [[ -f "$envfiname" ]]; then
echo "$envfiname" > "$virtualization"
if [[ $? -ne 0 ]]; then
puts "$envfiname: failed create virtual environment"
exit 1
fi
modinstall "$envfiname"
elif [[ -d "$envfiname" ]]; then
if [[ $(ls -A "$envfiname") ]]; then
read -e -p "$(puts "${envfiname}: This directory is not empty are you sure [Y/n] ")" envforcec
if [[ "${envforcec^^}" != "Y" ]]; then
envfiname=
continue
fi
envcreate "$envfiname"
fi
else
puts "$envfiname: no such file or directory"
read -e -p "$(puts "$envfiname: create the virtual environment here [Y/n] ")" envcreate
if [[ "${envcreate^^}" != "Y" ]]; then
envfiname=
continue
fi
envcreate "$envfiname"
fi
done
fi
# Read saved Society virtual environment activation.
virtual="$(cat $virtualization)"
# Clean Python cache Byte-Code compiled.
function clean() {
for cache in $(find "${basepath}/" | grep "__pycache__"); do
if [[ -d $cache ]]; then
rm -rf $cache
if [[ $? -ne 0 ]]; then
puts "${cache}: failed remove directory"
fi
fi
done
}
declare -A actions=(
[account]="Facebook account management"
[cleaner]="Cleaning The Society Files"
[download]="Facebook multithread media downloader"
[graphql]="Facebook graphql utilities"
[help]="Show this help"
[install]="Install Society as Python3 Module"
[id]="Facebook get profile or page id"
[linting]="Linting Society code before commit"
[package]="Pip"
[parser]="Facebook parser (not implemented at this time)"
[running]="Running The Society as CLI"
[service]="Running The Society as Web Service"
[target]=""
[testing]=""
[upgrade]="Upgrade The Society code from original repository"
[token]="Facebook access token utilities"
[zombie]="Running The Society as Bot Telegram"
)
action=${1,,}
default="running"
running=(
"account"
"download"
"graphql"
"help"
"id"
"parser"
"target"
"testing"
"token"
)
arguments=()
if [[ "$action" == "" ]]; then
action=$default
else
i=1
for argument in ${@}; do
if [[ $i != 1 ]]; then
arguments+=( $argument )
fi
i=$((i+1))
done
fi
# Activate the python virtual environment.
source "$virtual"
if [[ $? -ne 0 ]]; then
puts "$virtual: failed to activate python virtual environment"
fi
case ${action,,} in
c|cleaner)
contents=()
if [[ -f "${basepath}/.gitignore" ]]; then
while IFS= read -r content; do
contents+=( "$content" )
done < "${basepath}/.gitignore"
fi
for content in "${contents[@]}"; do
if [[ ! -z "$content" ]]; then
if [[ "${content:0:1}" == "#" ]]; then
continue
fi
prefix="$(echo -e "$content" | cut -d "." -f 1)"
length=${#prefix}
if [[ "${prefix:$((length-1)):${#length}}" == "*" ]]; then
if [[ "$prefix" == "*" ]]; then
continue
fi
target="${basepath}/$content"
prefix="$(echo -e "${target}" | cut -d "." -f 1)"
extension="$(echo -e "${target}" | cut -d "." -f 2)"
for file in $prefix; do
if [[ "$file" == "$prefix" ]]; then
continue
fi
# temp="${file%%extension*}"
# start="$(echo -e "${file%%extension*}" | echo -e ${#temp})"
# puts "${file}:${start}:${file:$((start-${#extension})):$((start))}"
if [[ -f "$file" ]]; then
filename="${file:$((${#basepath}+1)):$((${#file}))}"
removeable=
while [[ -z "$removeable" ]]; do
puts "remove: $filename [Y/n]" "\c"
read removeable
case "${removeable,,}" in
y) rm $file ;;
n) puts "skipped: ${filename}" ;;
*) removeable= ;;
esac
done
fi
done
fi
fi
done
;;
i|install) python3 ${basepath}/setup.py install ${arguments[@]} ;;
l|linting)
python3 -m pylint --argument-naming-style=camelCase \
--attr-naming-style=camelCase \
--class-attribute-naming-style=any \
--class-const-naming-style=any \
--class-naming-style=PascalCase \
--const-naming-style=any \
--extension-pkg-allow-list=pyzstd \
--variable-naming-style=camelCase \
--function-naming-style=camelCase \
--max-attributes=30 \
--max-public-methods=60 \
--method-naming-style=camelCase \
--good-names="e,Executor,i,id,u,k,ThreadExecutor,ThreadRunner,v" \
--ignore-docstrings=y \
--ignore-long-lines="[^\n]+" \
--indent-string="\t" \
--disable=arguments-differ \
--disable=broad-exception-caught \
--disable=consider-using-f-string \
--disable=function-redefined \
--disable=keyword-arg-before-vararg \
--disable=missing-function-docstring \
--disable=missing-module-docstring \
--disable=multiple-statements \
--disable=non-parent-init-called \
--disable=protected-access \
--disable=redefined-argument-from-local \
--disable=redefined-builtin \
--disable=redefined-outer-name \
--disable=too-many-arguments \
--disable=too-many-boolean-expressions \
--disable=too-many-branches \
--disable=too-many-lines \
--disable=too-many-locals \
--disable=too-many-nested-blocks \
--disable=too-many-statements \
--disable=super-init-not-called \
--disable=too-few-public-methods \
--disable=trailing-newlines \
--disable=trailing-whitespace \
--disable=unnecessary-dunder-call \
--disable=unnecessary-ellipsis \
--disable=unnecessary-lambda-assignment \
--disable=unnecessary-pass \
--disable=unexpected-special-method-signature \
--disable=wrong-import-order \
--disable=wrong-import-position \
${basepath}/setup.py \
${basepath}/src/society/*.py \
${basepath}/src/society/actions/*.py \
${basepath}/src/society/typing/*.py
;;
p|package) pip ${arguments[@]} ;;
s|service) python3 ${basepath}/src/service.py ${arguments[@]} ;;
u|upgrade)
puts "$basepath: this directory will be deleted permanently"
read -e -p "$(puts "are you sure want to upgrade [Y/n] ")" upgrade
if [[ "${upgrade^^}" != "Y" ]]; then
puts "aborted"
exit 1
fi
pathname="$(dirname $basepath)"
basename="$(basename $basepath)"
archive="Society-main.tar.gz"
backup="Society-backup.tar.gz"
target="https://github.com/hxAri/Society/archive/refs/heads/main.tar.gz"
puts "$backup: backing source code"
cd "$pathname"
if [[ $? -ne 0 ]]; then
puts "$pathname: failed change current working directory"
exit 1
fi
tar -cvf "${backup}" "$basepath"
if [[ $? -ne 0 ]]; then
puts "$backup: failed backup source code"
exit 1
fi
cd -
if [[ $? -ne 0 ]]; then
puts "$basename: failed change to previous working directory"
exit 1
fi
puts "$archive: downloading source code from repository"
wget --tries=20 $target -O "${pathname}/${archive}"
if [[ $? -ne 0 ]]; then
puts "$archive: failed download source code"
exit 1
fi
puts "$archive: extracting the contents"
tar -xvf "${pathname}/${archive}" -C "$pathname"
if [[ $? -ne 0 ]]; then
puts "$archive: failed to extract the contents"
exit 1
fi
puts "$basename: removing old directory"
rm -rf "${pathname}/${basename}"
if [[ $? -ne 0 ]]; then
puts "$basename: failed to remove the directory"
exit 1
fi
puts "Society-main: moving the directory"
mv "${pathname}/Society-main" "${pathname}/${basename}"
if [[ $? -ne 0 ]]; then
puts "Society-main: failed to move the directory"
exit 1
fi
puts "Society: successfully updated"
echo "$virtual" > "$virtualization"
if [[ $? -ne 0 ]]; then
puts "$virtual: failed create virtual environment"
exit 1
fi
modinstall "$virtual"
;;
z|zombie) python3 ${basepath}/src/zombie.py ${arguments[@]} ;;
*)
if [[ "$action" != "running" ]]; then
execute=
for define in ${running[@]}; do
if [[ "$action" == "$define" ]]; then
python3 ${basepath}/src/society.py "$action" ${arguments[@]}
execute=ok
break
fi
done
if [[ $execute != "ok" ]]; then
puts ""
puts " Society Terminal Console"
puts ""
puts " example [command] [arguments] [--options]"
iter=1
for keyset in ${!actions[@]}; do
if [[ ${running[$( echo ${running[@]/$keyset//} | cut -d/ -f1 | wc -w | tr -d " " )]} != "$keyset" ]]; then
index=1
length=$((12-${#keyset}))
if [[ $iter == "1" ]]; then
prefix=" command "
else
prefix=" "
fi
iter=$((iter+1))
prefix+="$keyset"
prefix+=" "
while [[ $index != $length ]]; do
index=$((index+1))
prefix+=" "
done
puts "$prefix" "${actions[$keyset]}"
if [[ $keyset == "running" ]]; then
for runner in ${!actions[@]}; do
if [[ ${running[$( echo ${running[@]/$runner//} | cut -d/ -f1 | wc -w | tr -d " " )]} == "$runner" ]]; then
if [[ "${actions[$runner]}" == "" ]]; then
continue
fi
index=1
length=$((10-${#runner}))
prefix=" "
prefix+=" · $runner"
prefix+=" "
while [[ $index != $length ]]; do
index=$((index+1))
prefix+=" "
done
puts "$prefix" "${actions[$runner]}"
fi
done
fi
fi
done
fi
else
python3 ${basepath}/src/society.py ${arguments[@]}
fi
;;
esac
# Clean python cache files.
clean
# Deactivate python virtual environment.
deactivate
puts ""
exit 0