-
Notifications
You must be signed in to change notification settings - Fork 4
/
bget.bat
1932 lines (1591 loc) · 65.4 KB
/
bget.bat
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
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
@echo off
setlocal enabledelayedexpansion
call :macros
:: Bget- Batch script fetcher
::Made by Jahwi
:: Conceived, coded and died in 2016, resurrected and recoded in 2018. Enjoy! \o/
::------------------------------------------------------------------------------------------------
::<SETTINGS>
::------------------------------------------------------------------------------------------------
::init directories
for %%a in (scripts temp bin docs) do (
if not exist "%~dp0\%%~a" md "%~dp0\%%~a"
)
if not exist "%appdata%\Bget\scripts" md "%appdata%\Bget\scripts"
::make and append configurable global vars to config file if non-existent.
if not exist "%~dp0\bin\config.bget" (
echo [DO NOT DELETE] >"%~dp0\bin\config.bget"
echo js>"%~dp0\bin\config.bget":defmethod
echo yes>"%~dp0\bin\config.bget":adl
echo %appdata%\Bget\scripts>"%~dp0\bin\config.bget":scl
echo yes>"%~dp0\bin\config.bget":rsl
)
::init global vars.
set "version=0.4.1-191019 "
set global_vars_list=ddm adl scl rsl lf
set global_vars_full="ddm#[Default Download Method] Sets the default download method." "adl#[auto-delete_logs] Toggles deletion of temp files on/off." "scl#[Script Location] The default script download folder." "rsl#[Refresh Script List] Toggles refreshing [redownloading] of the script list on every GET operation." "lf#[Last Fetched Script List] Shows the date and time the script list was last refreshed."
::set "script_location=%appdata%\Bget\scripts"
set list_location=https://raw.githubusercontent.com/jahwi/bget-list/master/master.txt
::set auto-delete_logs=yes
set valid_defmethod=
set auto-delete_logs=
set valid_adl_bool=
REM load the configurable global vars from the config file
>nul 2>&1 set/p defmethod=<"%~dp0\bin\config.bget":defmethod
>nul 2>&1 set/p auto-delete_logs=<"%~dp0\bin\config.bget":adl
>nul 2>&1 set/p script_location=<"%~dp0\bin\config.bget":scl
>nul 2>&1 set/p refresh_script_list=<"%~dp0\bin\config.bget":rsl
::validate the dafault download method, fix if errors are found.
for %%s in (curl js vbs bits ps) do ( if /i "!defmethod!"=="%%s" set "valid_defmethod=yes" )
if not "!valid_defmethod!"=="yes" (
echo Error: Invalid default download method "!defmethod!". Setting to JS.
echo js>"%~dp0\bin\config.bget":defmethod
set defmethod=js
)
::validate the auto-delete_logs bool.
if /i not "!auto-delete_logs!"=="yes" (
if /i not "!auto-delete_logs!"=="no" echo yes>"%~dp0\bin\config.bget":adl
)
::validate the script location path.
if not exist "!script_location!\" (
set "script_location=%appdata%\Bget\scripts"
echo !script_location!>"%~dp0\bin\config.bget":scl
)
REM validate the refresh script list bool.
if /i not "!refresh_script_list!"=="yes" (
if /i not "!refresh_script_list!"=="no" echo yes>"%~dp0\bin\config.bget":rsl
)
::------------------------------------------------------------------------------------------------
::</SETTINGS>
::------------------------------------------------------------------------------------------------
:main
::checks for errors in user input, then calls the switch.
::input validation
set input_string=%*
set temp_input_string=%*
if defined input_string for %%a in (a b c d e f g h i j k l m n o p q r s t u v w x y z - . _ 1 2 3 4 5 6 7 8 9 0 [ ] { } \ :) do (
if defined input_string set input_string=!input_string:%%a=!
if defined input_string set input_string=!input_string: =!
if defined input_string set input_string=!input_string:"=!
)
::if no switch is supplied.
if "%~1"=="" (
set msg=Error: No switch supplied.
call :help
exit /b
)
if not "!input_string!"=="" (
REM if '/?' is triggered.
if "!input_string!"=="-?" (
call :help
exit /b
)
echo Error: Invalid input.
echo Type "%~n0 -help" for more information.
exit /b
)
REM ------------------------------------------------------------------------------------------------------------------------
REM deal with -nobanner and -refresh
for %%# in (-nobanner -refresh) do (
set %%#_found=false
echo !temp_input_string! | findstr /i /c:"%%#" >nul
if "!errorlevel!"=="0" (
if defined temp_input_string set temp_input_string=!temp_input_string:%%#=!
set %%#_found=true
)
)
REM remove trailing spaces
:trim
if defined temp_input_string if "!temp_input_string:~0,1!_"==" _" set temp_input_string=!temp_input_string:~1!
if defined temp_input_string if "!temp_input_string:~-1!_"==" _" set temp_input_string=!temp_input_string:~0,-1!
if defined temp_input_string if "!temp_input_string:~0,1!_"==" _" goto :trim
if defined temp_input_string if "!temp_input_string:~-1!_"==" _" goto :trim
REM echo Nobanner found: !-nobanner_found!
REM echo Refresh found: !-refresh_found!
REM echo Edited string: "!temp_input_string!"
rem exit /b
REM provision for the nobanner switch
if /i not "!-nobanner_found!"=="true" (
for %%a in (" ---------------------------------------------------------------------------"
" Bget v!version! Package Manager for Windows Scripts."
" Made by Jahwi in 2018 | Edits made by Icarus | Bugs squashed by B00st3d"
" https://github.com/jahwi/bget"
" Type %~n0 -help to get the list of commands."
" ---------------------------------------------------------------------------"
""
) do echo=%%~a
)
::REFRESH function
if /i "!-refresh_found!"=="true" set refresh_script_list=yes
if /i "!-refresh_found!"=="true" echo Refreshing script list... && call :getlist !defmethod! && if "!temp_input_string!"=="" exit /b
REM ------------------------------------------------------------------------------------------------------------------------
REM print the bget intro, followed by the relevant output
::loop through valid switches
set valid_bool=
for /f "tokens=1 delims= " %%a in ("!temp_input_string!") do (
for %%# in (get remove update info list upgrade help pastebin openscripts search newscripts set query version) do (
if /i "-%%#"=="%%~a" set valid_bool=yes
)
)
if not "!valid_bool!"=="yes" (
echo Error: Invalid switch.
echo Type "%~n0 -help" for more information.
exit /b
)
if "!valid_bool!"=="yes" (
REM set switch_string=%*
REM cut out the se commands
REM if /i "!switch_string:~0,9!"=="-nobanner" set switch_string=!switch_string:~10!
REM if /i "!switch_string:~0,8!"=="-refresh" set switch_string=!switch_string:~9!
call :!temp_input_string:~1!
REM cleanup logs and temp files
if /i "!auto-delete_logs!"=="yes" (
REM deletes the script list if rsl is set to "yes"
if "!refresh_script_list!"=="yes" if exist "%~dp0\temp\master!sess_rand!.txt" del /f /q "%~dp0\temp\master!sess_rand!.txt" >nul
if exist "%~dp0\temp\hash!sess_rand!.txt" del /f /q "%~dp0\temp\hash!sess_rand!.txt" >nul
)
exit /b
)
::--------------------------------------------------------------------
::Beginning of switch functions.
::--------------------------------------------------------------------
:help
::opens helpdoc
if /i "%~1"=="-doc" (
if /i not "%*"=="-doc" echo Error[h3]: Invalid number of arguments. && exit /b
if exist "%~dp0\docs\readme.txt" (
type "%~dp0\docs\readme.txt"
exit /b
)
if not exist "%~dp0\docs\readme.txt" echo the Bget help doc is missing. Run bget -upgrade -usebits -force to get it. && exit /b
)
::check for invalid args
for %%# in (get remove update info list upgrade help pastebin openscripts search newscripts set query version) do (
if /i "%%#"=="%~1" if /i not "%*"=="%~1" echo Error[h3]: Invalid number of arguments. && exit /b
)
::help for the -get command
if /i "%~1"=="get" (
echo Description: Fetches scripts using script names.
echo.
echo Usage: %~n0 -get {optional download method} [options] "script names"
echo.
echo.
echo Options
echo -use[method] Fetches the specified scripts using the specfied method.
echo -all Fetches all the scripts from Bget's repo.
echo.
echo.
echo Example: %~n0 -get -usecurl "test colour brpg"
echo.
echo Note:
echo [1] Valid methods are: -usejs, -usevbs, -useps, -usebits, -usecURL
echo [2] If no download method is supplied, Bget will default to the default download method [!defmethod!].
echo [3] Scripts located outside Bget's repo cannot be downloaded using the BITS method.
echo [4] If the "refresh script list" variable is set to "yes", Bget will ignore the specified download method, and instead read a cached script list. See the readme's QUERY and SET sections for more details.
exit /b
)
::help for the -pastebin command
if /i "%~1"=="pastebin" (
echo Description: Fetches a script hosted on Pastebin, using a paste code.
echo.
echo Usage: %~n0 -pastebin {optional download method} "Paste Code" "local filename"
echo.
echo.
echo Options
echo -use[method] Fetches the specified scripts using the specfied method.
echo.
echo.
echo Example: %~n0 -pastebin "1wsBxRs4" script.bat
echo.
echo Note:
echo [1] Valid methods are: -usejs, -usevbs, -useps, and -usecURL
echo [2] If no download method is supplied, Bget will default to the default download method [!defmethod!].
echo [3] Pastebin scripts cannot be downloaded using the BITS download method.
echo [4] Pastebin scripts are kept in the scripts folder, at [!script_location!\pastebin\].
echo [5] The Paste Code is the unique element of a PASTEBIN url.
echo E.g a pastebin script located at https://pastebin.com/YkEtQYFR would have YkEtQYFR as its paste code.
echo If you get the paste code wrong, you'll probably get a pastebin error as the output file instead of your intended script.
exit /b
)
::help for the -remove command
if /i "%~1"=="remove" (
echo Description: Removes scripts and/or logs.
echo.
echo Usage: %~n0 -remove [options] [scripts]
echo.
echo.
echo Options
echo -all Removes all scripts.
echo -all -y Removes all scripts, and doesn't ask for confirmation.
echo -pastebin Removes all pastebin scripts.
echo -pastebin -y Removes all pastebin scripts, and doesn't prompt for confirmation.
echo -logs Deletes Bget's temporary files, empties Bget's temp folder.
echo.
echo.
echo Example: %~n0 -remove "scriptA scriptB scriptC"
echo Example: %~n0 -remove -all
echo Example: %~n0 -remove -pastebin
exit /b
)
::help for the -update command
if /i "%~1"=="update" (
echo Description: Fetches the latest versions of scripts.
echo.
echo Usage: %~n0 -update {optional download method} [options] "script names"
echo.
echo.
echo Options
echo -use[method] Updates the specified scripts using the specfied method.
echo -all Updates all the scripts from Bget's repo.
echo -force Updates all the scripts from Bget's repo, regardless of local version.
echo.
echo.
echo Example: %~n0 -update -usecurl "test colour brpg"
echo Example: %~n0 -update -all -force
echo.
echo Note:
echo [1] Valid methods are: -usejs, -usevbs, -useps, -usebits, -usecURL
echo [2] If no download method is supplied, Bget will default to the default download method [!defmethod!].
echo [3] Scripts located outside Bget's repo cannot be updated using the BITS method.
echo [4] If the "refresh script list" variable is set to "yes", Bget will ignore the specified download method, and instead read a cached script list. See the readme's QUERY and SET sections for more details.
exit /b
)
::help for the -info command
if /i "%~1"=="-info" (
echo Description: Displays info about a specified script.
echo.
echo Usage: %~n0 -info {optional download method} "script name"
echo.
echo.
echo Options
echo -use[method] Fetches script info using the specfied method.
echo.
echo.
echo Example: %~n0 -info -usecurl "test"
echo.
echo Note:
echo [1] Valid methods are: -usejs, -usevbs, -useps, -usebits, -usecURL
echo [2] If no download method is supplied, Bget will default to the default download method [!defmethod!].
echo [3] Scripts located outside Bget's repo cannot have their hashes and last modified vars displayed by the info command.
echo [4] If the "refresh script list" variable is set to "yes", Bget will ignore the specified download method, and instead read a cached script list. See the readme's QUERY and SET sections for more details.
exit /b
)
::help for the -list command
if /i "%~1"=="list" (
echo Description: Lists local and remote scripts.
echo.
echo Usage: %~n0 -list {optional download method} [options]
echo.
echo.
echo Options
echo -local List fetched scripts.
echo -server -use[method] Fetches and displays the script list using the specfied method.
echo -full Displays the script list with minimal formatting. Can only be used with the
echo -server switch. Can be used with both the -only and -sortby filters.
echo -only Displays only output matching any of the following criteria:
echo name, author, category, and date. Can only be used with the -server switch.
echo -only name xyz Displays scripts with names matching the specified search string.
echo -only author xyz Displays scripts with an author matching the specified search string.
echo -only category xyz Displays scripts with a category matching the specified search string.
echo -only date xyz Displays scripts with a last modified date matching the specified search string.
echo -sortby Sorts the script list by any of the following criteria:
echo name, author, category, and date. Can only be used with the -server switch.
echo -sortby name Sorts the script list alphabetically by script name.
echo -sortby author Sorts the script list alphabetically by script author.
echo -sortby category Sorts the script list alphabetically by script category.
echo -sortby date Sorts the script list by scripts' last modified dates.
echo.
echo.
echo Example: %~n0 -list -local
echo Example: %~n0 -list -server -usecurl
echo Example: %~n0 -list -server -full
echo Example: %~n0 -list -server -only author Jahwi
echo Example: %~n0 -list -server -only author Jahwi -full
echo Example: %~n0 -list -server -sortby author
echo Example: %~n0 -list -server -sortby author -full
echo.
echo Note:
echo [1] Valid methods are: -usejs, -usevbs, -useps, -usebits, -usecURL
echo [2] If no download method is supplied, Bget will default to the default download method [!defmethod!].
echo [3] Bget can't display the hash or last-modified dates of scripts located outside the repo.
echo [4] If the "refresh script list" variable is set to "yes", Bget will ignore the specified download method, and instead read a cached script list. See the readme's QUERY and SET sections for more details.
exit /b
)
::help for the -upgrade command
if /i "%~1"=="upgrade" (
echo Description: Downloads and sets-up the latest version of Bget.
echo.
echo Usage: %~n0 -upgrade {optional download method} [options]
echo.
echo.
echo Options
echo -use[method] Upgrades Bget using the specfied method.
echo -force Upgrades Bget, regardless of local version.
echo.
echo.
echo Example: %~n0 -upgrade -usecurl
echo Example: %~n0 -upgrade -force
echo.
echo Note:
echo [1] Valid methods are: -usejs, -usevbs, -useps, -usebits, -usecURL
echo [2] If no download method is supplied, Bget will default to the default download method [!defmethod!].
exit /b
)
::help for the -help command
::so meta
if /i "%~1"=="help" (
echo Description: Gives help info about Bget's commands.
echo.
echo Usage: %~n0 -help [options]
echo.
echo.
echo Options
echo -doc Displays Bget's readme
echo [command] Displays help info about a particular command.
echo.
echo.
echo Example: %~n0 -help
echo Example: %~n0 -help -doc
echo Example: %~n0 -help get
echo.
exit /b
)
::help for the -openscripts command
if /i "%~1"=="openscripts" (
echo Description: Opens the directory where scripts are stored at [!script_location!].
echo.
echo Usage: %~n0 -openscripts
echo.
echo.
echo.
echo Example: %~n0 -openscripts
echo.
exit /b
)
::help for the -search command
if /i "%~1"=="search" (
echo Description: Searches for scripts from the script list.
echo.
echo Usage: %~n0 -search {optional download method} [string]
echo.
echo.
echo.
echo Options
echo -use[method] Fetches the resource using the specfied method.
echo.
echo Example: %~n0 -search "test"
echo.
echo Note:
echo [1] Valid methods are: -usejs, -usevbs, -useps, -usebits, -usecURL
echo [2] If no download method is supplied, Bget will default to the default download method [!defmethod!].
echo [3] If the "refresh script list" variable is set to "yes", Bget will ignore the specified download method, and instead read a cached script list. See the readme's QUERY and SET sections for more details.
exit /b
)
::help for the -newscripts command
if /i "%~1"=="newscripts" (
echo Description: Checks for recently added scripts on Bget's server.
echo.
echo Usage: %~n0 -newscripts {optional download method}
echo.
echo.
echo.
echo Options
echo -use[method] Fetches the resource using the specfied method.
echo Example: %~n0 -newscripts
echo Example: %~n0 -newscripts -usevbs
echo.
echo Note:
echo [1] Valid methods are: -usejs, -usevbs, -useps, -usebits, -usecURL
echo [2] If no download method is supplied, Bget will default to the default download method [!defmethod!].
echo [3] If the "refresh script list" variable is set to "yes", Bget will ignore the specified download method, and instead read a cached script list. See the readme's QUERY and SET sections for more details.
echo.
exit /b
)
::help for the -set command
if /i "%~1"=="set" (
echo Description: Assigns values to configurable global variables.
echo.
echo Usage: %~n0 -set [global_variable] [value]
echo.
echo.
call :set
echo.
echo Example: %~n0 -set rsl yes.
echo.
exit /b
)
::help for the -query command
if /i "%~1"=="query" (
echo Description: Displays the values of select global variables.
echo.
echo Usage: %~n0 -query [global_variable]
echo.
echo.
call :query
echo.
echo Example: %~n0 -query scl
echo.
exit /b
)
::help for the -nobanner command
if /i "%~1"=="nobanner" (
echo Description: Supresses the banner when running commands.
echo.
echo Usage: %~n0 -nobanner [command]
echo.
echo Example: %~n0 -nobanner -get "test"
echo Example: %~n0 -nobanner -update "test"
exit /b
)
::help for the -refresh command
if /i "%~1"=="refresh" (
echo Description: Downloads a new copy of the script list before running commands.
echo.
echo Usage: %~n0 -refresh [command]
echo.
echo Example: %~n0 -refresh -get "test"
echo Example: %~n0 -refresh -update "test"
exit /b
)
::is printed if help switch, no switch or an incorrect switch is supplied.
for %%a in (
" ---------------------------------------------------------------------------"
" Usage: BGET [-switch {ARGs} ]"
" [-get {-usemethod} "SCRIPTs" ] Fetches a script/scripts."
" [-pastebin {-usemethod} PASTE_CODE local_filename ] Gets a Pastebin script."
" [-remove "SCRIPTs" ] Removes a script/scripts"
" [-update {-usemethod} "SCRIPTs" ] Updates the script/scripts"
" [-info {-usemethod} SCRIPT ] Gets info on the specified script."
" [-list -server {-usemethod} ] Lists scripts on Bget's server."
" [-list -local] Lists local scripts."
" [-search {usemethod} "STRING" ] Search scripts on the server."
" [-upgrade {-usemethod} ] Updates Bget."
" [-newscripts {-usemethod} ] Lists new scripts released."
" [-set -ddm {method}] Changes the default download method."
" [-query {global_variable} ] Displays the value of select global variables."
" [-search search_string ] Searches for scripts that match specified criteria."
" -openscripts Opens the scripts folder."
" -nobanner Skips displaying the intro banner."
" -refresh Download the latest version of the script list."
" -help Prints this help screen."
" -help -doc Opens the full help text."
""
" [#]Supported methods: -useJS -useVBS -usePS -useBITS -useCURL"
" Example: bget -get -useVBS test"
" [#]Some Antiviruses flag the JS and VBS download functions."
" Either witelist them or use the BITS/PS methods."
" [#]If you downloaded Bget from anywhere other than GitHub, be sure to"
" upgrade it."
" [#]Type BGET -help -doc for the full help text."
" [#]Type BGET -help [command] for command-specific help."
" ---------------------------------------------------------------------------"
) do echo=%%~a
if defined msg echo !msg!
set msg=
exit /b
::--------------------------------------------------------------------
:get
::the man, the myth, the legend, the main squeeze, the bees knees, the script fetching function.
::check for user errors
set get_bool=
set get_method=
if "%~1"=="" echo Error[g1]: Incorrect syntax. && exit /b
for %%s in (curl js vbs bits ps) do (
if /i "%~1"=="-use%%s" (
set get_bool=yes
set get_method=%%s
if "%~2"=="" echo Error[g2]: Incorrect syntax. && exit /b
)
)
if not "!get_bool!"=="yes" (
REM echo Error: Invalid get method.
REM echo Type "%~n0 -help" for more information.
if "!refresh_script_list!"=="yes" echo No method supplied. Defaulting to !defmethod! download method...
call :get -use!defmethod! "%~1"
exit /b
)
set get_bool=
if not "%~3"=="" (
echo Error[g3]: Invalid number of arguments.
echo Type "%~n0 -help" for more information.
exit /b
)
::downloads
::will attempt to download curl if when using the curl get method, curl isnt found in the curl subdirectory.
set script_fetched_count=0
set scripts_to_download=
::gets the script list
echo Reading script list...
call :getlist !get_method!
if not exist "%~dp0\temp\master!sess_rand!.txt" exit /b
::if "-all" switch is used
if /i "%~2"=="-all" (
for /f "tokens=1-8 delims=," %%r in ('findstr /b /c:"[#]," "%~dp0\temp\master!sess_rand!.txt"') do (
set /a scripts_to_download+=1
call :get_recurse "%%~s"
)
echo Fetched [!script_fetched_count!/!scripts_to_download!] scripts.
exit /b
)
::single scripts and args that aren't "-all"
for %%# in (%~2) do ( set /a scripts_to_download+=1 )
for %%r in (%~2) do (
call :get_recurse "%%~r"
)
echo Fetched [!script_fetched_count!/!scripts_to_download!] scripts.
exit /b
:get_recurse
::calls itself to download the specified scripts
set script_count=
for /f "tokens=1-8 delims=," %%a in ('findstr /b /c:"[#],%~1," "%~dp0\temp\master!sess_rand!.txt"') do (
set /a script_count+=1
if exist "!script_location!\%%~b\" (
echo The script "%%~b" already exists in this directory. Skipping...
set /a script_count+=1
)
if not exist "!script_location!\%%~b\" (
set /a script_count+=1
echo Fetching %%~b...
REM add warning because BITS cant download from external repositories.
if /i "!get_method!"=="bits" (
if /i "%%f"=="External-File-No-Hash-Available" (
echo Warning: BITS download method cannot download scripts from an external repo.
)
)
if not exist "!script_location!\%%~b" md "!script_location!\%%~b"
call :download -!get_method! "%%~c" "!script_location!\%%~b\%%~e"
if not exist "!script_location!\%%~b\%%~e" (
echo Error[g4]: An error occured while fetching "%%~nb".
if exist "!script_location!\%%~b" rd /s /q "!script_location!\%%~b"
)
if exist "!script_location!\%%~b\%%~e" (
set /a script_fetched_count+=1
echo %%f>"!script_location!\%%~b\hash.txt"
echo %%d>"!script_location!\%%~b\info.txt"
echo %%g>"!script_location!\%%~b\author.txt"
echo %date% %time% >"!script_location!\%%~b\last_modified.txt"
if "%%~xe"==".cab" (
echo Extracting...
call :cab "!script_location!\%%~b\%%~e" "!script_location!\%%~b"
)
%=Deal with zips=%
if "%%~xe"==".zip" (
echo Extracting...
call :unzip "!script_location!\%%~b\%%~e" "!script_location!\%%~b\"
)
echo [+] Done.
)
)
)
if not defined script_count echo The script "%~1" does not exist on the server.
exit /b
::--------------------------------------------------------------------
:pastebin
::I feel like I've paste-been here before.
::warning: scripts downloaded from pastebin are not vetted by bget staff
::be sure to inspect code downloaded from pastebin.
echo Bget Pastebin tip: PASTE_CODE is the unique element of a PASTEBIN url.
echo E.g a pastebin script located at https://pastebin.com/YkEtQYFR would have YkEtQYFR as its paste code.
echo If you get the paste code wrong, you'll probably get a pastebin error as the output file instead of your intended script.
echo.
echo.
:pastebin_recurse
::check for user errors
set paste_bool=
set paste_method=
::if "%~1"=="" echo Error[p1]: No Pastebin get method supplied. && exit /b
if "%~1"=="-usebits" echo Error: the pastebin function doesn't support BITSadmin as of yet. && exit /b
for %%s in (curl js vbs ps) do (
if /i "%~1"=="-use%%s" (
set paste_bool=yes
set paste_method=%%s
)
)
if not "!paste_bool!"=="yes" (
REM echo Error: Invalid get method.
REM echo Type "%~n0 -help" for more information.
echo No method supplied. Defaulting to !defmethod! download method...
call :pastebin_recurse -use!defmethod! "%~1" "%~2"
exit /b
)
if "%~2"=="" echo Error[p2]: No paste code supplied. && exit /b
if "%~3"=="" echo Error[p4]: You must specify a local filename. && exit /b
if not "%~4"=="" echo Error[p3]: Invalid number of arguments. && exit /b
set paste_bool=
::begin the pastebin fetching
if exist "!script_location!\pastebin\%~2\%~nx3" echo Error[p5]: The file name already exists && exit /b
if not exist "!script_location!\pastebin\%~2" md "!script_location!\pastebin\%~2"
echo Fetching "%~2" into "%~nx3"...
call :download -!paste_method! "https://pastebin.com/raw/%~2" "!script_location!\pastebin\%~2\%~nx3"
if not exist "!script_location!\pastebin\%~2\%~nx3" (
echo Error[p4]: An error occured fetching the pastebin script.
if exist "!script_location!\pastebin\%~2" rd /s /q "!script_location!\pastebin\%~2"
exit /b
)
if exist "!script_location!\pastebin\%~2\%~nx3" echo [+] Done. && exit /b
::paranoia
exit /b
::--------------------------------------------------------------------
:remove
::"Mr Stark, I don't feel so good"
::removes a script (You guessed it!)
set removed_scripts=0
set script_count=
::check for errors
if "%~1"=="" (
echo Error: No script supplied.
echo Type "%~n0 -help" for more information.
exit /b
)
if /i "%~1"=="-all" (
REM the -y switch triggers a bypass.
if /i not "%~2"=="-y" choice /c yn /n /m "Delete all scripts? [y/n]
if /i not "%~2"=="-y" if "!errorlevel!"=="2" exit /b
set script_count=
for /d %%a in ("!script_location!\*") do (
if exist "%%~a\hash.txt" (
set /a script_count+=1
echo Removing "%%~na"... && rd /s /q "%%~a"
if exist "%%~a" rd /s /q "%%~a"
if exist "%%a" echo Error[p6]: Failed to remove %%~na.
if not exist "%%a" set /a "removed_scripts+=1"
)
)
echo Removed [!removed_scripts!/!script_count!] scripts.
if not defined script_count echo You have no scripts.
exit /b
)
::deletes pastebin scripts.
if /i "%~1"=="-pastebin" (
if /i not "%~2"=="-y" choice /c yn /n /m "Clear ALL your pastebin scripts? This can't be undone. [(Y)es/(N)o]"
if /i not "%~2"=="-y" if "!errorlevel!"=="2" exit /b
if exist "!script_location!\pastebin" (
rd /s /q "!script_location!\pastebin" >nul
if not exist "!script_location!\pastebin" echo Pastebin scripts removed.
if exist "!script_location!\pastebin" echo Error[p7]: An error occured while deleting the pastebin folder.
) else ( echo Error: You don't have any pastebin scripts in the scripts directory. )
exit /b
)
::deletes logs
if /i "%~1"=="-logs" (
if exist "%~dp0\temp" (
rd /s /q "%~dp0\temp"
if not exist "%~dp0\temp" echo [+] Temp files removed.
if exist "%~dp0\temp" echo Error[r1]: An error occured while deleting the temp files.
if not exist "%~dp0\temp" md "%~dp0\temp"
)
exit /b
)
::deletes individual/multiple scrips.
for %%r in (%~1) do (
set /a script_count+=1
if not exist "!script_location!\%%~r" echo The script "%%~r" does not exist.
if exist "!script_location!\%%~r" (
rd /s /q "!script_location!\%%~r"
if exist "!script_location!\%%~r" rd /s /q "!script_location!\%%~r"
if exist "!script_location!\%%~r" echo Error[p7]: Bget could not delete "%%~r".
if not exist "!script_location!\%%~r" set /a "removed_scripts+=1" && echo Removed %%r.
)
)
echo Removed [!removed_scripts!/!script_count!] scripts.
exit /b
::--------------------------------------------------------------------
:update
::updates the specified script
::the script must exist for it to be updated
::what do you call a date in the sky?
::an UPdate.
::check for user errors
set update_bool=
set update_method=
::display syntax if no first argument is supplied.
if "%~1"=="" (
echo Syntax:
echo -update "scripts" Updates the specified script/scripts
echo -update "scripts" -force Updates the specified scripts, regardless of version.
exit /b
)
for %%s in (curl js vbs bits ps) do (
if /i "%~1"=="-use%%s" (
set update_bool=yes
set update_method=%%s
if "%~2"=="" echo Error[u2] Incorrect Syntax. && exit /b
)
)
if not "!update_bool!"=="yes" (
REM echo Error: Invalid get method.
REM echo Type "%~n0 -help" for more information.
if "!refresh_script_list!"=="yes" echo No method supplied. Defaulting to !defmethod! download method...
call :update -use!defmethod! "%~1" "%~2"
exit /b
)
if not "%~3"=="" (
if /i not "%~3"=="-force" echo Error[u3]: Invalid number of arguments. && exit /b
)
if not "%~4"=="" echo Error[u3]: Invalid number of arguments. && exit /b
set update_bool=
::update
::will attempt to download curl if when using the curl update method, curl isnt found in the curl subdirectory.
::sess rand allows multiple bget instances to be run without running into a "file is in use" issue
set scripts_to_update=0
set script_updated_count=0
::gets script list
echo Reading script list...
call :getlist !update_method!
if not exist "%~dp0\temp\master!sess_rand!.txt" exit /b
::if "-all" switch is used
if /i "%~2"=="-all" (
for /f "tokens=1-8 delims=," %%r in ('findstr /b /c:"[#]," "%~dp0\temp\master!sess_rand!.txt"') do (
if exist "!script_location!\%%~s\" (
call :update_recurse "%%~s" %~3
set /a scripts_to_update+=1
)
if "!scripts_to_update!"=="0" echo Error: No local scripts found.
echo Updated [!script_updated_count!/!scripts_to_update!] scripts.
exit /b
)
)
::single scripts and args that aren't "-all"
for %%# in (%~2) do ( set /a scripts_to_update+=1 )
for %%_ in (%~2) do (
call :update_recurse "%%~_" %~3
)
echo Updated [!script_updated_count!/!scripts_to_update!] scripts.
exit /b
:update_recurse
set script_count=
if not exist "!script_location!\%~1\" echo Error: "%~1" does not exist on the local machine.
if exist "!script_location!\%~1\" (
for /f "tokens=1-8 delims=," %%a in ('findstr /b /c:"[#],%~1," "%~dp0\temp\master!sess_rand!.txt"') do (
set /a script_count+=1
echo Updating %%~b...
set hash=
if not exist "!script_location!\%%~b\hash.txt" echo hash file for %%~b is missing. Updating anyway.
if exist "!script_location!\%%~b\hash.txt" (
set/p hash=<"!script_location!\%%~b\hash.txt"
if /i "%~2"=="-force" echo Forcing update... && set hash=%random%%random%%random%%random%
if /i "!hash!"=="%%~f" echo "%%~b" is up-to-date. Skipping.
)
if /i not "!hash!"=="%%~f" (
REM add warning because BITS cant download from external repositories.
if /i "!update_method!"=="bits" (
if /i "%%f"=="External-File-No-Hash-Available" (
echo Warning: BITS download method cannot download scripts from an external repo.
)
)
if not exist "%~dp0\temp\%%~b" md "%~dp0\temp\%%~b"
call :download -!update_method! "%%~c" "%~dp0\temp\%%~b\%%~e"
if not exist "%~dp0\temp\%%~b\%%~e" echo Could not update "%%~b".
if exist "%~dp0\temp\%%~b\%%~e" (
if not defined hash set /a hash=%random%
if not exist "!script_location!\%%~b\old-!hash!" md "!script_location!\%%~b\old-!hash!"
echo Cleaning up old version...
if exist "!script_location!\%%~b\%%~e" move /Y "!script_location!\%%~b\%%~e" "!script_location!\%%~b\old-!hash!"
if exist "!script_location!\%%~b\package\%%~e" move /Y "!script_location!\%%~b\package\%%~e" "!script_location!\%%~b\old-!hash!"
move /Y "%~dp0\temp\%%~b\%%~e" "!script_location!\%%~b\"
rd /s /q "%~dp0\temp\%%~b"
if not exist "!script_location!\%%~b\%%~e" echo An error occured while updating the script.
if exist "!script_location!\%%~b\%%~e" (
set /a script_updated_count+=1
echo %%f>"!script_location!\%%~b\hash.txt"
echo %%d>"!script_location!\%%~b\info.txt"
echo %%g>"!script_location!\%%~b\author.txt"
echo %date% %time% >"!script_location!\%%~b\last_modified.txt"
%=Extract archives=%
%=deal with cabs=%
if "%%~xe"==".cab" (
echo Extracting...
call :cab "!script_location!\%%~b\%%~e" "!script_location!\%%~b"
)
%=Deal with zips=%
if "%%~xe"==".zip" (
echo Extracting...
call :unzip "!script_location!\%%~b\%%~e" "!script_location!\%%~b\"
)
echo [+] Done.
)
)
)
)
if not defined script_count echo The script does not exist on the server.
)
exit /b
::--------------------------------------------------------------------
:info
::couldn't make a joke here if i tried.
::Chuck Norris doesn't read books, he simply stares the book down till he gets the information he wants.
::retrieves relevant information about the script from the bget server
::check for user errors
set get_bool=
set get_method=
if "%~1"=="" echo Error[i1]: Incorrect Syntax. && exit /b
for %%s in (curl js vbs bits ps) do (
if /i "%~1"=="-use%%s" (
set get_bool=yes
set get_method=%%s
if "%~2"=="" echo Error[i2]: Incorrect Syntax. && exit /b
)