-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathsbgen.sh
executable file
·1204 lines (1049 loc) · 39.6 KB
/
sbgen.sh
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
#!/bin/bash
#
# Copyright 2017-2023 Jeremy Hansen <jebrhansen -at- gmail.com>
# All rights reserved.
#
# Redistribution and use of this script, with or without modification, is
# permitted provided that the following conditions are met:
#
# 1. Redistributions of this script must retain the above copyright
# notice, this list of conditions and the following disclaimer.
#
# THIS SOFTWARE IS PROVIDED BY THE AUTHOR ''AS IS'' AND ANY EXPRESS OR IMPLIED
# WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
# MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
# EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
# PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
# OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
# WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
# OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
# ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
# This script will be used to generate the needed files for SlackBuilds
# based on the templates provided by SBo, however, they will be edited and
# ready for use (unlike downloading them directly from SBo).
# Changelog:
# v0.7.1 - 26 JUN 2024
# Clean-up coding inconsistencies and minor corrections.
# v0.7 - 25 JUN 2024
# Add doinst.sh support.
# v0.6.4 - 2 APR 2024
# Add brackets around email in SlackBuild copyright header.
# v0.6.3 - 3 JUN 2023
# Fix determining if a python source link is hashed and not using a
# proper versioned link.
# v0.6.2 - 17 MAY 2023
# Fix character counting for short description due to forgetting to
# count the colon when determining total character count.
# v0.6.1 - 18 MAR 2023
# Correct required python dependency for scripts without a setup.py,
# escaped some missed special characters, and matched the makepkg
# command with upstream's template.
# v0.6 - 16 MAR 2023
# Add correction for github and pypi/python.org links that are
# directly copied from the sites. This means no more needing to
# correct github links to provide us with the correct filenames.
# It also replaces hashed links on pypi/python.org, which prevents
# my version-bump.sh script from working.
# v0.5.2 - 13 MAR 2023
# Add new python build method for packages that don't include a
# setup.py. Adds wheel & python3-installer dependencies to respective
# build scripts.
# v0.5.1 - 13 MAR 2023
# Fix infinite loop when long description is more lines than a
# slack-desc allows
# v0.5 - 30 APR 2022
# Add interactive mode to prompt for information instead of requiring
# passing commandline options
# v0.4.4 - 24 APR 2022
# Fix regex and change slack-desc function to gen_slackdesc
# v0.4.3 - 24 APR 2022
# Add SRCVER and conf file support
# v0.4.2 - 20 APR 2022
# Add download of source with MD5SUM generation
# v0.4.1 - 20 APR 2022
# Add SRCNAM option
# v0.4 - 20 APR 2022
# Add support for short and long descriptions for slack-desc
# v0.3.1 - 8 APR 2022
# Use curly brackets on SBOUTPUT variables
# v0.3 - 7 MAR 2022
# Bump scripts to match 15.0 templates
# v0.2 - 31 MAY 2020
# Add automatic padding for slack-desc
# v0.1 - 13 APR 2017
# Initial release
# "one-liner" to find count of scripts using stock commands per script type
# for i in "\./configure \\\\" "cmake \\\\" "runghc Setup configure" "meson \\.\\. \\\\" "^perl.*\\.PL" "python. setup.py install" "gem specification"; do grep "$i" ~/sbo-github/*/*/*.SlackBuild | cut -d: f1 | uniq | wc -l; done
# ===========================================================================
# User configurable settings. Add your information here, override with shell
# variables, or create a conf file (default set to $HOME/.sbgen.conf)
CONFFILE=${CONFFILE:-"$HOME/.sbgen.conf"}
[ -f "${CONFFILE}" ] && source "${CONFFILE}"
NAME=${NAME:-Your name}
EMAIL=${EMAIL:-Your email}
YEAR=${YEAR:-$(date +%Y)}
# Location for your SlackBuild repo
SBLOC=${SBLOC:-./slackbuilds}
# ===========================================================================
function help() {
cat <<EOH
-- Usage:
$(basename "$0") [options] <1-$SCRIPTCNT> <program_name> <version> [category]
-- Option parameters :
-h : This help.
-f : Force overwriting existing directory
-p : Prompt for all options
-w <homepage> : Set the homepage (website)
-d <download> : Set the download location
-m <md5sum> : Set the md5sum
-D <download64> : Set the 64bit download
-M <md5sum64> : Set the 64bit md5sum
-r <dependencies> : Set the REQUIRES for required dependencies
(Multiples REQUIRES need to be enclosed in quotes)
-s <description> : Set the short description (use quotations)
-i : Include doinst.sh file for later pruning
-l : Prompt later for long description
-S <srcnam> : Set optional SRCNAM variable
-V <srcver> : Set optional SRCVER variable
-- Description:
This script requires passing at least the number corresponding to script
type (see below), the program name and the program version.
You can optionally pass the homepage, download, md5sum, x86_64-download,
x86_64-md5sum and any required dependencies.
If you want it placed in a certain subfolder under your SlackBuilds
directory, pass that "category". They don't have to correspond with SBo's
categories as this is only local.
-- Script types:
EOH
script_types
}
# Set script count so I don't need to remember to change the prompt range
# in the many places it is used within the script
SCRIPTCNT=8
script_types ()
{
echo -e " 1 : AutoTools (./configure && make && make install)
2 : Python (python setup.py install)
3 : CMake (mkdir build && cd build && cmake ..)
4 : Perl (perl Makefile.PL)
5 : Haskell (runghc Setup Configure)
6 : RubyGem (gem specification && gem install)
7 : Meson (mkdir build && cd build && meson ..)
8 : Other (Used for manually specifying \"build\" process)
(This list is sorted based on the frequency in SBo's 15.0 repo.)\n"
}
# Option parsing:
while getopts "hfpw:d:m:D:M:r:s:ilS:V:" OPTION
do
case $OPTION in
h ) help; exit
;;
f ) FORCE=yes
;;
p ) PROMPT=yes
;;
w ) HOMEPAGE=$OPTARG
;;
d ) DOWNLOAD=$OPTARG
;;
m ) MD5SUM=$OPTARG
;;
D ) DOWNLOAD64=$OPTARG
;;
M ) MD5SUM64=$OPTARG
;;
r ) REQUIRES=$OPTARG
;;
s ) SHORTDESC="$OPTARG"
;;
i ) DOINST=yes
;;
l ) LONGDESC=yes
;;
S ) SETSRCNAM="$OPTARG"
;;
V ) SETSRCVER="$OPTARG"
;;
* ) help; exit
;;
esac
done
shift $((OPTIND - 1))
# Display the help and exit if nothing is passed except -p
if [ $# -eq 0 ] && [ "$PROMPT" != "yes" ]; then
help
exit 1
fi
# If PROMPT is set and script type, PRGNAM, and VERSION aren't passed, prompt
# for them and CATEGORY
if [ "$PROMPT" == "yes" ] && [ -z "$1" ] || [ -z "$2" ] || [ -z "$3" ]; then
# While loop to ensure proper category is set
while true; do
echo "Available script types:"
script_types
read -erp "Please select script type from list [1-$SCRIPTCNT]: " SCRIPTNUM
# Check that it's a valid script number
if ! [[ $SCRIPTNUM =~ ^[1-$SCRIPTCNT]$ ]]; then
echo -e "\n============================================="
echo "ERROR: Invalid script type! Please try again."
echo -e "=============================================\n"
else
break
fi
done
# Ensure PRGNAM is set
while true; do
read -erp "Please provide program name (PRGNAM): " PRGNAM
if [ -n "${PRGNAM}" ]; then
break
else
echo -e "\nERROR: PRGNAM cannot be blank! Please try again.\n"
fi
done
# Ensure VERSION is set
while true; do
read -erp "Please provide version: " VERSION
if [ -n "${VERSION}" ]; then
break
else
echo -e "\nERROR: VERSION cannot be blank! Please try again.\n"
fi
done
# CATEGORY is optional, so don't check
read -erp "Please provide script category (optional): " CATEGORY
# If PROMPT is not set, error out if three arguments aren't passed
elif [ -z "$1" ] || [ -z "$2" ] || [ -z "$3" ]; then
echo -e "\n\tERROR: You must pass the script type, program name, and version.\n"
help
exit
# If more than 4 arguments are passed, error out.
elif [ "$#" -gt "4" ]; then
echo -e "\n\tERROR: Too many arguments were passed. Please check command and try again.\n"
help
exit
else
# Set the program name and version
SCRIPTNUM=$1
PRGNAM=$2
VERSION=$3
CATEGORY="$4"
fi
# Set SBOUTPUT
SBOUTPUT="${SBLOC}/${CATEGORY}/${PRGNAM}"
# Let's not overwrite an existing folder unless it is forced
if [ -e "$SBOUTPUT" ] && [ "$PROMPT" == "yes" ]; then
read -erp "$SBOUTPUT already exists. Would you like to overwrite it? y/N " answer
# If it's a yes, set FORCE
if /usr/bin/grep -qi "y" <<< "$answer"; then
FORCE=yes
else
echo "Please adjust parameters and try again."
exit 1
fi
elif [ -e "$SBOUTPUT" ] && [ "${FORCE:-no}" != "yes" ]; then
echo "$SBOUTPUT already exists. To overwrite, use $(basename "$0") -f to override"
exit 1
fi
# If the script type isn't valid, error out.
if ! [[ $SCRIPTNUM =~ ^[1-$SCRIPTCNT]$ ]]; then
echo -e "\n\tERROR: Invalid script type\n"
help
exit
fi
# Prompt for remaining options
if [ "$PROMPT" == "yes" ]; then
# Regex to check for valid webaddress and file location. Separate http from
# ftp as homepages shouldn't be ftp sites, but downloads can be.
# Thanks to https://stackoverflow.com/a/3184819/2251996 for the regex
REGEX='://[-A-Za-z0-9\+&@#/%?=~_|!:,.;]*[-A-Za-z0-9\+&@#/%=~_|]'
WEBEX='(https?)'
DOWNEX='(https?|ftp)'
# Prompt for homepage
while true; do
read -erp "Please enter homepage: " HOMEPAGE
# If a homepage was entered, check regex for proper format. If it is not
# seen as valid, prompt them to enter the same homepage a second time to
# override the regex. If no homepage was entered, exit the loop and move on
if [ -n "${HOMEPAGE}" ]; then
# If website was detected as invalid, but the user enters it a second
# time, override the regex and save the homepage
if [ "$ORIGLINK" == "$HOMEPAGE" ]; then
break
# If homepage is set, verify it is a valid address with regex
elif [[ ! ${HOMEPAGE} =~ ${WEBEX}${REGEX} ]]; then
echo -e "\nERROR: Homepage doesn't seem to be a valid website. Please try again."
echo -e "If it is valid, enter the same site again to override."
ORIGLINK="$HOMEPAGE"
# Otherwise keep the homepage entered and move on
else
break
fi
# If no homepage was entered, exit the loop
else
break
fi
done
# Prompt for 32bit/universal download
while true; do
echo -e "\nPlease enter 32bit or universal source link."
read -erp "If 32bit is unsupported, leave blank: " DOWNLOAD
# If a download was entered, check regex for proper format. If it is not
# seen as valid, prompt them to enter the same download a second time to
# override the regex. If no download was entered, assume 32bit is
# unsupported.
if [ -n "${DOWNLOAD}" ]; then
# If website was detected as invalid, but the user enters it a second
# time, override the regex and save the homepage
# Also break if UNSUPPORTED
if [ "$ORIGLINK" == "$DOWNLOAD" ] || [ "$DOWNLOAD" == "UNSUPPORTED" ]; then
break
# If homepage is set, verify it is a valid address with regex
elif [[ ! ${DOWNLOAD} =~ ${DOWNEX}${REGEX} ]]; then
echo -e "\nERROR: Download doesn't seem to be a valid link. Please try again."
echo -e "If it is valid, enter the same link again to override."
ORIGLINK="$DOWNLOAD"
# Otherwise keep the homepage entered and move on
else
break
fi
# If nothing was entered, assume 32bit is not supported
else
DOWNLOAD="UNSUPPORTED"
break
fi
done
# Prompt for 32bit/universal md5sum
if [ -n "$DOWNLOAD" ] && [ "$DOWNLOAD" != "UNSUPPORTED" ]; then
echo -e "\nEnter md5sum for 32bit/universal source."
read -erp "Leave blank to have it auto-generated: " MD5SUM
fi
# Prompt for 64bit download
while true; do
echo -e "\nPlease enter 64bit source link. Leave blank if previous link was universal."
read -erp "If 64bit is unsupported, please type \"UNSUPPORTED\": " DOWNLOAD64
# If a download was entered, check regex for proper format. If it is not
# seen as valid, prompt them to enter the same download a second time to
# override the regex. If 64bit is unsupported, prompt user to enter that.
# If no download is entered, assume the script does not require a special
# download for 64bit.
if [ -n "${DOWNLOAD64}" ]; then
# If website was detected as invalid, but the user enters it a second
# time, override the regex and save the homepage
# Also break if UNSUPPORTED
if [ "$ORIGLINK" == "$DOWNLOAD64" ] || [ "$DOWNLOAD" == "UNSUPPORTED" ]; then
break
# If homepage is set, verify it is a valid address with regex
elif [[ ! ${DOWNLOAD64} =~ ${DOWNEX}${REGEX} ]] || [ ! "$DOWNLOAD64" == "UNSUPPORTED" ] ; then
echo -e "\nERROR: Download doesn't seem to be a valid link. Please try again."
echo -e "If it is valid, enter the same link again to override."
ORIGLINK="$DOWNLOAD64"
# Otherwise keep the homepage entered and move on
else
break
fi
# If nothing was entered, exit the loop
else
break
fi
done
# Prompt for 64bit md5sum
if [ -n "$DOWNLOAD64" ] && [ "$DOWNLOAD64" != "UNSUPPORTED" ]; then
echo -e "\nEnter md5sum for 64bit source."
read -erp "Leave blank to have it auto-generated: " MD5SUM64
fi
# Enter any dependencies
read -erp "Please enter any required dependencies (otherwise leave blank): " REQUIRES
# Does it need a doinst.sh?
read -erp "Does this program need a doinst.sh? y/N " answer
if /usr/bin/grep -qi "y" <<< "$answer"; then
DOINST=yes
fi
# Prompt for SRCNAM -- needed for perl SlackBuilds
if [ "$SCRIPTNUM" -ne "4" ]; then
read -erp "Set separate source name (SRCNAM) variable (otherwise leave blank): " SETSRCNAM
else
echo -e "\nPerl scripts set SRCNAM automatically by removing the \"perl-\" from the PRGNAM."
echo "Leaving this to the defaults would have SRCNAM be \"$(echo "$PRGNAM" | cut -d- -f2-)\"."
read -erp "Leave blank unless you want to override: " SETSRCNAM
SRCorPRG="SRCNAM"
fi
# Prompt for SRCVER
read -erp "Set separate source version (SRCVER) variable (otherwise leave blank): " SETSRCVER
# Try and keep the short description within the length of the handy ruler
while true; do
# Prep some variables for our sanity checks and make sure they didn't add
# a closing parenthesis that shouldn't be there
if [ -n "$SHORTDESC" ]; then
SHORTLENGTH="$(( ${#PRGNAM} + ${#SHORTDESC} ))"
OPENPAREN="${SHORTDESC//[^(]}"
CLOSEPAREN="${SHORTDESC//[^)]}"
# If there are fewer opening parenthesis than closing and the last character
# is a closing parenthesis, remove it
if [ "${#OPENPAREN}" -lt "${#CLOSEPAREN}" ] && [ "${SHORTDESC: -1}" == ")" ]; then
SHORTDESC="${SHORTDESC:: -1}"
fi
fi
# If not already set, prompt for short description in slack-desc
if [ -z "$SHORTDESC" ] && [ -z "$LOOP" ]; then
read -erp "Set short description for slack-desc (otherwise leave blank): " SHORTDESC
LOOP=yes
# If it is set, check and see if it is too long for the slack-desc
elif [ "$SHORTLENGTH" -gt "67" ]; then
echo "Short description is too long."
# Display the "handy ruler" to better show size requirements
echo "|-----handy-ruler------------------------------------------------------|"
echo ": $PRGNAM ($SHORTDESC)"
echo "Please try again (leave off the closing parenthesis)"
read -erp ": $PRGNAM (" SHORTDESC
# Otherwise exit the loop
else
unset LOOP
break
fi
done
# Prompt to see if they'd like to add a long description later
echo -e "\nWould you like to enter the long description for slack-desc?"
read -erp "If yes, this will be prompted for later: y/N " answer
# If it's a yes, set LONGDESC
if /usr/bin/grep -qi "y" <<< "$answer"; then
LONGDESC=yes
fi
# Give us a blank line
echo
fi
# Set up SRCNAM if used
if [ -n "$SETSRCNAM" ] && [ "$SCRIPTNUM" -ne "4" ]; then
SRCorPRG="SRCNAM"
# Perl scripts are unique in determining SRCNAM automatically.
# If a user manually set SRCNAM, ask them if they're sure they want to use it
elif [ -n "$SETSRCNAM" ] && [ "$SCRIPTNUM" -eq "4" ]; then
echo "Perl scripts set SRCNAM automatically by removing the \"perl-\" from the PRGNAM."
echo "You manually specified $SETSRCNAM when the script would set it to $(echo "$PRGNAM" | cut -d- -f2-)."
read -erp "Would you like to keep your manually set name? y/N " answer
# If it's a yes, set SRCorPRG
if /usr/bin/grep -qi "y" <<< "$answer"; then
SRCorPRG="SRCNAM"
else
SETSRCNAM=
SRCorPRG="PRGNAM"
fi
# If SETSRCNAM is not set for perl scripts, default to auto-setting it
elif [ -z "$SETSRCNAM" ] && [ "$SCRIPTNUM" -eq "4" ]; then
SRCorPRG="SRCNAM"
# Otherwise assume they don't need SRCNAM
else
SRCorPRG="PRGNAM"
fi
# Set up SRCVER if used
if [ -n "$SETSRCVER" ]; then
SRCorVER="SRCVER"
else
SRCorVER="VERSION"
fi
function SBintro() {
mkdir -p "$SBOUTPUT"
# Let's create the copyright header
cat << EOF > "${SBOUTPUT}"/"$PRGNAM".SlackBuild
#!/bin/bash
# Slackware build script for $PRGNAM
# Copyright $YEAR $NAME <$EMAIL>
# All rights reserved.
#
# Redistribution and use of this script, with or without modification, is
# permitted provided that the following conditions are met:
#
# 1. Redistributions of this script must retain the above copyright
# notice, this list of conditions and the following disclaimer.
#
# THIS SOFTWARE IS PROVIDED BY THE AUTHOR "AS IS" AND ANY EXPRESS OR IMPLIED
# WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
# MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
# EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
# PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
# OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
# WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
# OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
# ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
EOF
# Now we'll set up the section for variables, extracting the source, and
# changing permissions.
cat << EOF >> "${SBOUTPUT}"/"$PRGNAM".SlackBuild
cd \$(dirname \$0) ; CWD=\$(pwd)
PRGNAM=$PRGNAM
VERSION=\${VERSION:-$VERSION}
EOF
# Add SRCNAM and SRCVER if set
if [ -n "$SETSRCNAM" ]; then
echo "SRCNAM=\${SRCNAM:-$SETSRCNAM}" >> "${SBOUTPUT}"/"$PRGNAM".SlackBuild
fi
if [ -n "$SETSRCVER" ]; then
echo "SRCVER=\${SRCVER:-$SETSRCVER}" >> "${SBOUTPUT}"/"$PRGNAM".SlackBuild
fi
# Resume some more
cat << EOF >> "${SBOUTPUT}"/"$PRGNAM".SlackBuild
BUILD=\${BUILD:-1}
TAG=\${TAG:-_SBo}
PKGTYPE=\${PKGTYPE:-tgz}
EOF
# Add SRCNAM for perl scripts per the perl template
if [ "$SCRIPTNUM" -eq "4" ] && [ -z "$SETSRCNAM" ]; then
echo -e "SRCNAM=\"\$(printf \$PRGNAM | cut -d- -f2-)\"\n" >> "${SBOUTPUT}"/"$PRGNAM".SlackBuild
fi
# Resume the rest
cat << EOF >> "${SBOUTPUT}"/"$PRGNAM".SlackBuild
if [ -z "\$ARCH" ]; then
case "\$( uname -m )" in
i?86) ARCH=i586 ;;
arm*) ARCH=arm ;;
*) ARCH=\$( uname -m ) ;;
esac
fi
if [ ! -z "\${PRINT_PACKAGE_NAME}" ]; then
echo "\$PRGNAM-\$VERSION-\$ARCH-\$BUILD\$TAG.\$PKGTYPE"
exit 0
fi
TMP=\${TMP:-/tmp/SBo}
PKG=\$TMP/package-\$PRGNAM
OUTPUT=\${OUTPUT:-/tmp}
if [ "\$ARCH" = "i586" ]; then
SLKCFLAGS="-O2 -march=i586 -mtune=i686"
LIBDIRSUFFIX=""
elif [ "\$ARCH" = "i686" ]; then
SLKCFLAGS="-O2 -march=i686 -mtune=i686"
LIBDIRSUFFIX=""
elif [ "\$ARCH" = "x86_64" ]; then
SLKCFLAGS="-O2 -fPIC"
LIBDIRSUFFIX="64"
else
SLKCFLAGS="-O2"
LIBDIRSUFFIX=""
fi
set -e
rm -rf \$PKG
mkdir -p \$TMP \$PKG \$OUTPUT
cd \$TMP
EOF
}
# Extract section with optional SRCNAM and SRCVER support
function SBextract() {
cat << EOF >> "${SBOUTPUT}"/"$PRGNAM".SlackBuild
rm -rf \$${SRCorPRG}-\$${SRCorVER}
tar xvf \$CWD/\$${SRCorPRG}-\$${SRCorVER}.tar.gz
cd \$${SRCorPRG}-\$${SRCorVER}
chown -R root:root .
find -L . \\
\\( -perm 777 -o -perm 775 -o -perm 750 -o -perm 711 -o -perm 555 \\
-o -perm 511 \\) -exec chmod 755 {} \\; -o \\
\\( -perm 666 -o -perm 664 -o -perm 640 -o -perm 600 -o -perm 444 \\
-o -perm 440 -o -perm 400 \\) -exec chmod 644 {} \\;
EOF
}
# 2179 autotools scripts
function SBautotools() {
cat << EOF >> "${SBOUTPUT}"/"$PRGNAM".SlackBuild
CFLAGS="\$SLKCFLAGS" \\
CXXFLAGS="\$SLKCFLAGS" \\
./configure \\
--prefix=/usr \\
--libdir=/usr/lib\${LIBDIRSUFFIX} \\
--sysconfdir=/etc \\
--localstatedir=/var \\
--mandir=/usr/man \\
--docdir=/usr/doc/\$PRGNAM-\$VERSION \\
--disable-static \\
--build=\$ARCH-slackware-linux
make
make install DESTDIR=\$PKG
rm -f \$PKG/{,usr/}lib\${LIBDIRSUFFIX}/*.la
EOF
}
# 848 python scripts
function SBpython () {
# This will automatically add python3 support. Please remove it if you don't want it.
cat << EOF >> "${SBOUTPUT}"/"$PRGNAM".SlackBuild
# For python2
python2 setup.py install --root=\$PKG
# For python3
python3 setup.py install --root=\$PKG
# For no setup.py (requires python3-build as dependency)
python3 -m build --wheel --no-isolation
python3 -m installer --destdir=\$PKG dist/*.whl
EOF
}
#578 cmake scripts
function SBcmake () {
cat << EOF >> "${SBOUTPUT}"/"$PRGNAM".SlackBuild
mkdir -p build
cd build
cmake \\
-DCMAKE_C_FLAGS:STRING="\$SLKCFLAGS" \\
-DCMAKE_CXX_FLAGS:STRING="\$SLKCFLAGS" \\
-DCMAKE_INSTALL_PREFIX=/usr \\
-DLIB_SUFFIX=\${LIBDIRSUFFIX} \\
-DMAN_INSTALL_DIR=/usr/man \\
-DCMAKE_BUILD_TYPE=Release ..
make
make install/strip DESTDIR=\$PKG
cd ..
rm -f \$PKG/{,usr/}lib\${LIBDIRSUFFIX}/*.la
EOF
}
# 58 meson scripts
function SBmeson () {
cat << EOF >> "${SBOUTPUT}"/"$PRGNAM".SlackBuild
mkdir build
cd build
CFLAGS="\$SLKCFLAGS" \\
CXXFLAGS="\$SLKCFLAGS" \\
meson .. \\
--buildtype=release \\
--infodir=/usr/info \\
--libdir=/usr/lib\${LIBDIRSUFFIX} \\
--localstatedir=/var \\
--mandir=/usr/man \\
--prefix=/usr \\
--sysconfdir=/etc \\
-Dstrip=true
"\${NINJA:=ninja}"
DESTDIR=\$PKG \$NINJA install
cd ..
rm -f \$PKG/{,usr/}lib\${LIBDIRSUFFIX}/*.la
EOF
}
# 551 perl scripts
function SBperl () {
cat << EOF >> "${SBOUTPUT}"/"$PRGNAM".SlackBuild
# Build method #1 (preferred)
perl Makefile.PL \\
PREFIX=/usr \\
INSTALLDIRS=vendor \\
INSTALLVENDORMAN1DIR=/usr/man/man1 \\
INSTALLVENDORMAN3DIR=/usr/man/man3
make
make test
make install DESTDIR=\$PKG
# Build method #2
# requires perl-Module-Build or perl-Module-Build-Tiny
perl Build.PL \\
--installdirs vendor \\
--config installvendorman1dir=/usr/man/man1 \\
--config installvendorman3dir=/usr/man/man3
./Build
./Build test
./Build install \\
--destdir \$PKG
EOF
}
# 328 haskell scripts
function SBhaskell () {
cat << EOF >> "${SBOUTPUT}"/"$PRGNAM".SlackBuild
CFLAGS="\$SLKCFLAGS" \\
CXXFLAGS="\$SLKCFLAGS" \\
runghc Setup configure \\
--prefix=/usr \\
--libdir=/usr/lib\${LIBDIRSUFFIX} \\
--libsubdir=ghc-\${GHC_VERSION}/\$SRCNAM-$VERSION \\
--enable-shared \\
--enable-library-profiling \\
--docdir=/usr/doc/\$PRGNAM-\$VERSION
runghc Setup build
runghc Setup haddock
runghc Setup copy --destdir=\$PKG
runghc Setup register --gen-pkg-config
PKGCONFD=/usr/lib\${LIBDIRSUFFIX}/ghc-\${GHC_VERSION}/package.conf.d
PKGID=\$( grep -E "^id: " \$SRCNAM-\$VERSION.conf | cut -d" " -f2 )
mkdir -p \$PKG/\$PKGCONFD
mv \$SRCNAM-\$VERSION.conf \$PKG/\$PKGCONFD/\$PKGID.conf
EOF
}
# 91 ruby scripts
function SBruby () {
cat << EOF >> "${SBOUTPUT}"/"$PRGNAM".SlackBuild
DESTDIR=\$( ruby -r rbconfig -e '
include RbConfig
printf("%s/%s/gems/%s\n",
CONFIG["libdir"],
CONFIG["RUBY_INSTALL_NAME"],
CONFIG["ruby_version"]
)
')
gem specification \$CWD/\$SRCNAM-\$VERSION.gem | \\
ruby -r yaml -r rbconfig -e '
c = RbConfig::CONFIG
path = sprintf("%s/%s/gems/%s",
c["libdir"],
c["RUBY_INSTALL_NAME"],
c["ruby_version"])
sys_gemspecs = Dir.glob(path + "/specifications/**/*.gemspec").map {|g| gs = Gem::Specification.load(g); gs.name }
obj = Gem::Specification.from_yaml(\$stdin)
obj.dependencies.each {|dep|
if not(dep.type == :runtime)
next
end
if not(sys_gemspecs.include?(dep.name))
\$stderr.write("WARNING: #{dep.name} gem not found\n")
sleep 0.5
end
}'
gem install \\
--local \\
--no-update-sources \\
--ignore-dependencies \\
--backtrace \\
--install-dir \$PKG/\$DESTDIR \\
--bindir \$PKG/usr/bin \\
\$CWD/\$SRCNAM-\$VERSION.gem
find \$PKG -print0 | xargs -0 file | grep -e "executable" -e "shared object" | grep ELF \\
| cut -f 1 -d : | xargs strip --strip-unneeded 2> /dev/null || true
mkdir -p \$PKG/usr/doc/\$PRGNAM-\$VERSION
tar -x -O --file=\$CWD/\$SRCNAM-\$VERSION.gem data.tar.gz \\
| tar -xz -C \$PKG/usr/doc/\$PRGNAM-\$VERSION --file=- \\
<documentation>
cat \$CWD/\$PRGNAM.SlackBuild > \$PKG/usr/doc/\$PRGNAM-\$VERSION/\$PRGNAM.SlackBuild
EOF
}
function SBstrip_docs() {
cat << EOF >> "${SBOUTPUT}"/"$PRGNAM".SlackBuild
find \$PKG -print0 | xargs -0 file | grep -e "executable" -e "shared object" | grep ELF \\
| cut -f 1 -d : | xargs strip --strip-unneeded 2> /dev/null || true
find \$PKG/usr/man -type f -exec gzip -9 {} \\;
for i in \$( find \$PKG/usr/man -type l ) ; do ln -s \$( readlink $i ).gz \$i.gz ; rm \$i ; done
rm -f \$PKG/usr/info/dir
gzip -9 \$PKG/usr/info/*.info*
find \$PKG -name perllocal.pod -o -name ".packlist" -o -name "*.bs" | xargs rm -f || true
mkdir -p \$PKG/usr/doc/\$PRGNAM-\$VERSION
cp -a \\
<documentation> \\
\$PKG/usr/doc/\$PRGNAM-\$VERSION
cat \$CWD/\$PRGNAM.SlackBuild > \$PKG/usr/doc/\$PRGNAM-\$VERSION/\$PRGNAM.SlackBuild
EOF
}
function SBclosing() {
cat << EOF >> "${SBOUTPUT}"/"$PRGNAM".SlackBuild
mkdir -p \$PKG/install
cat \$CWD/slack-desc > \$PKG/install/slack-desc
EOF
# Only add the line if doinst.sh was requested
if [ "$DOINST" == "yes" ]; then
echo -e "cat \$CWD/doinst.sh > \$PKG/install/doinst.sh" >> "${SBOUTPUT}"/"$PRGNAM".SlackBuild
# Add the doinst.sh file
cat << EOF > "${SBOUTPUT}"/doinst.sh
# \$RCSfile: doinst.sh,v $
# \$Revision: 1.9 $
# \$Date: 2023-05-11 07:58:15+01 $
# DW
# NOTE DO:
# PLEASE only keep the functions/sections/commands that you need.
# PLEASE delete EVERYTHING else (including these comments).
# PLEASE let us know in the comment section of the upload form if including
# custom functions or commands.
# NOTE PLEASE DO NOT:
# Add or change user or group accounts.
# Change any of the default system settings files.
# Add commands that take forever to complete.
# Use applications like checkinstall or installwatch, that 'touch' every file
# on the system.
# NOTE on paths
# Most commands do not have an initial '/' in directory path arguments so that
# they work correctly when using pkgtools --root <path> or \$ROOT options.
# Installpkg and friends chdir to \$ROOT or --root <path> before installing packages.
# The exceptions are the 'chroot' commands which do use an initial '/'.
# The chroot command is used to avoid files on the host being changed when
# using --root or \$ROOT.
#
# Example: /usr/bin/update-desktop-database -q usr/share/applications
# ^Full path for command^ ^No initial slash^
# NOTE on tests
# [ -e <path> ] => Tests if a directory or file exists.
# [ -x <command> ] => Tests if command is executable.
# Will also fail silently if not -e too.
# NOTE on redirections
# Most commands redirect stdout and stderr to /dev/null to keep down the noise.
# If you need to see error messages while testing, the easiest way is to
# temporarily comment out 2>&1.
# FUNCTION: config()
# DESCRIPTION: Discards identical copies of config and rc.INIT files.
# ARGUMENTS: A single filename.
# NOTE
# Files should be installed with a .new extension.
# Example: etc/rc.d/rc.myshinynewdaemon.new
# We don't clobber if it's avoidable.
# "slackpkg new-config" is one way that users can list+process .new files.
config() {
NEW="\$1"
OLD="\$(dirname \$NEW)/\$(basename \$NEW .new)"
# If there's no config file by that name, mv it over:
if [ ! -r \$OLD ]; then
mv \$NEW \$OLD
elif [ "\$(cat \$OLD | md5sum)" = "\$(cat \$NEW | md5sum)" ]; then
# toss the redundant copy
rm \$NEW
fi
# Otherwise, we leave the .new copy for the admin to consider...
}
# FUNCTION: preserve_perms()
# DESCRIPTION: Keeps the executable bit that a user may have set (or unset) on
# an rc.INIT or config file since she first installed a package.
# ARGUMENTS: A single filename.
# NOTE
# This calls the above config() function to discard identical copies.
# Files should be installed with a .new extension.
# Use for files in etc/rc.d/ and etc/profile.d/
# Other config files may also need this.
preserve_perms() {
NEW="\$1"
OLD="\$(dirname \$NEW)/\$(basename \$NEW .new)"
if [ -e \$OLD ]; then
cp -a \$OLD \${NEW}.incoming
cat \$NEW > \${NEW}.incoming
mv \${NEW}.incoming \$NEW
fi
config \$NEW
}
# FUNCTION: schema_install()
# DESCRIPTION: Installs options (schemas) to the gnome config database.
# ARGUMENTS: A single filename.
# NOTE Not to be confused with glib schemas
schema_install() {
SCHEMA="\$1"
GCONF_CONFIG_SOURCE="xml::etc/gconf/gconf.xml.defaults" \
chroot . gconftool-2 --makefile-install-rule \
/etc/gconf/schemas/\$SCHEMA \
1>/dev/null
}
# Examples (NOTE must be *after* their respective function definitions!)
# Does the finished package have files in etc/gconf/schemas/?
schema_install blah.schemas
# Does the finished package have init files in etc/rc.d/?
preserve_perms etc/rc.d/rc.INIT.new
# Does the finished package have config files in etc/?
config etc/configfile.new
# DESCRIPTION: Updates the system desktop database.
# Does the finished package have a .desktop file in usr/share/applications/?
if [ -x /usr/bin/update-desktop-database ]; then
/usr/bin/update-desktop-database -q usr/share/applications >/dev/null 2>&1
fi
# DESCRIPTION: Updates the system mime database.
# Does the finished package have files in usr/share/mime/?
if [ -x /usr/bin/update-mime-database ]; then
/usr/bin/update-mime-database usr/share/mime >/dev/null 2>&1
fi
# DESCRIPTION: Updates the GTK icon cache.
# Does the finished package have files in usr/share/icons/hicolor/?
# If other icon themes are installed, then add to/modify this as needed
if [ -e usr/share/icons/hicolor/icon-theme.cache ]; then
if [ -x /usr/bin/gtk-update-icon-cache ]; then
/usr/bin/gtk-update-icon-cache -f usr/share/icons/hicolor >/dev/null 2>&1
fi
fi
# DESCRIPTION: GSettings (glib2) schema compiler.
# Does the finished package have files in usr/share/glib-2.0/schemas/?
# NOTE Not to be confused with gnome setting schemas
if [ -e usr/share/glib-2.0/schemas ]; then
if [ -x /usr/bin/glib-compile-schemas ]; then
/usr/bin/glib-compile-schemas usr/share/glib-2.0/schemas >/dev/null 2>&1
fi
fi
# DESCRIPTION: Updates the GIO cache.
# Does the finished package have files in /usr/lib(64)/gio/modules/?
# If needed -- be sure to sed @LIBDIR@ inside the build script
# Example: sed -i "s|@LIBDIR@|/usr/lib\$LIBDIRSUFFIX|g" doinst.sh
# NOTE An initial '/' in the lib dir here because of 'chroot'.
# NOTE Be sure to use double-quotes ""
chroot . /usr/bin/gio-querymodules @LIBDIR@/gio/modules/ 1> /dev/null >/dev/null 2>&1
EOF
echo "A doinst.sh file was added, but it will need modification to be useful."
echo "Please edit accordingly (maybe use sbopkglint for pointers)."
fi
cat << EOF >> "${SBOUTPUT}"/"$PRGNAM".SlackBuild
cd \$PKG
/sbin/makepkg -l y -c n \$OUTPUT/\$PRGNAM-\$VERSION-\$ARCH-\$BUILD\$TAG.\$PKGTYPE
EOF
echo "Created ${SBOUTPUT}/${PRGNAM}.SlackBuild"
}
# Try to correct for weird download links (github and pypi, I'm looking at you)
function check_download() {
TESTURL="$1"
DOMAIN="$(echo "$TESTURL" | cut -d"/" -f 3)"
# If SRCNAM/SRCVER are not set, set them to PRGNAM/VERSION to simplify URLs
if [ -z "$SETSRCNAM" ]; then
SETSRCNAM="$PRGNAM"
fi
if [ -z "$SETSRCVER" ]; then