forked from wimpysworld/deb-get
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdeb-get
executable file
·1586 lines (1457 loc) · 56.9 KB
/
deb-get
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
#!/usr/bin/env bash
LC_ALL=C
PACKAGE_INSTALLATION_TRIES=0
PACKAGE_INSTALLATION_COUNT=0
readonly VERSION="0.3.9"
# set a github auth token (e.g a PAT ) in DEBGET_TOKEN to get a bigger rate limit
if [ -n "${DEBGET_TOKEN}" ]; then
export HEADERAUTH="Authorization: token ${DEBGET_TOKEN}"
export HEADERPARAM="--header"
else
unset HEADERAUTH
unset HEADERPARAM
fi
function usage() {
cat <<HELP
Usage
deb-get {update [--repos-only] [--quiet] | upgrade | show <pkg list> | install <pkg list>
| reinstall <pkg list> | remove [--remove-repo] <pkg list>
| purge [--remove-repo] <pkg list>
| search [--include-unsupported] <regex> | cache | clean
| list [--include-unsupported] [--raw|--installed|--not-installed]
| prettylist [<repo>] | csvlist [<repo>] | fix-installed [--old-apps]
| help | version}
deb-get provides a high-level commandline interface for the package management
system to easily install and update packages published in 3rd party apt
repositories or via direct download.
update
update is used to resynchronize the package index files from their sources.
When --repos-only is provided, only initialize and update deb-get's
external repositories, without updating apt or looking for updates of
installed packages.
When --quiet is provided the fetching of deb-get repository updates is done without progress feedback.
upgrade
upgrade is used to install the newest versions of all packages currently
installed on the system.
install
install is followed by one package (or a space-separated list of packages)
desired for installation or upgrading.
reinstall
reinstall is followed by one package (or a space-separated list of
packages) desired for reinstallation.
remove
remove is identical to install except that packages are removed instead of
installed. When --remove-repo is provided, also remove the apt repository
of apt/ppa packages.
purge
purge is identical to remove except that packages are removed and purged
(any configuration files are deleted too). When --remove-repo is provided,
also remove the apt repository of apt/ppa packages.
clean
clean clears out the local repository (/var/cache/deb-get) of retrieved
package files.
search
search for the given regex(7) term(s) from the list of available packages
supported by deb-get and display matches. When --include-unsupported is
provided, include packages with unsupported architecture or upstream
codename and include PPAs for Debian-derived distributions.
show
show information about the given package (or a space-separated list of
packages) including their install source and update mechanism.
list
list the packages available via deb-get. When no option is provided, list
all supported packages and tell which ones are installed (slower). When
--include-unsupported is provided, include packages with unsupported
architecture or upstream codename and include PPAs for Debian-derived
distributions (faster). When --raw is provided, list all packages and do
not tell which ones are installed (faster). When --installed is provided,
only list the packages installed (faster). When --not-installed is provided,
only list the packages not installed (faster).
prettylist
markdown formatted list the packages available in repo. repo defaults to
01-main. If repo is 00-builtin or 01-main the packages from 00-builtin are
included. Use this to update README.md.
csvlist
csv formatted list the packages available in repo. repo defaults to
01-main. If repo is 00-builtin or 01-main the packages from 00-builtin are
included. Use this with 3rd party wrappers.
cache
list the contents of the deb-get cache (/var/cache/deb-get).
fix-installed
fix installed packages whose definitions were changed. When --old-apps is
provided, transition packages to new format. This command is only intended
for internal use.
help
show this help.
version
show deb-get version.
HELP
}
function package_is_installed() {
[[ " ${INSTALLED_APPS[*]} " =~ " ${1} " ]]
}
function elevate_privs() {
if [ "$(id -ru)" -eq 0 ]; then
# Alreday in the root context
ELEVATE=""
elif command -v doas 1>/dev/null && doas true 2>/dev/null; then
ELEVATE="doas"
elif command -v sudo 1>/dev/null && sudo true 2>/dev/null; then
ELEVATE="sudo"
else
fancy_message fatal "$(basename "${0}") requires sudo or doas to elevate permissions, neither were found."
fi
}
function create_cache_dir() {
if [ -d /var/cache/get-deb ]; then
${ELEVATE} mv /var/cache/get-deb "${CACHE_DIR}"
fi
${ELEVATE} mkdir -p "${CACHE_DIR}" 2>/dev/null
${ELEVATE} chmod 755 "${CACHE_DIR}" 2>/dev/null
}
function create_etc_dir() {
${ELEVATE} mkdir -p "${ETC_DIR}" 2>/dev/null
${ELEVATE} chmod 755 "${ETC_DIR}" 2>/dev/null
}
function unroll_url() {
# Sourceforge started adding parameters
local TRIM_URL="$(curl -w "%{url_effective}" -I -L -s -S "${1}" -o /dev/null)"
printf '%s' "${TRIM_URL/\.deb*/.deb}"
}
function get_github_releases() {
METHOD="github"
CACHE_FILE="${CACHE_DIR}/${APP}.json"
# Cache github releases json for 1 hour to try and prevent API rate limits
# https://docs.github.com/en/rest/overview/resources-in-the-rest-api#rate-limiting
# {"message":"API rate limit exceeded for 62.31.16.154. (But here's the good news: Authenticated requests get a higher rate limit. Check out the documentation for more details.)","documentation_url":"https://docs.github.com/rest/overview/resources-in-the-rest-api#rate-limiting"}
# curl -I https://api.github.com/users/flexiondotorg
# Do not process github releases while generating a pretty list or upgrading
if [[ ' install update fix-installed ' =~ " ${ACTION} " ]]; then
if [ ! -e "${CACHE_FILE}" ] || [ -n "$(find "${CACHE_FILE}" -mmin +"${DEBGET_CACHE_RTN:-60}")" ]; then
fancy_message info "Updating ${CACHE_FILE}"
local URL="https://api.github.com/repos/${1}/releases${2:+/$2}"
wgetcmdarray=(wget "${HEADERPARAM}" "${HEADERAUTH}" -q --no-use-server-timestamps "${URL}" -O "${CACHE_FILE}")
${ELEVATE} "${wgetcmdarray[@]}" || ( fancy_message warn "Updating ${CACHE_FILE} failed." )
if [ -f "${CACHE_FILE}" ] && grep "API rate limit exceeded" "${CACHE_FILE}"; then
fancy_message warn "Updating ${CACHE_FILE} exceeded GitHub API limits. Deleting it."
${ELEVATE} rm "${CACHE_FILE}" 2>/dev/null
fi
fi
fi
}
function get_website() {
METHOD="website"
CACHE_FILE="${CACHE_DIR}/${APP}.html"
if [[ ' install update fix-installed ' =~ " ${ACTION} " ]]; then
if [ ! -e "${CACHE_FILE}" ] || [ -n "$(find "${CACHE_FILE}" -mmin +"${DEBGET_CACHE_RTN:-60}")" ]; then
fancy_message info "Updating ${CACHE_FILE}"
if ! ${ELEVATE} wget ${WGET_VERBOSITY} --no-use-server-timestamps ${WGET_TIMEOUT} "${1}" -O "${CACHE_FILE}"; then
fancy_message warn "Updating ${CACHE_FILE} failed. Deleting it."
${ELEVATE} rm -f "${CACHE_FILE}"
fi
fi
fi
}
function fancy_message() {
if [ -z "${1}" ] || [ -z "${2}" ]; then
return
fi
local RED="\e[31m" GREEN="\e[32m" YELLOW="\e[33m" MAGENTA="\e[35m" RESET="\e[0m"
MESSAGE_TYPE="${1}"
MESSAGE="${2}"
case "${MESSAGE_TYPE}" in
(info) printf " [${GREEN}+${RESET}] %s\n" "${MESSAGE}";;
(progress) printf " [${GREEN}+${RESET}] %s" "${MESSAGE}";;
(recommend) printf " [${MAGENTA}!${RESET}] %s\n" "${MESSAGE}";;
(warn) printf " [${YELLOW}*${RESET}] WARNING! %s\n" "${MESSAGE}";;
(error) printf " [${RED}!${RESET}] ERROR! %s\n" "${MESSAGE}" >&2;;
(fatal)
printf " [${RED}!${RESET}] ERROR! %s\n" "${MESSAGE}" >&2
exit 1;;
(*) printf " [?] UNKNOWN: %s\n" "${MESSAGE}";;
esac
}
function download_deb() {
local URL="${1}"
local FILE="${2}"
if ! ${ELEVATE} wget ${WGET_VERBOSITY} --continue ${WGET_TIMEOUT} --show-progress --progress=bar:force:noscroll "${URL}" -O "${CACHE_DIR}/${FILE}"; then
fancy_message error "Failed to download ${URL}. Deleting ${CACHE_DIR}/${FILE}..."
${ELEVATE} rm "${CACHE_DIR}/${FILE}" 2>/dev/null
return 1
fi
}
function eula() {
if [ -n "${EULA}" ] && [ "${DEBIAN_FRONTEND}" != noninteractive ]; then
echo -e "${EULA}\n\n"
printf '%s\n' "Do you agree to the ${APP} EULA?"
select yn in "Yes" "No"; do
case "$yn" in
Yes) return 0;;
No) return 1;;
esac
done
fi
}
function update_apt() {
${ELEVATE} apt-get -q -o Dpkg::Progress-Fancy="1" -y update
}
function upgrade_apt() {
${ELEVATE} apt-get -q -o Dpkg::Progress-Fancy="1" -y upgrade
}
# Update only the added repo (during install action)
function update_only_repo() {
fancy_message info "Updating: /etc/apt/sources.list.d/${APT_LIST_NAME}.list"
${ELEVATE} apt-get update -o Dir::Etc::sourcelist="sources.list.d/${APT_LIST_NAME}.list" \
-o Dir::Etc::sourceparts="-" -o APT::Get::List-Cleanup="0"
}
function install_apt() {
((PACKAGE_INSTALLATION_TRIES++))
add_apt_repo
if ! update_only_repo; then
remove_repo --remove-repo --quiet
return
fi
if ! package_is_installed "${APP}"; then
if ! eula; then
remove_repo --remove-repo --quiet
return
fi
if ! ${ELEVATE} apt-get -q=2 -o Dpkg::Progress-Fancy="1" -y install "${APP}"; then
remove_repo --remove-repo --quiet
return
fi
add_installed
maint_supported_cache
else
if [ "${ACTION}" == "reinstall" ]; then
if ! ${ELEVATE} apt-get -q=2 -o Dpkg::Progress-Fancy="1" -y --reinstall --allow-downgrades install "${APP}"; then
return
fi
else
fancy_message info "${APP} is up to date."
fi
fi
((PACKAGE_INSTALLATION_COUNT++))
}
function install_ppa() {
ppa_to_apt
install_apt
}
function install_deb() {
local URL="${1}"
local FILE="${FILE:-${URL##*/}}"
local STATUS=""
((PACKAGE_INSTALLATION_TRIES++))
if ! package_is_installed "${APP}"; then
if ! eula; then
return
fi
if ! download_deb "${URL}" "${FILE}"; then
return
fi
if ! ${ELEVATE} apt-get -q=2 -o Dpkg::Progress-Fancy="1" -y install "${CACHE_DIR}/${FILE}"; then
return
fi
add_installed
maint_supported_cache
else
if [ "${ACTION}" == "reinstall" ]; then
if ! download_deb "${URL}" "${FILE}"; then
return
fi
if ! ${ELEVATE} apt-get -q=2 -o Dpkg::Progress-Fancy="1" -y --reinstall --allow-downgrades install "${CACHE_DIR}/${FILE}"; then
return
fi
elif dpkg --compare-versions "${VERSION_PUBLISHED}" gt "${VERSION_INSTALLED}"; then
if ! download_deb "${URL}" "${FILE}"; then
return
fi
if ! ${ELEVATE} apt-get -q=2 -o Dpkg::Progress-Fancy="1" -y install "${CACHE_DIR}/${FILE}"; then
return
fi
elif [ -z "${FILE}" ]; then
fancy_message warn "${APP} update check failed, moving on to next package."
else
fancy_message info "${FILE} is up to date."
fi
fi
((PACKAGE_INSTALLATION_COUNT++))
if [ -f "${CACHE_DIR}/${FILE}" ]; then
${ELEVATE} rm "${CACHE_DIR}/${FILE}" 2>/dev/null
fi
}
function remove_deb() {
local APP="${1}"
local REMOVE="${2:-remove}"
local FILE="${FILE:-${URL##*/}}"
local STATUS=""
if package_is_installed "${APP}" || [[ " ${DEPRECATED_INSTALLED[*]} " =~ " ${APP} " ]]; then
STATUS=$(dpkg-query -Wf '${Status}' "${APP}")
if [ "${STATUS}" == "deinstall ok config-files" ]; then
REMOVE="purge"
fi
${ELEVATE} apt-get -q -y --autoremove ${REMOVE} "${APP}"
remove_installed "${APP}"
maint_supported_cache
else
fancy_message info "${APP} is not installed."
fi
# Remove repos/PPA/key even if the app is not installed.
case "${METHOD}" in
direct|github|website)
if [ -f "${CACHE_DIR}/${FILE}" ]; then
fancy_message info "Removing ${CACHE_DIR}/${FILE}"
${ELEVATE} rm "${CACHE_DIR}/${FILE}" 2>/dev/null
fi
;;
apt|ppa)
remove_repo "${3}";;
esac
}
function version_deb() {
if package_is_installed "${APP}"; then
dpkg-query -Wf '${Version}' "${APP}" 2> /dev/null
# else empty output
fi
}
function info_deb() {
local INSTALLED="${VERSION_INSTALLED:-No}"
case "${METHOD}" in
(direct|github|website)
printf '%s\n' "${PRETTY_NAME}"
printf ' %s:\t%s\n' Package "${APP}" Repository "${APP_SRC}" Updater deb-get Installed "${INSTALLED}" Published "${VERSION_PUBLISHED}" Architecture "${ARCHS_SUPPORTED}" Download "${URL}" Website "${WEBSITE}" Summary "${SUMMARY}";;
(apt)
printf '%s\n' "${PRETTY_NAME}"
printf ' %s:\t%s\n' Package "${APP}" Repository "${APP_SRC}" Updater apt Installed "${INSTALLED}" Architecture "${ARCHS_SUPPORTED}" Repository "${APT_REPO_URL}" Website "${WEBSITE}" Summary "${SUMMARY}";;
(ppa)
printf '%s\n' "${PRETTY_NAME}"
printf ' %s:\t%s\n' Package "${APP}" Repository "${APP_SRC}" Updater apt Installed "${INSTALLED}" Architecture "${ARCHS_SUPPORTED}" Launchpad "${PPA}" Website "${WEBSITE}" Summary "${SUMMARY}";;
esac
}
function validate_deb() {
local FULL_APP="${1}"
export APP_SRC=${FULL_APP%/*} APP=${FULL_APP##*/}
export DEFVER=""
export ASC_KEY_URL="" GPG_KEY_URL="" GPG_KEY_ID=""
export APT_LIST_NAME="${APP}" APT_REPO_URL="" APT_REPO_OPTIONS="" PPA=""
export ARCHS_SUPPORTED="amd64" CODENAMES_SUPPORTED=""
export METHOD="direct"
export EULA=""
export VERSION_INSTALLED="" VERSION_PUBLISHED=""
export PRETTY_NAME="" SUMMARY="" WEBSITE=""
export URL=""
export CACHE_FILE="" FILE=""
# Source the variables
if [ "${APP_SRC}" == "00-builtin" ]; then
deb_"${APP}" 2>/dev/null
else
. "${ETC_DIR}/${APP_SRC}.d/${APP}" 2>/dev/null
fi
if [[ " ${ARCHS_SUPPORTED} " =~ " ${HOST_ARCH} " ]] && { [ -z "${CODENAMES_SUPPORTED}" ] || [[ " ${CODENAMES_SUPPORTED} " =~ " ${UPSTREAM_CODENAME} " ]]; } && { [ "${METHOD}" != ppa ] || [ "${UPSTREAM_ID}" == ubuntu ]; }; then
if [ -z "${DEFVER}" ] || [ -z "${PRETTY_NAME}" ] || [ -z "${SUMMARY}" ] || [ -z "${WEBSITE}" ]; then
fancy_message error "Missing required information of package ${APP}:"
printf >&2 '%s\n' "DEFVER=${DEFVER}" "PRETTY_NAME=${PRETTY_NAME}" "SUMMARY=${SUMMARY}" "WEBSITE=${WEBSITE}"
exit 1
fi
VERSION_INSTALLED=$(version_deb)
if [ -n "${APT_REPO_URL}" ]; then
METHOD="apt"
if [ "${ACTION}" != "prettylist" ]; then
if [ -z "${ASC_KEY_URL}" ] && [ -z "${GPG_KEY_URL}" ] && [ -z "${GPG_KEY_ID}" ]; then
fancy_message error "Missing required information of apt package ${APP}:"
printf >&2 '%s\n' "ASC_KEY_URL=${ASC_KEY_URL}" "GPG_KEY_URL=${GPG_KEY_URL}" "GPG_KEY_ID=${GPG_KEY_ID}"
exit 1
fi
if [ -n "${ASC_KEY_URL}" ] && [ -n "${GPG_KEY_URL}" ]; then
fancy_message error "Conflicting repository key types for apt package ${APP}:"
printf >&2 '%s\n' "ASC_KEY_URL=${ASC_KEY_URL}" "GPG_KEY_URL=${GPG_KEY_URL}" "GPG_KEY_ID=${GPG_KEY_ID}"
exit 1
fi
if [ -n "${GPG_KEY_URL}" ] && [ -n "${GPG_KEY_ID}" ]; then
fancy_message error "Conflicting repository key types for apt package ${APP}:"
printf >&2 '%s\n' "ASC_KEY_URL=${ASC_KEY_URL}" "GPG_KEY_URL=${GPG_KEY_URL}" "GPG_KEY_ID=${GPG_KEY_ID}"
exit 1
fi
if [ -n "${ASC_KEY_URL}" ] && [ -n "${GPG_KEY_ID}" ]; then
fancy_message error "Conflicting repository key types for apt package ${APP}:"
printf >&2 '%s\n' "ASC_KEY_URL=${ASC_KEY_URL}" "GPG_KEY_URL=${GPG_KEY_URL}" "GPG_KEY_ID=${GPG_KEY_ID}"
exit 1
fi
fi
elif [ -n "${PPA}" ]; then
METHOD="ppa"
else
# If the method is github and the cache file is empty, ignore the package
# The GitHub API is rate limit has likely been reached
if [ "${METHOD}" == github ] && [ ! -s "${CACHE_FILE}" ]; then
if ! [[ ' prettylist remove purge ' =~ " ${ACTION} " ]]; then
fancy_message warn "Cached file ${CACHE_FILE} is empty or missing."
${ELEVATE} rm "${CACHE_FILE}" 2>/dev/null
fi
fi
if { { [[ ' github website ' =~ " ${METHOD} " ]] && [ -s "${CACHE_FILE}" ]; } || [ "${METHOD}" == direct ]; } &&
! [[ ' prettylist remove purge ' =~ " ${ACTION} " ]] &&
{ [ -z "${URL}" ] || [ -z "${VERSION_PUBLISHED}" ]; }; then
fancy_message error "Missing required information of ${METHOD} package ${APP}:"
printf >&2 '%s\n' "URL=${URL}" "VERSION_PUBLISHED=${VERSION_PUBLISHED}"
exit 1
fi
fi
elif [ -n "${PPA}" ]; then
METHOD="ppa"
else
# If the method is github and the cache file is empty, ignore the package
# The GitHub API is rate limit has likely been reached
if [ "${METHOD}" == github ] && [ ! -s "${CACHE_FILE}" ]; then
if ! [[ ' prettylist remove purge ' =~ " ${ACTION} " ]]; then
fancy_message warn "Cached file ${CACHE_FILE} is empty or missing."
${ELEVATE} rm "${CACHE_FILE}" 2>/dev/null
fi
fi
if { { [[ ' github website ' =~ " ${METHOD} " ]] && [ -s "${CACHE_FILE}" ]; } || [ "${METHOD}" == direct ]; } &&
! [[ ' prettylist remove purge ' =~ " ${ACTION} " ]] &&
{ [ -z "${URL}" ] || [ -z "${VERSION_PUBLISHED}" ]; } &&
{ [ -z "${ARCHS_SUPPORTED}" ] || [[ " ${ARCHS_SUPPORTED} " =~ " ${HOST_ARCH} " ]]; } &&
{ [ -z "${CODENAMES_SUPPORTED}" ] || [[ " ${CODENAMES_SUPPORTED} " =~ " ${UPSTREAM_CODENAME} " ]]; }; then
fancy_message error "Missing required information of ${METHOD} package ${APP}:"
printf >&2 '%s\n' "URL=${URL}" "VERSION_PUBLISHED=${VERSION_PUBLISHED}"
exit 1
fi
fi
}
function list_debs() {
if [ "${1}" == --include-unsupported ]; then
case "${2}" in
(--raw)
printf '%s\n' "${APPS[@]##*/}"
;;
(--installed)
printf '%s\n' "${INSTALLED_APPS[@]}"
;;
(--not-installed)
printf '%s\n' "${APPS[@]##*/}" | comm -23 - <(printf '%s\n' "${INSTALLED_APPS[@]}")
;;
(*)
local PAD=' '
for FULL_APP in "${APPS[@]}"; do
local APP=${FULL_APP##*/}
if package_is_installed "${APP}"; then
printf '%s %s [ installed ]\n' "${APP}" "${PAD:${#APP}}"
else
printf '%s\n' "${APP}"
fi
done
esac
else
if [ -f "${CACHE_DIR}"/supported.list ] ; then
case "${2}" in
(--raw)
list_debs --include-unsupported --raw | comm --nocheck-order -12 ${CACHE_DIR}/supported_apps.list -
;;
(--installed)
# these don't have the [installed] tag so need a similar file to join
list_debs --include-unsupported --installed | comm --nocheck-order -12 ${CACHE_DIR}/supported_apps.list -
;;
(--not-installed)
list_debs --include-unsupported --not-installed | comm --nocheck-order -12 ${CACHE_DIR}/supported_apps.list -
;;
(--only-unsupported)
list_debs --include-unsupported --raw | comm --nocheck-order -13 ${CACHE_DIR}/supported_apps.list -
;;
(*)
# this has [ installed ] tags
list_debs --include-unsupported | comm --nocheck-order -12 ${CACHE_DIR}/supported.list -
;;
esac
else
#elevate_privs
# because we need to update the cache files this one slow time
for FULL_APP in "${APPS[@]}"; do
validate_deb "${FULL_APP}"
if [[ " ${ARCHS_SUPPORTED} " =~ " ${HOST_ARCH} " ]] && { [ -z "${CODENAMES_SUPPORTED}" ] || [[ " ${CODENAMES_SUPPORTED} " =~ " ${UPSTREAM_CODENAME} " ]]; } && { [ "${METHOD}" != ppa ] || [ "${UPSTREAM_ID}" == ubuntu ]; }; then
case "${2}" in
(--raw)
printf '%s\n' "${APP}"
;;
(--installed)
if package_is_installed "${APP}"; then
printf '%s\n' "${APP}"
fi
;;
(--not-installed)
if ! package_is_installed "${APP}"; then
printf '%s\n' "${APP}"
fi
;;
(*)
if package_is_installed "${APP}"; then
local PAD=' '
printf "%s %s [ installed ]\n" "${APP}" "${PAD:${#APP}}"
else
printf '%s\n' "${APP}"
fi
;;
esac
fi
done
fi
fi
}
function prettylist_debs() {
local REPO="${1:-01-main}"
local ICON=""
cat <<"EOMSG"
| Source | Package Name | Description |
| :------: | :------------- | :------------ |
EOMSG
for FULL_APP in "${APPS[@]}"; do
validate_deb "${FULL_APP}"
if [ "${APP_SRC}" == "${REPO}" ] || { [ "${REPO}" == "01-main" ] && [ "${APP_SRC}" == "00-builtin" ]; }; then
case "${METHOD}" in
apt) ICON="debian.png";;
github) ICON="github.png";;
ppa) ICON="launchpad.png";;
*) ICON="direct.png";;
esac
echo "| [<img src=\"../.github/${ICON}\" align=\"top\" width=\"20\" />](${WEBSITE}) | "'`'"${APP}"'`'" | <i>${SUMMARY}</i> |"
fi
done
}
function csvlist_debs() {
local REPO="${1:-01-main}"
for FULL_APP in "${APPS[@]}"; do
validate_deb "${FULL_APP}"
if [ "${APP_SRC}" == "${REPO}" ] || { [ "${REPO}" == "01-main" ] && [ "${APP_SRC}" == "00-builtin" ]; }; then
echo "\"${APP}\",\"${PRETTY_NAME}\",\"${VERSION_INSTALLED}\",\"${ARCHS_SUPPORTED}\",\"${METHOD}\",\"${SUMMARY}\""
fi
done
}
function update_debs() {
local STATUS=""
update_apt
for APP in "${INSTALLED_APPS[@]}"; do
validate_deb "${APPNAME2FULL[$APP]}"
if [ "${METHOD}" == "direct" ] || [ "${METHOD}" == "github" ] || [ "${METHOD}" == "website" ]; then
STATUS=$(dpkg-query -Wf '${Status}' "${APP}")
if [ "${STATUS}" == "install ok installed" ] && dpkg --compare-versions "${VERSION_PUBLISHED}" gt "${VERSION_INSTALLED}"; then
fancy_message info "${APP} (${VERSION_INSTALLED}) has an update pending. ${VERSION_PUBLISHED} is available."
fi
fi
done
}
function upgrade_debs() {
local STATUS=""
upgrade_apt
for APP in "${INSTALLED_APPS[@]}"; do
validate_deb "${APPNAME2FULL[$APP]}"
if [ "${METHOD}" == "direct" ] || [ "${METHOD}" == "github" ] || [ "${METHOD}" == "website" ]; then
STATUS=$(dpkg-query -Wf '${Status}' "${APP}")
if [ "${STATUS}" == "install ok installed" ]; then
install_deb "${URL}"
fi
fi
done
}
function init_repos() {
if [ ! -e "${ETC_DIR}/01-main.repo" ]; then
${ELEVATE} tee "${ETC_DIR}/01-main.repo" <<<"${MAIN_REPO_URL}" >/dev/null
fi
for REPO in $(find "${ETC_DIR}" -maxdepth 1 -name "*.repo" ! -name 00-builtin.repo ! -name 99-local.repo -type f -printf "%f\n" | sed "s/.repo$//"); do
if [ ! -e "${ETC_DIR}/${REPO}.d" ]; then
${ELEVATE} mkdir "${ETC_DIR}/${REPO}.d" 2>/dev/null
${ELEVATE} chmod 755 "${ETC_DIR}/${REPO}.d" 2>/dev/null
fi
done
}
function refresh_supported_cache_lists() {
# WARN: this function must run in a subshell
local lockfile=${CACHE_DIR}/updating_supported.lock
if [ -f "$lockfile" ]; then
fancy_message warn "Cannot update cache of supported apps: $lockfile found (job still running?)"
return 0
else
trap "trap - EXIT; ${ELEVATE} rm -f \"$lockfile\"" EXIT
${ELEVATE} touch "$lockfile"
${ELEVATE} rm -f "${CACHE_DIR}/supported.list" "${CACHE_DIR}/supported_apps.list"
fancy_message info "Updating cache of supported apps in the background"
list_debs | grep -v -e '^[[:space:]][[:space:]]*\[' | ${ELEVATE} tee "${CACHE_DIR}/supported.list.tmp" >/dev/null
${ELEVATE} mv "${CACHE_DIR}/supported.list.tmp" "${CACHE_DIR}/supported.list"
# # belt and braces no longer needed
#${ELEVATE} sed -i '/[+]/d' ${CACHE_DIR}/supported.list.tmp
cut -d" " -f 1 "${CACHE_DIR}/supported.list" | sort -u | ${ELEVATE} tee "${CACHE_DIR}/supported_apps.list" >/dev/null
fi
}
function update_repos() {
local REPO_URL=""
# preserve current behaviour for now but allow modification via env
local CURL_VERBOSITY="-q --progress-bar"
local WGET_VERBOSITY="-q"
if [[ " $* " == *' --quiet '* ]] ; then
CURL_VERBOSITY="-Ss"
WGET_VERBOSITY="-q"
fi
for REPO in $(find "${ETC_DIR}" -maxdepth 1 -name "*.repo" ! -name 00-builtin.repo ! -name 99-local.repo -type f -printf "%f\n" | sed "s/.repo$//"); do
# export REPO ETC_DIR ELEVATE # no longer needed, `| bash -` replaced with `eval`
fancy_message info "Updating ${ETC_DIR}/${REPO}"
REPO_URL="$(head -n 1 "${ETC_DIR}/${REPO}.repo")"
${ELEVATE} wget ${UPD_WGET_VERBOSITY} ${WGET_TIMEOUT} "${REPO_URL}/manifest" -O "${ETC_DIR}/${REPO}.repo"
# ${ELEVATE} rm "${ETC_DIR}/${REPO}.d/* # we currently leave old litter : either <- this or maybe rm older ones
# although so long as manifest is good we are OK
# Faster by some margin if we are hitting github
# Otherwise revert to old-style for a bespoke hosted repo
pushd "${ETC_DIR}/${REPO}.d" >/dev/null
(eval "$(
awk -F/ '/github/ {print "# fetching github repo";
print "GITREPO="$4"/"$5;\
print "BRANCH="$6;\
print "curl ${CURL_VERBOSITY} -L https://api.github.com/repos/${GITREPO}/tarball/${BRANCH} | ${ELEVATE} tar zx --wildcards \"*/${REPO}*/packages/*\" --strip-components=3"}
! /github/ {print "# fetching non-github repo";
print "tail -n +2 \"${ETC_DIR}/${REPO}.repo\" | sed \"s/^#//\" | ${ELEVATE} sort -u -o \"${ETC_DIR}/${REPO}.repo.tmp\"";\
print "${ELEVATE} wget ${UPD_WGET_VERBOSITY} ${WGET_TIMEOUT} -N -B \"${REPO_URL}/packages/\" -i \"${ETC_DIR}/${REPO}.repo.tmp\" -P \"${ETC_DIR}/${REPO}.d\"";
print "${ELEVATE} rm \"${ETC_DIR}/${REPO}.repo.tmp\""
} '\
<<<"${REPO_URL}"
)")
popd >/dev/null
done
refresh_supported_cache_lists &
}
function list_repo_apps() {
if [ -d "${ETC_DIR}" ]; then
find "${ETC_DIR}" -maxdepth 1 -name '*.repo' ! -name 00-builtin.repo ! -name 99-local.repo -type f -printf '%f\n' |
sort -r |
while IFS= read -r REPO; do
# WARN: repos can't contain '/' or '\', which the rest of the code assumes anyway
sed -n -e "1d; /^#/d; s/^/${REPO%.repo}\//p" <"${ETC_DIR}/${REPO}" | sort -u
done
fi
}
function populate_deprecated_apps() {
declare -ga DEPRECATED_APPS=() DEPRECATED_INSTALLED=()
if [ -d "${ETC_DIR}" ]; then
mapfile -t DEPRECATED_APPS < <(
find "${ETC_DIR}" -maxdepth 1 -name "*.repo" ! -name 00-builtin.repo ! -name 99-local.repo -type f -printf "%f\n" |
sort -r |
while IFS= read -r REPO; do
# sort -t ... -u may fail
sed -n -e "1d; s/^#/${REPO%.repo}\//p" <"${ETC_DIR}/${REPO}" | sort -t / -k 2 | uniq
done
)
if [ "${#DEPRECATED_APPS[@]}" -gt 0 ]; then
mapfile -t DEPRECATED_INSTALLED < <(dpkg-query 2>/dev/null -Wf '${db:Status-abbrev}${Package}\n' "${DEPRECATED_APPS[@]##*/}" | sed -n -e 's/^ii //p')
fi
fi
readonly DEPRECATED_INSTALLED
}
function list_local_apps() {
if [ -d "${ETC_DIR}/99-local.d" ]; then
find "${ETC_DIR}/99-local.d" -maxdepth 1 -type f -printf '99-local/%f\n'
fi
}
function print_etc_overrides() {
if [ ${#LOCAL_APPS[@]} -gt 0 ] || [ ${#APP_CONFLICTS[@]} -gt 0 ]; then
local DEB_GET_SCRIPT_FILE="${0}"
local NUM_OLDER_CONFLICTS=0
for APP in "${APP_CONFLICTS[@]}"; do
local FULL_APP=${APPNAME2FULL[$APP]}
fancy_message warn "Conflict detected, duplicate declaration of package ${APP}, using declaration from ${FULL_APP%/*}"
if [[ " ${LOCAL_APPS[*]} " =~ " ${FULL_APP} " ]] && [ "${DEB_GET_SCRIPT_FILE}" -nt "${ETC_DIR}/99-local.d/${APP}" ]; then
((NUM_OLDER_CONFLICTS++))
fi
done
if [ "${NUM_OLDER_CONFLICTS}" -gt 0 ]; then
fancy_message recommend "Duplicate entr(ies) already merged upstream (if no longer needed), must be manually removed from your ${ETC_DIR}/99-local.d folder."
fi
for FULL_APP in "${LOCAL_APPS[@]}"; do
fancy_message info "Including local package ${FULL_APP##*/}"
done
if [ ${#LOCAL_APPS[@]} -gt 0 ]; then
fancy_message recommend "Please consider contributing back new entries, an issue (or raise a PR) directly at https://github.com/wimpysworld/deb-get/pulls"
fi
fi
}
function print_deprecated() {
for APP in "${DEPRECATED_INSTALLED[@]}"; do
fancy_message warn "Deprecated package ${APP} detected. It will no longer receive updates, and keeping it installed is considered unsafe."
fancy_message recommend "Please remove it with: deb-get purge ${APP}"
done
}
function fix_old_apps() {
local OLD_METHOD=""
local OLD_APT_LIST_NAME=""
local OLD_PPA=""
case "${APP}" in
1password)
OLD_METHOD="apt"
OLD_APT_LIST_NAME="1password"
;;
anydesk)
OLD_METHOD="apt"
OLD_APT_LIST_NAME="anydesk-stable"
;;
appimagelauncher)
OLD_METHOD="ppa"
OLD_PPA="ppa:appimagelauncher-team/stable"
;;
atom)
OLD_METHOD="apt"
OLD_APT_LIST_NAME="atom"
;;
audio-recorder)
OLD_METHOD="ppa"
OLD_PPA="ppa:audio-recorder/ppa"
;;
azure-cli)
OLD_METHOD="apt"
OLD_APT_LIST_NAME="azure-cli"
;;
blanket)
OLD_METHOD="ppa"
OLD_PPA="ppa:apandada1/blanket"
;;
brave-browser)
OLD_METHOD="apt"
OLD_APT_LIST_NAME="brave-browser-release"
;;
cawbird)
OLD_METHOD="apt"
OLD_APT_LIST_NAME="home:IBBoard:cawbird"
;;
chronograf)
OLD_METHOD="apt"
OLD_APT_LIST_NAME="influxdata"
;;
code)
OLD_METHOD="apt"
OLD_APT_LIST_NAME="vscode"
;;
copyq)
OLD_METHOD="ppa"
OLD_PPA="ppa:hluk/copyq"
;;
cryptomator)
OLD_METHOD="ppa"
OLD_PPA="ppa:sebastian-stenzel/cryptomator"
;;
docker-ce)
OLD_METHOD="apt"
OLD_APT_LIST_NAME="docker"
;;
enpass)
OLD_METHOD="apt"
OLD_APT_LIST_NAME="enpass"
;;
firefox-esr)
OLD_METHOD="ppa"
OLD_PPA="ppa:mozillateam/ppa"
;;
foliate)
OLD_METHOD="ppa"
OLD_PPA="ppa:apandada1/foliate"
;;
fsearch)
OLD_METHOD="ppa"
OLD_PPA="ppa:christian-boxdoerfer/fsearch-stable"
;;
google-chrome-stable)
OLD_METHOD="apt"
OLD_APT_LIST_NAME="google-chrome"
;;
google-earth-pro-stable)
OLD_METHOD="apt"
OLD_APT_LIST_NAME="google-earth-pro"
;;
gpu-viewer)
OLD_METHOD="ppa"
OLD_PPA="ppa:arunsivaraman/gpuviewer"
;;
influxdb)
OLD_METHOD="apt"
OLD_APT_LIST_NAME="influxdata"
;;
influxdb2)
OLD_METHOD="apt"
OLD_APT_LIST_NAME="influxdata"
;;
influxdb2-cli)
OLD_METHOD="apt"
OLD_APT_LIST_NAME="influxdata"
;;
insync)
OLD_METHOD="apt"
OLD_APT_LIST_NAME="insync"
;;
jellyfin)
OLD_METHOD="apt"
OLD_APT_LIST_NAME="jellyfin"
;;
kapacitor)
OLD_METHOD="apt"
OLD_APT_LIST_NAME="influxdata"
;;
kdiskmark)
OLD_METHOD="ppa"
OLD_PPA="ppa:jonmagon/kdiskmark"
;;
keepassxc)
OLD_METHOD="ppa"
OLD_PPA="ppa:phoerious/keepassxc"
;;
keybase)
OLD_METHOD="apt"
OLD_APT_LIST_NAME="keybase"
;;
kopia-ui)
OLD_METHOD="apt"
OLD_APT_LIST_NAME="kopia"
;;
lutris)
OLD_METHOD="ppa"
OLD_PPA="ppa:lutris-team/lutris"
;;
microsoft-edge-stable)
OLD_METHOD="apt"
OLD_APT_LIST_NAME="microsoft-edge"
;;
neo4j)
OLD_METHOD="apt"
OLD_APT_LIST_NAME="neo4j"
;;
nextcloud-desktop)
OLD_METHOD="ppa"
OLD_PPA="ppa:nextcloud-devs/client"
;;
nomad)
OLD_METHOD="apt"
OLD_APT_LIST_NAME="nomad"
;;
obs-studio)
OLD_METHOD="ppa"
OLD_PPA="ppa:flexiondotorg/obs-fully-loaded"
;;
openrazer-meta)
OLD_METHOD="ppa"
OLD_PPA="ppa:openrazer/stable"
;;
opera-stable)
OLD_METHOD="apt"
OLD_APT_LIST_NAME="opera-stable"
;;
papirus-icon-theme)
OLD_METHOD="ppa"
OLD_PPA="ppa:papirus/papirus"
;;
plexmediaserver)
OLD_METHOD="apt"
OLD_APT_LIST_NAME="plexmediaserver"
;;
polychromatic)
OLD_METHOD="ppa"
OLD_PPA="ppa:polychromatic/stable"
;;
protonvpn)
OLD_METHOD="apt"
OLD_APT_LIST_NAME="protonvpn-stable"
;;
qownnotes)
OLD_METHOD="ppa"
OLD_PPA="ppa:pbek/qownnotes"
;;
quickemu)
OLD_METHOD="ppa"
OLD_PPA="ppa:flexiondotorg/quickemu"
;;
quickgui)
OLD_METHOD="ppa"
OLD_PPA="ppa:yannick-mauray/quickgui"
;;
resilio-sync)
OLD_METHOD="apt"
OLD_APT_LIST_NAME="resilio-sync"
;;
retroarch)
OLD_METHOD="ppa"
OLD_PPA="ppa:libretro/stable"
;;
signal-desktop)
OLD_METHOD="apt"
OLD_APT_LIST_NAME="signal-xenial.list"
;;
skypeforlinux)
OLD_METHOD="apt"
OLD_APT_LIST_NAME="skype-stable"
;;
slack-desktop)
OLD_METHOD="apt"
OLD_APT_LIST_NAME="slack"
;;
softmaker-office-2021)
OLD_METHOD="apt"
OLD_APT_LIST_NAME="softmaker"
;;
strawberry)
OLD_METHOD="ppa"
OLD_PPA="ppa:jonaski/strawberry"
;;
sublime-merge)
OLD_METHOD="apt"
OLD_APT_LIST_NAME="sublime-text"
;;
sublime-text)
OLD_METHOD="apt"
OLD_APT_LIST_NAME="sublime-text"
;;
syncthing)
OLD_METHOD="apt"
OLD_APT_LIST_NAME="syncthing"
;;
teams)
OLD_METHOD="apt"
OLD_APT_LIST_NAME="teams"
;;
telegraf)
OLD_METHOD="apt"
OLD_APT_LIST_NAME="influxdata"
;;
terraform)