forked from OpenMandrivaAssociation/omdv-build-iso
-
Notifications
You must be signed in to change notification settings - Fork 0
/
omdv-build-iso.sh
executable file
·2394 lines (2171 loc) · 102 KB
/
omdv-build-iso.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
# OpenMandriva Association 2012
# Original author: Bernhard Rosenkraenzer <[email protected]>
# Modified on 2014 by: Tomasz Paweł Gajc <[email protected]>
# Modified on 2015 by: Tomasz Paweł Gajc <[email protected]>
# Modified on 2015 by: Colin Close <[email protected]>
# Modified on 2015 by: Crispin Boylan <[email protected]>
# Modified on 2016 by: Tomasz Paweł Gajc <[email protected]>
# Modified on 2016 by: Colin Close <[email protected]>
# Modified on 2017 by: Colin Close <[email protected]>
# Mofified 0n 2018 by: Colin Close <[email protected]>
# April 2018 Major Revision to support the use of the
# dnf which replaces urpmi: Colin Close <[email protected]>
# October 2019 Revise user mode list storage <[email protected]>
# This tool is licensed under GPL license
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
#
# This tool is specified to build OpenMandriva Lx distribution ISO
main() {
# This function which starts at the top of the file is executed first from the end of file
# to ensure that all functions are read before the body of the script is run.
# All global variables need to be inside the curly braces of this function.
# Make sure MAXERRORS gets preset to a real number else parallel will error out.
# This will be overidden by the users value if given.
MAXERRORS=1
if [ "$#" -lt 1 ]; then
usage_help
exit 1
fi
for k in "$@"; do
case "$k" in
--arch=*)
EXTARCH=${k#*=}
;;
--tree=*)
TREE=${k#*=}
case "$TREE" in
lx4)
TREE=4.0
;;
*)
TREE="$TREE"
;;
esac
;;
--version=*)
VERSION=${k#*=}
if [[ "${VERSION,,}" = 'cooker' ]]; then
VERSION="$(date +%Y.0)"
fi
;;
--release_id=*)
RELEASE_ID=${k#*=}
;;
--boot-kernel-type=*)
BOOT_KERNEL_TYPE=${k#*=}
;;
--type=*)
declare -l lc
lc=${k#*=}
case "$lc" in
plasma|plasma-wayland|mate|cinnamon|lxqt|icewm|xfce4|weston|gnome3|minimal|sway|mate|edu)
TYPE="$lc"
;;
user)
TYPE=my.add
;;
*)
TYPE=$lc
printf "%s\n" "Creating iso named $TYPE" "You will need to provide the name of you window manager and the name of the executable to run it."
# printf "%s\n" "$TYPE is not supported."
# usage_help
;;
esac
;;
--displaymanager=*)
DISPLAYMANAGER=${k#*=}
;;
--workdir=*)
WORK=${k#*=}
# Expand the tilde
WORKDIR=${WORK/#\~/$HOME}
;;
--outputdir=*)
OUTPUT=${k#*=}
# Expand the tilde
OUTPUTDIR=${OUTPUT/#\~/$HOME}
;;
--listrepodir=*)
REPO=${k#*=}
# Expand the tilde
LREPODIR=${REPO/#*\~/$HOME}
;;
--debug)
DEBUG=debug
;;
--noclean)
NOCLEAN=noclean
;;
--rebuild)
REBUILD=rebuild
;;
--quicken)
QUICKEN=squashfs
;;
--compressor=*)
declare -l lcmp
lcmp=${k#*=}
case "$lcmp" in
gzip|gz|lzo|lz4|xz|zstd)
COMPTYPE=$lcmp
;;
*)
printf "%s\n" "Error: Illegal compressor name"
printf "%s\n" "Using default zstd"
COMPTYPE=zstd
exit
;;
esac
;;
--keep)
KEEP=keep
;;
--testrepo)
TESTREPO=testrepo
;;
--unsupprepo)
UNSUPPREPO=unsupprepo
;;
--repolist=*)
ENABLEREPO=${k#*=}
;;
--baserepo)
BASEREPO=baserepo
;;
--parallel)
PLLL=plll
;;
--isover=*)
ISO_VER=${k#*=}
;;
--maxerrors=*)
MAXERRORS=${k#*=}
;;
--devmode)
DEVMODE=devmode
;;
--auto-update)
AUTO_UPDATE=1
;;
--usemirrors)
USEMIRRORS=usemirrors
;;
--makelistrepo)
MAKELISTREPO=makelistrepo
;;
--defaultlang=*)
DEFAULTLANG=${k#*=}
;;
--defaultkbd=*)
DEFAULTKBD=${k#*=}
;;
--help)
usage_help
;;
*)
printf "%s\n" "Unknown argument $k" >/dev/stderr
usage_help
exit 1
;;
esac
done
# Locales aren't installed in the chroot yet (obviously), don't spew errors about that
export LANG=C
export LC_ALL=C
# We lose our cli variables when we invoke sudo so we save them
# and pass them to sudo when it is started. Also the user name is needed.
# The abf isobuilder docker instance is created with a single working directory /home/omv/iso_builder.
# This directory must not be deleted as it contains important (but hidden) config files.
# A support directory /home/omv/docker-iso-worker is also created this should also not be touched.
# When an iso build request is generated from ABF the script commandline along with the data from the git repo
# for the named branch of the script is loaded into the /home/omv/iso_builder directory and the script executed
# from that directory. If the build completes without error a directory /home/omv/iso_builder/results is created
# and the completed iso along with it's md5 and sha1 checksums are moved to it. These files are eventually uploaded
# to abf for linking and display on the build results webpage. If the results are placed anywhere else they are not displayed.
SUDOVAR=""EXTARCH="$EXTARCH "TREE="$TREE "VERSION="$VERSION "RELEASE_ID="$RELEASE_ID "TYPE="$TYPE "DISPLAYMANAGER="$DISPLAYMANAGER \
"DEBUG="$DEBUG "NOCLEAN="$NOCLEAN "REBUILD="$REBUILD "WORKDIR="$WORKDIR "OUTPUTDIR="$OUTPUTDIR "ISO_VER="$ISO_VER "ABF="$ABF "QUICKEN="$QUICKEN \
"COMPTYPE="$COMPTYPE "KEEP="$KEEP "TESTREPO="$TESTREPO "UNSUPPREPO="$UNSUPPREPO "ENABLEREPO="$ENABLEREPO "AUTO_UPDATE="$AUTO_UPDATE \
"DEVMODE="$DEVMODE "ENSKPLST="$ENSKPLST "PLLL="$PLLL "MAXERRORS="$MAXERRORS "LREPODIR="$LREPODIR "USEMIRRORS="$USEMIRRORS "BASEREPO="$BASEREPO \
"MAKELISTREPO="$MAKELISTREPO "DEFAULTLANG="$DEFAULTLANG "DEFAULTKBD="$DEFAULTKBD"
# run only when root
if [ "$(id -u)" != '0' ]; then
# We need to be root for umount and friends to work...
# NOTE the following command will only work on OMDV for the first registered user
# this user is a member of the wheel group and has root privelidges
exec sudo -E $(printf "%s\n" ${SUDOVAR}) $0 "$@"
printf "%s\n" "-> Run me as root."
exit 1
fi
if [ -n "$DEBUG" ]; then
set -x
else
set +x
fi
# Set the local build prefix
if [ -d /home/omv ] && [ -d /home/omv/docker-iso-worker ]; then
WHO=omv
else
# SUDO_USER is an environment variable from the shell it gets set if you run as sudo
WHO="$SUDO_USER"
UHOME=/home/"$WHO"
export UHOME
fi
# default definitions
DIST=omdv
[ -z "$EXTARCH" ] && EXTARCH="$(rpm -E '%{_target_cpu}')"
[ -z "$EXTARCH" ] && EXTARCH="$(uname -m)"
[ -z "${DEFAULTLANG}" ] && DEFAULTLANG="en_US.utf8"
[ -z "${DEFAULTKBD}" ] && DEFAULTKBD="us"
[ -z "${TREE}" ] && TREE=cooker
[ -z "${VERSION}" ] && VERSION="$(date +%Y.0)"
[ -z "${RELEASE_ID}" ] && RELEASE_ID=alpha
[ -z "${COMPTYPE}" ] && COMPTYPE="zstd -Xcompression-level 15"
[ -z "${MAXERRORS}" ] && MAXERRORS=1
ARCHEXCLUDE=""
printf "%s\n" $EXTARCH |grep -qE "^arm" && EXTARCH=armv7hnl
printf "%s\n" $EXTARCH |grep -qE "i.86" && EXTARCH=i686
# Exclude 32-bit compat packages on multiarch capable systems
case $EXTARCH in
znver1|x86_64)
ARCHEXCLUDE='--exclude=*.i686'
;;
aarch64)
ARCHEXCLUDE='--exclude=*.armv7hnl'
;;
esac
# always build free ISO
FREE=1
LOGDIR="."
if [ -z $ABF ]; then
IN_ABF='0'
fi
# The functions are stored in this in the order that they are executed.
# Functions that are not called directly are are commented out and are stored following the functions they are first called in
# though they may be called from alternate functions.
#
#main # Stared from the end of the script to ensure all functions are read
#usage_help ~ Does what it says on the tin
#hlpprtf # Block text formatting functions
#optprtf # Option formatting function
allowedOptions # Checks whether options are legal for operating environment
setWorkdir # Sets the workdirectory location depending on whether
# START ISO BUILD
mkeWkingEnv # Creates the working environment
#RemkWorkDir # Remake the working directory if you are rebuilding an iso.
#SaveDaTa # Saves useful chroot data for rebuilds
#RestoreDaTa # Restores data to the chroot for rebuild
SetFileList # Sets the current list repo paths.
#userISONme # Interactive menu to set user iso name and the windoe manager executable.
#cfrmISONme # Support for interactive menu.
#cfrmWMNme # Support for interactive menu.
mkeREPOdir # Creates users personal repo must always be first as it stores variables from one run to the next.
mKeBuild_id # Creates a unique build id.
mkISOLabel # Creates the iso labelling data and the UUIDS.
showInfo # Shows major options chosen.
getPkgList # Gets the package lists from git hub from barnch set by --isover.
MkeListRepo # Create git repo for pkg lists.
#MkeCmmtMsg # Creates a uniquely labelled commit message for git commits.
DtctCmmt # Check for changes and set change flag.
CarryOn # An entry point for the user build setup.
} #End of main
########################
# Start functions #
########################
# TODO:
# Test --auto-update switch
# Add --auto-upgrade
# Investigate why we can't mount our isos in plasma
CarryOn() {
InstallRepos # Installs the repo rpms if they are not already installed
updateSystem # Updates the system rpms if not already updated
createChroot # Creates chroot (proc dirs and mounts) Despatches to following funtions
#mkOmSpin # Creates an iso in the ABF environment
#getIncFiles # Recursively gets all the files included in a top level list and returns itin a variable
#createPkgList # Creates a package list from a list of package list files and returns it in a variable.
#mkUpdateChroot # Installs or updates the files in the chroot
#MyAdd # Local users package list for adding files to build
#MyRmv # Local users package list for removing files
#mkUserSpin # Creates a user chroot which includes the content of the my.add and my.rmv package lists
#updateUserSpin # Updates the user chroot with the content of the my.add and my.rmv package lists
createInitrd # Creates the initrds is able to use two different kernels and gives boot entries for both
createMemDisk # Creates a memdisk for embedding in the iso-build-lists.
createUEFI # Creates a bootable UEFI image
setupGrub2 # Configure and set up grub2
setupISOenv # Move files to ISO build directories
ClnShad # Clean out passwd locks from the chroots /etc
InstallRepos # Reinstall the repos so that the defaults are correct
createSquash # Create a squashed filesystem from the built chroot
buildIso # use xorriso to build an iso from the boot files and the squashfs
postBuild # Iso management md5sums etc
#umountAll # Function for unmounting all potentially mounted directories and devices
#errorCatch # Called on error calls umountAll and gives an exit message
FilterLogs # Provides various logs. When parallel is used gives a list of packages that failed to install
#END
}
usage_help() {
if [ -z "$EXTARCH" ] && [ -z "$TREE" ] && [ -z "$VERSION" ] && [ -z "$RELEASE_ID" ] && [ -z "$TYPE" ] && [ -z "$DISPLAYMANAGER" ]; then
printf "%b\n" ""
printf "%b\t" "Please run script with arguments" "usage $0 [options]"
printf "%b\n" "" "\t\t\t\t${ulon}${bold}GENERAL OPTIONS${normal}"
optprtf "--arch= " "Architecture of packages: i686, x86_64, znver1"
optprtf "--tree= " "Branch of software repository: cooker, lx4"
optprtf "--version=" "Version for software repository: 4.0"
optprtf "--release_id=" "Release identifer: alpha, beta, rc, final"
optprtf "--type= " "User environment type desired on ISO: plasma, mate, lxqt, icewm, xfce4, weston, gnome3, edu, minimal, user-type. ${ulon}${bold}NOTE:${normal} When type is set to ${bold}a user chosen name${normal} an interactive session will be invoked where the user will be asked for the window manager desktop file and the command required to start the desired window manager. Both entries must be valid for a proper build of the new iso. No error check is performed on the values entered. Th ese values are saved in a sub-directory of the list repo directory and are restored on each run."
hlpprtf "\t\t\tBy default the system build a minimal iso from a list repo with the user selected name. Subsequently the user may add additional include lines, packages or local filenames directories for inclusion to the my.add file in the repository named in the first step. The list repo is created ahead of the build so the script will exit after creating the intial repo to allow the user to add packages or includes to the my.add file before building the iso. On subsequent runs the program will not exit but continue on to build the iso. See also the --makelistrepo option. Switching between user created repos is accomplished by setting the --listrepodir to the desired directory."
printf "%b" "--displaymanager=" "\tDisplay Manager used in desktop environemt: sddm , none\n"
optprtf "--workdir=" "Set directory where ISO will be build The default is ~/omdv-buildchroot-<arch>"
optprtf "--outputdir=" "Set destination directory to where put final ISO file. The default is ~/omdv-buildchroot-<arch>/results"
printf "%b" "--boot-kernel-type" "\tKernel to use for booting, if different from standard kernel. Grub's menu will offer alternate kernels for booting\n"
optprtf "--auto-update" "Update the build chroot to the latest package versions. Saves rebuilding. Runs dnf --refresh distro-sync on the chroot"
printf -vl "%${COLUMNS:-`tput cols 2>&-||echo 80`}s\n" && echo ${l// /-}
printf "%b\n" "\t\t\t\t${ulon}${bold}REPOSITORY MANAGEMENT${normal}"
hlpprtf "\t\t\tSeveral options allow the selection of additional repositories in addition to the default (main). Please note that is the following options are used the selected repositories will be left enabled on the iso. If you just want the default repositories on the iso use the --baserepo switch in addition to the other selectors."
optprtf "--testrepo" "Enables the testing repo for the main repository"
optprtf "--unsupprepo" "Enables the unsupported repo"
optprtf "--repolist" "Allows a list of comma separated repoid's to enable. i.e. --repolist=unsupported,updates,restricted To obtain a list of repo-ids run 'dnf --quiet repolist --all' in a terminal. There is also a list in the documentation"
optprtf "--baserepo" "Resets the above options to the default for the repo group (rock, rolling, cooker)"
printf -vl "%${COLUMNS:-`tput cols 2>&-||echo 80`}s\n" && echo ${l// /-}
printf "%b\n" "\t\t\t\t${ulon}${bold}USER BUILDS - REMASTERING${normal}"
printf "%b\n"
hlpprtf "\t\t\tProvision is made for custom builds in the form of two files in the package list directories. These are my.add and my.rmv you can add packages names to either of these files and they will be added or removed. You may also add full paths to local rpm files and these will be installed as well. Including other package lists is also supported see the package list files with the folloing include syntax | %include .///omdv-<listname>.lst |. The my.rmv file can be used to temporarily remove packages from the package lists that are failing to install or are simple not required without the need to modify the original lists. The files are stored in a directory which is set up as a git repository; each time the script is run this directory is checked for changes and if any are found they committed to the git repository using a commmit message which contains the build-id and the number of times the script has been run for that build id thus providing a full record of the session. Note that changes to ALL the files are recorded and it is not mandatory that you use my.add or my.rmv it is just more convenient. my.rmv is the only way to remove packages from the chroot when using the --noclean and --rebuild options. To enable the user to create different custom builds and return to them easily the --lrepodir=<dirpath> option is provided. The dirpath defaults to ~/<user_name>s-user-iso but may be pointed to any directory path in the users home directory. The directory once created is never deleted by the script. It is for the user to remove redundant data directories. The script records the last used data directory and restores the content to the chroot unless --lrepodir is set to another value; then a new directory is created (if it does not already exist) with files downloaded from the github repository corresponding to the repository you wish to build against.\n"
optprtf "--lrepodir=" "The lrepodir option sets the path to the storage directory for the package lists and other iso files. Once set the path for this directory will be remembered until the value of the lrepodir dir is changedl This initiates a fresh build with virgin files from the OMA repos."
optprtf "--quicken" "Set up mksqaushfs to use no compression for faster iso builds. Intended mainly for testing"
optprtf "--noclean" "Do not clean build chroot and keep cached rpms. Updates chroot with new packages. Option will not re-install the packages it will only retain them"
printf "%b\n\n" "\t\t\tFor the following options you must have built an iso using the --noclean option before they can be applied"
optprtf "--rebuild" "Recreates the build chroot and rebuilds from cached rpms and supplementary files. This allows a developer to modify the ""fixed"" iso setup files and preserve them from one run to the next"
optprtf "--isover" "Allows the user to fetch a personal repository of build lists from their own repository. Currently the repository must reside on github as a branch of the omdv-build-iso repository"
optprtf "--usemirrors" "Use the mirrorlists to find packages; this option is only intended for use when the main ABF repositories are unavailable. It's possible that the iso will be built with out of date packages"
printf -vl "%${COLUMNS:-`tput cols 2>&-||echo 80`}s\n" && echo ${l// /-}
printf "%6b\n" "\t\t\t\t${ulon}${bold}DEVELOPER OPTIONS${normal}"
optprtf "--debug " "Enable debug output basically enables set -x. This option also allows ABF=1 to be used loacally for testing"
optprtf "--devmode" "Enables some developer aids see the README"
optprtf "--parallel" "Runs each item in the build list as a single transaction. Used in conjunction with --maxerrors=<integer> (default=1) can be used when remastering isos to allow failures due to missing or broken packages. This feature is intended for debugging iso builds and is helpful in tracking down broken dependencies. A list of failed packages is produced at the end of the run after the iso is built."
optprtf "--compressor" "This option allows a choice for the compressor to be used when the mksquashfs file is created. Valid choices are gzip, xz, lzo, lz4 and zstd."
optprtf "--keep " "Retains only the build lists from one run to another. This means that if you modify the package lists within the working directory (usually omdv-build-chroot-<arch>) they will be restored unconditionally on the next run irrespective of any other flags. This can be used to create lists for new compilations. The build lists are stored in a git repository and each time there is a change a commit is performed thus keeping a record of the users session."
optprtf "--makelistrepo" "Just make a list repo if one does not already exist the --listrepodir, --arch and --tree options must be set. Optionally the --isover option may be set to direct the script to an alternative branch on GitHub. The script will create the repo and then exit"
printf "%b\n"
printf "%b\n" "\t${ulon}${bold}For example:${normal}" " "
printf "%b\n" "\tBuild a x86_64 bit iso containg the plasma desktop with sddm as the display manager from the cooker repository"
printf "%b\n" "\t${bold}omdv-build-iso.sh --arch=x86_64 --tree=cooker --version=4.0 --release_id=alpha --type=plasma --displaymanager=sddm${normal}" " "
hlpprtf "\tCreate a user iso from the rolling tree using list files from the repository \"addrepos\" using the xz compressor to create the squashed filesystem. With this comman the user will enter an interactive session during which the iso will be named and the display manager chosen. On exit from the interactive session a user named repository will be set up and then the program will exit to allow the addition of data to indicate which packages to use to builds the new iso. When this is complete running the script a second time will build the users iso."
printf "%b\n" "\t${bold}omdv-build-iso.sh --arch=x86_64 --tree=rolling --version=4.0 --release_id=alpha --type=user --isover=addrepos --compressor=xz --displaymanager=sddm${normal}"
printf "%b\n" "\tNote that when --type is set to user the user may select their own ISO name during the execution of the script" " "
printf "%b\n" "\tFor detailed usage instructions consult the files in /usr/share/omdv-build-iso/docs/"
printf "%b\n" "\tExiting."
exit 1
else
return 0
fi
}
hlpprtf() {
#Indents text; add tabs '\t' at start of text to control indent
COLUMNS=$(tput cols)
FINAL=$(( COLUMNS - 80 ))
OP=$(printf "%b\n\t\t\t" "$1" | fmt -w "$FINAL")
printf "%s\n" "$OP"
}
optprtf() {
#Formats text for formatting program options in the help
COLUMNS=$(tput cols)
FINAL=$(( COLUMNS - 100 ))
OPT=$(printf "%s" "$1")
OPT1=$(printf "%b" "\t\t$2" | fmt -w "$FINAL" -c)
printf "%s" "$OPT"; printf "%s\n" "${OPT1//$'\n'$'\t'/$'\n'$'\t'$'\t'}"
}
bold=$(tput bold)
normal=$(tput sgr0)
ulon='\033[4m' # set underline on
allowedOptions() {
if [ "$ABF" = '1' ]; then
IN_ABF=1
printf "%s\n" "-> We are in ABF (https://abf.openmandriva.org) environment"
if [ -n "$NOCLEAN" ] && [ -n "$DEBUG" ]; then
printf "%s\n" "-> using --noclean inside ABF DEBUG instance"
elif [ -n "$NOCLEAN" ]; then
printf "%s\n" "-> You cannot use --noclean inside ABF (https://abf.openmandriva.org)"
exit 1
fi
# Allow the use of --workdir if in debug mode
if [ "$WORKDIR" != "/home/omv/build_iso" ] && [ -n "$DEBUG" ]; then
printf "%s\n" "-> using --workdir inside ABF DEBUG instance"
elif [ -n "$WORKDIR" ]; then
printf "%s\n" "-> You cannot use --workdir inside ABF (https://abf.openmandriva.org)"
exit 1
fi
if [ -n "$KEEP" ]; then
printf "%s\n" "-> You cannot use --keep inside ABF (https://abf.openmandriva.org)"
exit 1
fi
if [ -n "$NOCLEAN" ] && [ -n "$REBUILD" ]; then
printf "%s\n" "-> You cannot use --noclean and --rebuild together"
exit 1
fi
if [ -n "$REBUILD" ]; then
printf "%s\n" "-> You cannot use --rebuild inside ABF (https://abf.openmandriva.org)"
exit 1
fi
else
IN_ABF=0
fi
printf "%s\n" "In abf = $IN_ABF"
}
setWorkdir() {
# Set the $WORKDIR
# If ABF=1 then $WORKDIR codes to /bin on a local system so if you try and test with ABF=1 /bin is rm -rf ed.
# To avoid this and to allow testing use the --debug flag to indicate that the default ABF $WORKDIR path should not be used
# To ensure that the WORKDIR does not get set to /usr/bin if the script is started we check the WORKDIR path used by abf and
# To allow testing the default ABF WORKDIR is set to a different path if the DEBUG option is set and the user is non-root.
if [ "$IN_ABF" = '0' ]; then
if [ -z "$WORKDIR" ]; then
WORKDIR="$UHOME/omdv-build-chroot-$EXTARCH"
export WORKDIR
fi
# Make the directory for saving data between runs
mkdir -p "${UHOME}"/ISOBUILD
BUILDSAV="${UHOME}"/ISOBUILD
else
if [ "$IN_ABF" = '1' ] && [ -d '/home/omv/docker-iso-worker' ]; then
# We really are in ABF
printf "%s\n" "using realpath"
WORKDIR="$(realpath $(dirname "$0"))"
elif [ -n "$DEBUG" ]; then
if [ -z "$WORKDIR" ]; then
WORKDIR="$UHOME/omdv-build-chroot-$EXTARCH"
fi
printf "%s\n" "-> Debugging ABF build locally"
else
printf "%s\n" "-> DO NOT RUN THIS SCRIPT WITH ABF=1 ON A LOCAL SYSTEM WITHOUT SETTING THE DEBUG OPTION"
exit 1
fi
fi
printf "%s\n" "-> The work directory is $WORKDIR"
# Define these earlier so that files can be moved easily for the various save options
# this is where rpms are installed
CHROOTNAME="$WORKDIR/BASE"
# this is where ISO files are created
ISOROOTNAME="$WORKDIR/ISO"
mkdir -p ${CHROOTNAME}
mkdir -p ${ISOROOTNAME}
}
mkeWkingEnv() {
# User mode allows three modes of operation.
# All user modes rely on the script being run with no user options to generate the initial chroot.
# The options are:-
# --noclean Where the chroot (once generated) is reused
# --rebuild. Where the chroot/BASE is rebuilt from the initial rpm downloads
# Run without either option and with --workdir pointing to the chroot
# the script will delete the existing chroot and create a new one.
# For all modes any changes made to the pkg lists are implemented and recorded
# User mode also generates a series of diffs as a record of the multiple sessions.
# The --keep option allow these to be retained for subsequent sessions
if [ "$IN_ABF" = '0' ]; then
if [ -n "$NOCLEAN" ] && [ -d "$WORKDIR" ]; then #if NOCLEAN option selected then retain the chroot.
if [ ! -d "$COMMITDIR"/sessrec ]; then
touch "$WORKDIR"/.new
else
printf "%s\n" "-> You have chosen not to clean the base installation" \
"If your build chroot becomes corrupted you may want"\
"to take advantage of the 'rebuild' option to delete the corrupted files"\
"and build a new base installation." \
"This will be faster than dowloading the rpm packages again"
# The .new file will have been removed restore it for the next build.
touch "$WORKDIR"/.new
fi
# Note need to clean out grub uuid files here and maybe others
else
if [ -n "$REBUILD" ] && [ ! -d "$WORKDIR" ]; then
printf "%s\n" "-> Error the $WORKDIR does not exist there is nothing to rebuild." \
"-> You must run your command with the --noclean option set to create something to rebuild."
printf "%s\n" "-> No base chroot exists...creating one"
RemkWorkDir
elif [ -d "$WORKDIR" ]; then
SaveDaTa # Save data does not save the package lists sessions unless the --keep option is chosen
# It only saves the dnf rpm cache and the files in the dracut,grub2, boot, data and extraconfig directories
# which may of may not have been modified by ther user
RestoreDaTa # RestoreDaTa also cleans and recreates the $WORKDIR
fi
fi
else
# Expressly for debugging ABF=1 outside of the ABF builder
if [ "$IN_ABF" = '1' ] && [ -n "$DEBUG" ] && [ "$WHO" != 'omv' ] && [ -n "$NOCLEAN" ]; then
touch "$WORKDIR"/.new
printf "%s\n" "Using noclean inside abf mode debug instance"
else
RemkWorkDir
fi
fi
}
RemkWorkDir() {
printf "%s\n" "-> Remaking directories"
rm -rf "$WORKDIR"
mkdir -p ${WORKDIR}
# Create the mount points
mkdir -p ${CHROOTNAME}/proc ${CHROOTNAME}/sys ${CHROOTNAME}/dev ${CHROOTNAME}/dev/pts
# Create the ISO directory
mkdir -p ${ISOROOTNAME}
touch ${WORKDIR}/.new
}
SaveDaTa() {
printf "%s\n" "-> Saving config data"
if [ -n "$KEEP" ] || [ -n "$REBUILD" ]; then
printf "%s\n" "-> Saving system files for rebuild"
mv "$WORKDIR/dracut" "$BUILDSAV/dracut"
mv "$WORKDIR/grub2" "$BUILDSAV/grub2"
mv "$WORKDIR/boot" "$BUILDSAV/boot"
mv "$WORKDIR/data" "$BUILDSAV/data"
mv "$WORKDIR/extraconfig" "$BUILDSAV/extraconfig"
printf "%s\n" "-> Saving rpms for rebuild"
mv "$CHROOTNAME/var/cache/dnf/" "$BUILDSAV/dnf"
mv "$CHROOTNAME/etc/dnf/" "$BUILDSAV/etc/dnf"
fi
}
RestoreDaTa() {
printf "%s\n" "-> Cleaning WORKDIR"
# Re-creates the WORKDIR and populates it with saved data
# In the case of a rebuild the $CHROOTNAME dir is recreated and the saved rpm cache is restored to it..
rm -rf "$WORKDIR"
mkdir -p "$WORKDIR"
if [ -n "$KEEP" ] || [ -n "$REBUILD" ]; then
printf "%s\n" "-> Restoring system files"
mv "$BUILDSAV/dracut" "$WORKDIR/dracut"
mv "$BUILDSAV/grub2" "$WORKDIR/grub2"
mv "$BUILDSAV/boot" "$WORKDIR/boot"
mv "$BUILDSAV/data" "$WORKDIR/data"
mv "$BUILDSAV/extraconfig" "$WORKDIR/extraconfig"
fi
if [ -n "$REBUILD" ]; then
printf "%s\n" "-> Restoring rpms for new build"
#Remake needed directories
mkdir -p "$CHROOTNAME/proc" "$CHROOTNAME/sys" "$CHROOTNAME/dev/pts"
mkdir -p "$CHROOTNAME/var/lib/rpm" #For the rpmdb
mkdir -p "$CHROOTNAME/var/cache/dnf"
mv "$BUILDSAV/dnf" "$CHROOTNAME/var/cache/"
mv "$BUILDSAV/etc/dnf" "$CHROOTNAME/etc/dnf/"
else
# Clean out the dnf dir
cd "$BUILDSAV"||exit
if [ -d dnf ]; then
/bin/rm -r ./dnf
fi
fi
touch "$WORKDIR/.new"
}
SetFileList() {
# Assign the config build list
# This could work by just checking by checking whether the provided entry exists in the list of TYPES if it does not then this must be a user chosen name.
# we would still call the interactive session but the constraint on the naming would be removed.
case "$TYPE" in
plasma|plasma-wayland|mate|cinnamon|lxqt|icewm|xfce4|weston|gnome3|minimal|sway|mate|edu)
NEWTYPE=error
;;
*)
NEWTYPE="$TYPE"
;;
esac
if [ "$NEWTYPE" = "error" ]; then
if [ "$TYPE" = 'plasma-wayland' ]; then
FILELISTS="$WORKDIR/iso-pkg-lists-${TREE,,}/${DIST,,}-plasma.lst"
else
FILELISTS="$WORKDIR/iso-pkg-lists-${TREE,,}/${DIST,,}-${TYPE,,}.lst"
fi
elif [ "$NEWTYPE" != "error" ] && [ $IN_ABF == '1' ]; then
printf "%s\n" "You cannot create your own isos within ABF." "Please enter a legal value" "You may use the --isover=<branch name> i.e. A branch in the git repository of omdv-build-iso to pull in revised compilations of the standard lists."
errorCatch
else
printf "%s\n" "-> You are creating a user build"
hlpprtf "\t\t\t\tThis build will use the the omdv_minimal_iso.lst to create a basic iso. In addition you will need to provide the name the executable for the Window Manager and the name you wish to assign to the desktop file associated with it. At this point a list repository will be created with that name and the program will exit. This allows the user to add any desired packages and includes to the my.add list file before building the iso. On subsequent runs the program will not exit but continue on to build the iso." " "
#Check here whether .wmdeskname and .wmname are stored and if so load them into their variables.
#Hmm if the content of .repo matches that of NEWTYPE then WHAT? Load the repo name and then check for .wmdeskname and .wmname if these do'nt exist then call userISOnme to set them.
# then set COMMITDIR else if it doesn't match we need to create the COMMITDIR and call and THEN set .uisonme and .wmisoHmm ok
if [ -f "$UHOME/.repo" ]; then
if [ "$NEWTYPE" == "$(< "$UHOME/.repo")" ]; then
COMMITDIR=< "$UHOME/.repo"
fi
else
COMMITDIR="$UHOME/$NEWTYPE"
#check whether the .wmdeskname and the .wmname have been saved if true then load them if false call the routines to create them
if [ -f "$COMMITDIR"/sessrec/.wmdeskname ] && [ -f "$COMMITDIR"/sessrec/.wmname ]; then
WMDESK="$(< "${COMMITDIR}"/sessrec/.wmdeskname)"
WMNAME="$(< "${COMMITDIR}"/sessrec/.wmname)"
else
userDSKTPNme
fi
# Set the default file list for the user build.
FILELISTS="$WORKDIR/iso-pkg-lists-${TREE,,}/omdv-minimal.lst"
mkeUsrListRepo
hlpprtf "\t\tA git repository with basic build lists has been created in directory named $UHOME/$NEWTYPE. This directory is maintained as a git repository, this script will never overwrite it. Additional packages or files to be included on the iso may be added to the file my.add Packages or files that you wish to be removed may be added to the file my.rmv"
fi
fi
}
userDSKTPNme() {
# Interactive menu for managing the iso name and the window manager executable
# Works along with the two other functions cfrmISONme and cfrmWMNme set and save
# the iso and window manager names. The names are save in the list repo under the sessrec
# directory as .wmdeskname and .wmname.
if [ -f "$COMMITDIR"/sessrec/.wmdeskname ]; then
printf "%s\n" "Loading Iso name"
WMDESK="$(< "${COMMITDIR}"/sessrec/.wmdeskname)"
else
printf "%s\n" " " "Please give a name to your iso e.g Enlight" "This will also be the name of the WM desktop file associated with it"
read -r in1
printf "%s\n" "$in1"
if [ -n "$in1" ]; then
printf "%s\n" "The will be $in1" "Is this correct y or n ?"
cfrmDSKTPNme
fi
fi
if [ -f "$COMMITDIR"/sessrec/.wmname ]; then
printf "%s\n" "Loading window manager name"
WMNAME="$(< "${COMMITDIR}"/sessrec/.wmname)"
else
printf "%s\n" "Please provide the name of the window manager executable you wish to use for your desktop session."
read -r in1
printf "%s\n" "$in1"
if [ -n "$in1" ]; then
printf "%s\n" "The WM executable will be $in1" "Is this correct y or n ?"
cfrmWMNme
fi
printf "%s\n" "Your window manager executable is named $WMNAME" " "
fi
}
cfrmDSKTPNme() {
read -r in2
printf "%s\n" $in2
if [ $in2 = 'yes' ] || [ $in2 = 'y' ]; then
WMDESK="$in1"
printf "%s\n" "Your iso and window manager desktop file name will be $WMDESK" " "
return 0
fi
if [ $in2 = 'no' ] || [ $in2 = 'n' ]; then
userDSKTPNme
fi
}
cfrmWMNme() {
read -r in2
echo $in2
if [ $in2 = 'yes' ] || [ $in2 = 'y' ]; then
WMNAME="$in1"
printf "%s\n" "The WM executable will be $in1" "Is this correct y or n ?"
return 0
fi
if [ $in2 = 'no' ] || [ $in2 = 'n' ]; then
userDSKTPNme
fi
}
mkeREPOdir() {
# This function create the directory pointed to by the --listrepodir=< repo name> option
# if it does not exist. A small file (.repo) is written to the users home directory.
# This file is read on startup (if it exists) and the LREPODIR or NEWTYPE is set to the value contained in it
# One of these variables is used to set the COMMITDIR variable dependent on whether a standard or user iso is to be built.
# The variable that determines this is the TYPE variable.
# If the directory listed in the .repo file does not exit then it is created.
if [ "$IN_ABF" = '0' ]; then
if [ -n "$LREPODIR" ]; then
if [ "$LREPODIR" == "$(< "${UHOME}"/.rpodir)" ] && [ -d "$UHOME"/"$LREPODIR" ]; then
COMMITDIR="$UHOME"/"$LREPODIR"
printf "%s\n" "The package lists for this build are stored in $COMMITDIR found 1"
else
mkdir -p "$UHOME"/"$LREPODIR"/sessrec
printf "%s\n" "$LREPODIR" > "$UHOME"/.rpodir
COMMITDIR="$UHOME"/"$LREPODIR"
printf "%s\n" "The package lists for this build are stored in $COMMITDIR found 2"
fi
elif [ -n "$NEWTYPE" ] && [ "$NEWTYPE" != "error" ] && [ ! -d "$UHOME"/"$NEWTYPE"/iso-pkg-lists-"${TREE,,}"/omdv-minimal.lst ]; then
mkdir -p "$UHOME"/"$NEWTYPE"/sessrec
echo "$NEWTYPE" > "${UHOME}"/.rpodir
COMMITDIR="$UHOME"/"$NEWTYPE"
printf "%s\n" "The package lists for this build are stored in $COMMITDIR found 4"
elif [ -f "$UHOME"/.rpodir ]; then
LREPODIR="$(< "${UHOME}"/.rpodir)"
printf "%s\n" "$LREPODIR"
COMMITDIR="$UHOME"/"$LREPODIR"
printf "%s\n" "The package lists for this build are stored in $COMMITDIR found 3"
else
LREPODIR="$WHO"s-user-iso
mkdir -p "$UHOME"/"$LREPODIR"/sessrec
echo "$LREPODIR" > "${UHOME}"/.rpodir
COMMITDIR="$UHOME"/"$LREPODIR"
printf "%s\n" "The package lists for this build are stored in $COMMITDIR found 5"
fi
else
cd "$WORKDIR" || exit
COMMITDIR="${WORKDIR}"
fi
}
mKeBuild_id() {
# Makes a unique? build id
printf "%s\n" "Create the BUILD_ID"
if [ "$IN_ABF" = '0' ]; then
if [ -f "$COMMITDIR"/sessrec/.build_id ]; then
# The BUILD_ID has already been saved. Used to create commit messages.
BUILD_ID=$(cat "$COMMITDIR"/sessrec/.build_id)
else
BUILD_ID=$(date +%H%M)
printf "%s\n" ${BUILD_ID} > "$COMMITDIR"/sessrec/.build_id
fi
else
[ -z "$BUILD_ID" ] && BUILD_ID=$(date +%H%M)
fi
}
mkeUsrListRepo() {
#Creates and populates a list repository if --type=user
if [ "$IN_ABF" = '0' ]; then
if [[ (-n "$MAKELISTREPO" && -n "$LREPODIR") || -n "$NEWTYPE" ]]; then
mkeREPOdir
getPkgList
MkeListRepo
DtctCmmt
setWorkdir
if [ ! -f "$COMMITDIR"/sessrec/.wmdeskname ] && [ ! -f "$COMMITDIR"/sessrec/.wmname ]; then
printf "%s" "$WMDESK" > "$COMMITDIR/sessrec/.wmdeskname"
printf "%s" "$WMNAME" > "$COMMITDIR/sessrec/.wmname"
else #If they exist then continue i.e. exit the function to the next step.
printf "%s\n" "Building user iso $NEWTYPE"
CarryOn
fi
printf "%s\n" " " "Created local user list repo $TYPE" " "
hlpprtf "\t\t\tYou may now add package names, list files to include or paths to local package files that you wish to include in your iso to the my.add file in the list repo directory above. Running the script a second time will build an iso inclUding the packages you have added."
fi
fi
exit 0
}
mkISOLabel() {
# UUID Generation. xorriso needs a string of 16 asci digits.
# grub2 needs dashes to separate the fields..
GRUB_UUID="$(date -u +%Y-%m-%d-%H-%M-%S-00)"
ISO_DATE="$(printf "%s" "$GRUB_UUID" | sed -e s/-//g)"
# in case when i386 is passed, fall back to i686
[ "$EXTARCH" = 'i386' ] && EXTARCH=i686
[ "$EXTARCH" = 'i586' ] && EXTARCH=i686
if [ "${RELEASE_ID,,}" = 'final' ]; then
PRODUCT_ID="OpenMandrivaLx.$VERSION"
elif [ "${RELEASE_ID,,}" = 'snapshot' ]; then
RELEASE_ID="$RELEASE_ID.$(date +%Y%m%d).$BUILD_ID"
elif [ "${RELEASE_ID,,}" = 'beta' ]; then
RELEASE_ID="$RELEASE_ID.$(date +%Y%m%d).$BUILD_ID"
elif [ "${RELEASE_ID,,}" = 'alpha' ]; then
RELEASE_ID="$RELEASE_ID.$(date +%Y%m%d).$BUILD_ID"
fi
# Check if user build if true fixup name logic
if [ "$TYPE" = 'my.add' ]; then
PRODUCT_ID="OpenMandrivaLx.$VERSION-$RELEASE_ID-$NEWTYPE"
else
PRODUCT_ID="OpenMandrivaLx.$VERSION-$RELEASE_ID-$TYPE"
fi
printf "%s" "$PRODUCT_ID"
LABEL="$PRODUCT_ID.$EXTARCH"
[ $(printf "%s\n" "$LABEL" | wc -m) -gt 32 ] && LABEL="OpenMandrivaLx_$VERSION"
[ $(printf "%s\n" "$LABEL" | wc -m) -gt 32 ] && LABEL="$(printf "%s\n" "$LABEL" |cut -b1-32)"
}
showInfo() {
echo $'###\n'
printf "%s\n" "Building ISO with arguments:"
printf "%s\n" "Distribution is $DIST"
printf "%s\n" "Architecture for ISO is $EXTARCH"
printf "%s\n" "Tree is $TREE"
printf "%s\n" "Version is $VERSION"
printf "%s\n" "Release ID is $RELEASE_ID"
if [ "${TYPE,,}" = 'my.add' ]; then
printf "%s\n" "TYPE is user"
else
printf "%s\n" "Type is $TYPE"
fi
if [ "${TYPE,,}" = 'minimal' ]; then
printf "%s\n" "-> No display manager for minimal ISO."
elif [ "${TYPE,,}" = "my.add" ] && [ -z "$DISPLAYMANAGER" ]; then
printf "%s\n" "-> No display manager for user ISO."
else
printf "%s\n" "Display Manager is $DISPLAYMANAGER"
fi
printf "%s\n" "ISO label is $LABEL"
printf "%s\n" "Build ID is $BUILD_ID"
printf "%s\n" "Working directory is $WORKDIR"
if [ -n "$REBUILD" ]; then
printf "%s\n" "-> All rpms will be re-installed"
elif [ -n "$NOCLEAN" ]; then
printf "%s\n" "-> Installed rpms will be updated"
fi
if [ -n "$DEBUG" ]; then
printf "%s\n" "-> Debugging enabled"
fi
if [ -n "$QUICKEN" ]; then
printf "%s\n" "-> Squashfs compression disabled"
fi
if [ -n "$COMPTYPE" ]; then
printf "%s\n" "-> Using ${COMPTYPE} for Squashfs compression"
fi
if [ -n "$KEEP" ]; then
printf "%s\n" "-> The session diffs will be retained"
fi
printf "%s\n" "###" " "
}
getPkgList() {
# Package list handling has two modes. When the script is run on ABF the package lists are obtained from the git repos.
# The branch used will can be changed by using the --isover switch to get the lists from a different branch of the repo.
# When operated outside of ABF it is assumed that the user will wish to modify the lists to create their own custom iso.
# In this case the package lists are initially downloaded from GitHub and the versions that match the repo given on the command line
# is copied to the directory pointed to by the LREPODIR variable. The LREPODIR variable is automatically set to a default if the user
# does not provide a name. The directory name is stored in an hidden file .rpodir in the users home directory.
# A git repository is created in the LREPODIR and an an initial commit made with an automatically generated commit message which
# contains the "Build ID" and a session count which uniquely labels each commit.
# Should the user alter the files then on a subsequent iso build the files from the directory pointed to by the LREPODIR variable
# will be copied to the current working directory and a commit generated for the users changes.
# If the user wishes to create a new spin they can achieve this by setting the --listrepodir commandline option to a new directory
# where a new set of default files with their git repo will be created. Should the user wish to switch to their original iso using that directory name
# with the --listrepodir option will switch the default back to the original set of build lists. The number of directories is effectively unlimited.
printf "%s\n\n" "$FILELISTS $COMMITDIR"
if [ ! -d "$WORKDIR/iso-pkg-lists-${TREE,,}" ]; then
printf "%s\n" "-> Could not find $WORKDIR/iso-pkg-lists-${TREE,,}. Downloading from GitHub."
# download iso packages lists from https://github.com
# GitHub doesn't support git archive so we have to jump through hoops and get more file than we need
if [ -n "$ISO_VER" ]; then
export GIT_BRNCH="$ISO_VER"
elif [ ${TREE,,} == "cooker" ]; then
export GIT_BRNCH=master
else
export GIT_BRNCH=${TREE,,}
# ISO_VER defaults to user build entry
fi
cd "$WORKDIR" || exit
EX_PREF=./
EXCLUDE_LIST="--exclude ${EX_PREF}.abf.yml --exclude ${EX_PREF}ChangeLog --exclude ${EX_PREF}Developer_Info --exclude ${EX_PREF}Makefile --exclude ${EX_PREF}README --exclude ${EX_PREF}TODO --exclude ${EX_PREF}omdv-build-iso.sh --exclude ${EX_PREF}omdv-build-iso.spec --exclude ${EX_PREF}docs/* --exclude ${EX_PREF}tools/* --exclude ${EX_PREF}ancient/*"
wget -qO- https://github.com/OpenMandrivaAssociation/omdv-build-iso/archive/"${GIT_BRNCH}".zip | bsdtar -xvf- ${EXCLUDE_LIST} --strip-components 1
if [ ! -e "$FILELISTS" ]; then
printf "%s\n" "-> $FILELISTS does not exist. Exiting"
errorCatch
fi
fi
# If the list repo directory is empty populate it, create git repo and commit
# Otherwise copy contents of list repo directory to the WORKDIR.
if [ ! -f "$COMMITDIR"/${FILELISTS#$WORKDIR/} ]; then
printf "%s\n" "The local list repo directory is being populated"
popREPOdir
else
printf "%s\n" "-> Copying users local package lists from $COMMITDIR to workdir"
cp -R ${COMMITDIR}/iso-pkg-lists-${TREE}/ ${WORKDIR}/
fi
}
popREPOdir() {
# This function serves to populate a newly created package list repo after itdirectory creation by mkeREPOdir
# It is called conditionally (once and only once) when the package lists have been downloaded from the git repo.
cp -r ${WORKDIR}/iso-pkg-lists-${TREE}/ ${COMMITDIR}/
if [ ! -f ${COMMITDIR}/iso-pkg-lists-${TREE}/my.add ]; then
printf "%s\n" "There's been an error"
hlpprtf "\t\t\tPlease check whether the directory named in the hidden file .rpodir in your home directory still exists and if it does it may still have the .git directory which will allow you to recover your package lists. If no files exist please delete the .rpodir file and the directory named in it and start with a fresh build"
errorCatch
fi
}
MkeListRepo() {
# Create git repo for the package lists so we can record user mode changes.
if [ ! -d "${COMMITDIR}/iso-pkg-lists-${TREE}/.git" ]; then
printf "%s\n" "-> Creating package list repo"
cd ${COMMITDIR}/iso-pkg-lists-${TREE} || exit
git init
git add .
git config user.email "[email protected]"
git config user.name "iso buider"
MkeCmmtMsg
git commit -a -m "$CMMTMSG"
fi
}
MkeCmmtMsg() {
# Create a sequential commit message
if [ ! -d ${COMMITDIR}/sessrec ]; then
mkdir -p ${COMMITDIR}/sessrec
else
if [ -f ${COMMITDIR}/sessrec/.seqnum ]; then
SEQNUM=$(cat ${COMMITDIR}/sessrec/.seqnum)
SEQNUM=$((SEQNUM+1))
else
SEQNUM=1
fi
printf "%s\n" "$SEQNUM" >"${COMMITDIR}/sessrec/.seqnum"
SESSNO=$(cat ${COMMITDIR}/sessrec/.build_id)
CMMTMSG=$(printf "%s/n" "Changes for Build Id ${BUILD_ID}; Session No ${SEQNUM}")
fi
}
DtctCmmt() {
# Detect whether the lists have changed and if so set the change flag, generate commit msg and commit the changes.
if [ -d $COMMITDIR/iso-pkg-lists-$TREE ]; then
cd ${COMMITDIR}/iso-pkg-lists-${TREE} || exit
CHNGFLG=$(git diff)
if [ -n "$CHNGFLG" ]; then
MkeCmmtMsg
git commit -a -m "$CMMTMSG"
fi
fi
}
InstallRepos() {
# There are now different rpms available for cooker and release so these can be used to directly install the the repo files. The original function is kept just
# in case we need to revert to git again for the repo files.
#Get the repo files
if [ -e "$WORKDIR"/.new ]; then
PKGS=http://abf-downloads.openmandriva.org/"$TREE"/repository/$EXTARCH/main/release/
cd "$WORKDIR" || exit
curl -s -L $PKGS |grep '^<a' |cut -d'"' -f2 >PACKAGES
PACKAGES="distro-release-repos distro-release-repos-keys distro-release-repos-pkgprefs dnf-data"
for i in $PACKAGES; do
P=$(grep "^$i-[0-9].*" PACKAGES |tail -n1)
if [ "$?" != '0' ]; then
printf "%s\n" "Can't find $TREE version of $i, please report"
exit 1
fi
wget $PKGS/$P
done
fi
if [ -e "$WORKDIR"/.new ]; then
rpm -Uvh --root "$CHROOTNAME" --force --oldpackage --nodeps --ignorearch *.rpm
else
/bin/rm -rf "$CHROOTNAME"/etc/yum.repos.d/*.repo "$CHROOTNAME"/etc/dnf/dnf.conf
rpm --reinstall -vh --root "$CHROOTNAME" --replacefiles --nodeps --ignorearch *.rpm
fi
if [ -e "$CHROOTNAME/etc/yum.repos.d" ]; then ## we may hit ! -e that .new thing
ls -l $CHROOTNAME/etc/yum.repos.d
else
printf "%s\n" "/etc/yum.repos.d not present"
fi