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
|
#!/usr/bin/env bash
set -eu
SCRIPT="$(dirname "${0}")"
export SERENITY_ARCH="${SERENITY_ARCH:-i686}"
export SERENITY_TOOLCHAIN="${SERENITY_TOOLCHAIN:-GCC}"
if [ -z "${HOST_CC:=}" ]; then
export HOST_CC="${CC:=cc}"
export HOST_CXX="${CXX:=c++}"
export HOST_AR="${AR:=ar}"
export HOST_RANLIB="${RANLIB:=ranlib}"
export HOST_PATH="${PATH:=}"
export HOST_READELF="${READELF:=readelf}"
export HOST_OBJCOPY="${OBJCOPY:=objcopy}"
export HOST_PKG_CONFIG_DIR="${PKG_CONFIG_DIR:=}"
export HOST_PKG_CONFIG_SYSROOT_DIR="${PKG_CONFIG_SYSROOT_DIR:=}"
export HOST_PKG_CONFIG_LIBDIR="${PKG_CONFIG_LIBDIR:=}"
fi
DESTDIR="/"
maybe_source() {
if [ -f "$1" ]; then
. "$1"
fi
}
enable_ccache() {
if command -v ccache &>/dev/null; then
ccache_tooldir="${SERENITY_BUILD_DIR}/ccache"
mkdir -p "$ccache_tooldir"
for tool in gcc g++ c++; do
ln -sf "$(command -v ccache)" "${ccache_tooldir}/${SERENITY_ARCH}-pc-serenity-${tool}"
done
export PATH="${ccache_tooldir}:$PATH"
fi
}
target_env() {
maybe_source "${SCRIPT}/.hosted_defs.sh"
}
target_env
host_env() {
export CC="${HOST_CC}"
export CXX="${HOST_CXX}"
export AR="${HOST_AR}"
export RANLIB="${HOST_RANLIB}"
export PATH="${HOST_PATH}"
export READELF="${HOST_READELF}"
export OBJCOPY="${HOST_OBJCOPY}"
export PKG_CONFIG_DIR="${HOST_PKG_CONFIG_DIR}"
export PKG_CONFIG_SYSROOT_DIR="${HOST_PKG_CONFIG_SYSROOT_DIR}"
export PKG_CONFIG_LIBDIR="${HOST_PKG_CONFIG_LIBDIR}"
enable_ccache
}
packagesdb="${DESTDIR}/usr/Ports/packages.db"
makeopts=("-j$(nproc)")
installopts=()
configscript=configure
configopts=()
useconfigure=false
config_sub_path=config.sub
config_guess_path=config.guess
use_fresh_config_sub=false
use_fresh_config_guess=false
depends=()
patchlevel=1
auth_type=
auth_import_key=
auth_opts=()
launcher_name=
launcher_category=
launcher_command=
launcher_run_in_terminal=false
icon_file=
. "$@"
shift
: "${workdir:=$port-$version}"
cleanup_git() {
echo "WARNING: Reverting changes to $workdir as we are in dev mode!"
run git clean -xffd >/dev/null 2>&1
}
# Use the local git target repo as the workdir
# Make sure to clean it up afterwards
if [ -n "${IN_SERENITY_PORT_DEV:-}" ]; then
echo "WARNING: All changes to the workdir in the current state (inside ./package.sh dev) are temporary!"
echo " They will be reverted once the command exits!"
nongit_workdir="$workdir"
workdir=".$workdir-git"
trap "run cleanup_git" EXIT
fi
run_nocd() {
echo "+ $@ (nocd)" >&2
("$@")
}
run() {
echo "+ $@"
(cd "$workdir" && "$@")
}
run_replace_in_file() {
if [ "$(uname -s)" = "SerenityOS" ]; then
run sed -i "$1" $2
else
run perl -p -i -e "$1" $2
fi
}
get_new_config_sub() {
config_sub="${1:-config.sub}"
if [ ! -f "$workdir/$config_sub" ]; then
>&2 echo "Error: Downloaded $config_sub does not replace an existing file!"
exit 1
fi
if ! run grep -q serenity "$config_sub"; then
run do_download_file "https://git.savannah.gnu.org/gitweb/?p=config.git;a=blob_plain;f=config.sub" "${1:-config.sub}" false
fi
}
get_new_config_guess() {
config_guess="${1:-config.guess}"
if [ ! -f "$workdir/$config_guess" ]; then
>&2 echo "Error: Downloaded $config_guess does not replace an existing file!"
exit 1
fi
if ! run grep -q SerenityOS "$config_guess"; then
run do_download_file "https://git.savannah.gnu.org/gitweb/?p=config.git;a=blob_plain;f=config.guess" "${1:-config_guess}" false
fi
}
ensure_new_config_sub() {
get_new_config_sub "$config_sub_path"
}
ensure_new_config_guess() {
get_new_config_guess "$config_guess_path"
}
ensure_build() {
# Sanity check.
if [ ! -f "${DESTDIR}/usr/lib/libc.so" ]; then
echo "libc.so could not be found. This likely means that SerenityOS:"
echo "- has not been built and/or installed yet"
echo "- has been installed in an unexpected location"
echo "The currently configured build directory is ${SERENITY_BUILD_DIR}. Resolve this issue and try again."
exit 1
fi
}
install_main_icon() {
if [ -n "$icon_file" ] && [ -n "$launcher_command" ]; then
local launcher_binary="${launcher_command%% *}"
install_icon "$icon_file" "${launcher_binary}"
fi
}
install_icon() {
if [ "$#" -lt 2 ]; then
echo "Syntax: install_icon <icon> <launcher>"
exit 1
fi
local icon="$1"
local launcher="$2"
command -v convert >/dev/null || true
local convert_exists=$?
command -v identify >/dev/null || true
local identify_exists=$?
if [ "${convert_exists}" != "0" ] || [ "${identify_exists}" != 0 ]; then
echo 'Unable to install icon: missing convert or identify, did you install ImageMagick?'
return
fi
for icon_size in "16x16" "32x32"; do
index=$(run identify "$icon" | grep "$icon_size" | grep -oE "\[[0-9]+\]" | tr -d "[]" | head -n1)
if [ -n "$index" ]; then
run convert "${icon}[${index}]" "app-${icon_size}.png"
else
run convert "$icon[0]" -resize $icon_size "app-${icon_size}.png"
fi
done
run $OBJCOPY --add-section serenity_icon_s="app-16x16.png" "${DESTDIR}${launcher}"
run $OBJCOPY --add-section serenity_icon_m="app-32x32.png" "${DESTDIR}${launcher}"
}
install_main_launcher() {
if [ -n "$launcher_name" ] && [ -n "$launcher_category" ] && [ -n "$launcher_command" ]; then
install_launcher "$launcher_name" "$launcher_category" "$launcher_command"
fi
}
install_launcher() {
if [ "$#" -lt 3 ]; then
echo "Syntax: install_launcher <name> <category> <command>"
exit 1
fi
local launcher_name="$1"
local launcher_category="$2"
local launcher_command="$3"
local launcher_filename="${launcher_name,,}"
launcher_filename="${launcher_filename// /}"
local icon_override=""
case "$launcher_command" in
*\ *)
mkdir -p $DESTDIR/usr/local/libexec
launcher_executable="/usr/local/libexec/$launcher_filename"
cat >"$DESTDIR/$launcher_executable" <<SCRIPT
#!/bin/sh
exec $(printf '%q ' $launcher_command)
SCRIPT
chmod +x "$DESTDIR/$launcher_executable"
icon_override="IconPath=${launcher_command%% *}"
;;
*)
launcher_executable="$launcher_command"
;;
esac
mkdir -p $DESTDIR/res/apps
cat >$DESTDIR/res/apps/$launcher_filename.af <<CONFIG
[App]
Name=$launcher_name
Executable=$launcher_executable
Category=$launcher_category
RunInTerminal=$launcher_run_in_terminal
${icon_override}
CONFIG
}
# Checks if a function is defined. In this case, if the function is not defined in the port's script, then we will use our defaults. This way, ports don't need to include these functions every time, but they can override our defaults if needed.
func_defined() {
PATH= command -V "$1" > /dev/null 2>&1
}
func_defined pre_fetch || pre_fetch() {
:
}
func_defined post_fetch || post_fetch() {
:
}
do_download_file() {
local url="$1"
local filename="$2"
local accept_existing="${3:-true}"
echo "Downloading URL: ${url}"
# FIXME: Serenity's curl port does not support https, even with openssl installed.
if which curl >/dev/null 2>&1 && ! curl https://example.com -so /dev/null; then
url=$(echo "$url" | sed "s/^https:\/\//http:\/\//")
fi
# download files
if $accept_existing && [ -f "$filename" ]; then
echo "$filename already exists"
else
if which curl; then
run_nocd curl ${curlopts:-} "$url" -L -o "$filename"
else
run_nocd pro "$url" > "$filename"
fi
fi
}
fetch() {
pre_fetch
if [ "$auth_type" = "sig" ] && [ ! -z "${auth_import_key}" ]; then
# import gpg key if not existing locally
# The default keyserver keys.openpgp.org prints "new key but contains no user ID - skipped"
# and fails. Use a different key server.
gpg --list-keys $auth_import_key || gpg --keyserver hkps://keyserver.ubuntu.com --recv-key $auth_import_key
fi
tried_download_again=0
while true; do
OLDIFS=$IFS
IFS=$'\n'
for f in $files; do
IFS=$OLDIFS
read url filename auth_sum<<< $(echo "$f")
do_download_file "$url" "$filename"
done
verification_failed=0
OLDIFS=$IFS
IFS=$'\n'
for f in $files; do
IFS=$OLDIFS
read url filename auth_sum<<< $(echo "$f")
# check sha256sum if given
if [ "$auth_type" = "sha256" ]; then
echo "Expecting ${auth_type}sum: $auth_sum"
calc_sum="$(sha256sum $filename | cut -f1 -d' ')"
echo "${auth_type}sum($filename) = '$calc_sum'"
if [ "$calc_sum" != "$auth_sum" ]; then
# remove downloaded file to re-download on next run
rm -f $filename
echo "${auth_type}sums mismatching, removed erronous download."
if [ $tried_download_again -eq 1 ]; then
echo "Please run script again."
exit 1
fi
echo "Trying to download the files again."
tried_download_again=1
verification_failed=1
fi
fi
done
# check signature
if [ "$auth_type" = "sig" ]; then
if $NO_GPG; then
echo "WARNING: gpg signature check was disabled by --no-gpg-verification"
else
if $(gpg --verify "${auth_opts[@]}"); then
echo "- Signature check OK."
else
echo "- Signature check NOT OK"
for f in $files; do
rm -f $f
done
rm -rf "$workdir"
echo " Signature mismatching, removed erronous download."
if [ $tried_download_again -eq 1 ]; then
echo "Please run script again."
exit 1
fi
echo "Trying to download the files again."
tried_download_again=1
verification_failed=1
fi
fi
fi
if [ $verification_failed -ne 1 ]; then
break
fi
done
# extract
OLDIFS=$IFS
IFS=$'\n'
for f in $files; do
IFS=$OLDIFS
read url filename auth_sum<<< $(echo "$f")
if [ ! -f "$workdir"/.${filename}_extracted ]; then
case "$filename" in
*.tar.gz|*.tgz)
run_nocd tar -xzf "$filename"
run touch .${filename}_extracted
;;
*.tar.gz|*.tar.bz|*.tar.bz2|*.tar.xz|*.tar.lz|.tbz*|*.txz|*.tgz)
run_nocd tar -xf "$filename"
run touch .${filename}_extracted
;;
*.gz)
run_nocd gunzip "$filename"
run touch .${filename}_extracted
;;
*.zip)
run_nocd bsdtar xf "$filename" || run_nocd unzip -qo "$filename"
run touch .${filename}_extracted
;;
*.asc)
run_nocd gpg --import "$filename" || true
;;
*)
echo "Note: no case for file $filename."
;;
esac
fi
done
post_fetch
}
func_defined pre_install || pre_install() {
:
}
func_defined pre_patch || pre_patch() {
:
}
func_defined patch_internal || patch_internal() {
# patch if it was not yet patched (applying patches multiple times doesn't work!)
if [ -z "${IN_SERENITY_PORT_DEV:-}" ] && [ -d patches ]; then
for filepath in patches/*.patch; do
filename=$(basename $filepath)
if [ ! -f "$workdir"/.${filename}_applied ]; then
run patch -p"$patchlevel" < "$filepath"
run touch .${filename}_applied
fi
done
fi
}
func_defined pre_configure || pre_configure() {
:
}
func_defined configure || configure() {
chmod +x "${workdir}"/"$configscript"
run ./"$configscript" --host="${SERENITY_ARCH}-pc-serenity" "${configopts[@]}"
}
func_defined post_configure || post_configure() {
:
}
func_defined build || build() {
run make "${makeopts[@]}"
}
func_defined install || install() {
run make DESTDIR=$DESTDIR "${installopts[@]}" install
}
func_defined post_install || post_install() {
echo
}
func_defined clean || clean() {
if [ -z "${IN_SERENITY_PORT_DEV:-}" ]; then
rm -rf "$workdir" *.out
else
rm -rf "$nongit_workdir" *.out
fi
}
func_defined clean_dist || clean_dist() {
OLDIFS=$IFS
IFS=$'\n'
for f in $files; do
IFS=$OLDIFS
read url filename hash <<< $(echo "$f")
rm -f "$filename"
done
}
func_defined clean_all || clean_all() {
if [ -z "${IN_SERENITY_PORT_DEV:-}" ]; then
rm -rf "$workdir" *.out
else
rm -rf "$nongit_workdir" *.out
fi
OLDIFS=$IFS
IFS=$'\n'
for f in $files; do
IFS=$OLDIFS
read url filename hash <<< $(echo "$f")
rm -f "$filename"
done
}
addtodb() {
if [ -n "$(package_install_state $port $version)" ]; then
echo "Note: $port $version already installed."
return
fi
echo "Adding $port $version to database of installed ports..."
if [ "${1:-}" = "--auto" ]; then
echo "auto $port $version" >> "$packagesdb"
else
echo "manual $port $version" >> "$packagesdb"
fi
if [ "${#depends[@]}" -gt 0 ]; then
echo "dependency $port ${depends[@]}" >> "$packagesdb"
fi
echo "Successfully installed $port $version."
}
ensure_packagesdb() {
if [ ! -f "$packagesdb" ]; then
mkdir -p "$(dirname $packagesdb)"
touch "$packagesdb"
fi
}
package_install_state() {
local port=$1
local version=${2:-}
ensure_packagesdb
grep -E "^(auto|manual) $port $version" "$packagesdb" | cut -d' ' -f1
}
installdepends() {
for depend in "${depends[@]}"; do
if [ -z "$(package_install_state $depend)" ]; then
(cd "../$depend" && ./package.sh --auto)
fi
done
}
uninstall() {
if [ "$(package_install_state $port)" != "manual" ]; then
>&2 echo "Error: $port is not installed. Cannot uninstall."
return
elif [ ! -f plist ]; then
>&2 echo "Error: This port does not have a plist yet. Cannot uninstall."
return
fi
for f in `cat plist`; do
case $f in
*/)
run rmdir "${DESTDIR}/$f" || true
;;
*)
run rm -rf "${DESTDIR}/$f"
;;
esac
done
# Without || true, mv will not be executed if you are uninstalling your only remaining port.
grep -v "^manual $port " "$packagesdb" > packages.db.tmp || true
mv packages.db.tmp "$packagesdb"
}
do_installdepends() {
echo "Installing dependencies of $port..."
installdepends
}
do_fetch() {
echo "Fetching $port..."
fetch
}
do_patch() {
echo "Patching $port..."
pre_patch
patch_internal
}
do_configure() {
ensure_build
if [ "$useconfigure" = "true" ]; then
echo "Configuring $port..."
if "$use_fresh_config_sub"; then
ensure_new_config_sub
fi
if "$use_fresh_config_guess"; then
ensure_new_config_guess
fi
pre_configure
configure
post_configure
else
echo "This port does not use a configure script. Skipping configure step."
fi
}
do_build() {
ensure_build
echo "Building $port..."
build
}
do_install() {
ensure_build
pre_install
echo "Installing $port..."
install
install_main_launcher
install_main_icon
post_install
addtodb "${1:-}"
}
do_clean() {
echo "Cleaning workdir and .out files in $port..."
clean
}
do_clean_dist() {
echo "Cleaning dist in $port..."
clean_dist
}
do_clean_all() {
echo "Cleaning all in $port..."
clean_all
}
do_uninstall() {
echo "Uninstalling $port..."
uninstall
}
do_showproperty() {
while [ $# -gt 0 ]; do
if ! declare -p "${1}" > /dev/null 2>&1; then
echo "Property '$1' is not set." >&2
exit 1
fi
property_declaration="$(declare -p "${1}")"
if [[ "$property_declaration" =~ "declare -a" ]]; then
prop_array="${1}[@]"
# Some magic to avoid empty arrays being considered unset.
echo "${!prop_array+"${!prop_array}"}"
else
echo ${!1}
fi
printf '\n'
shift
done
}
do_all() {
do_installdepends
do_fetch
do_patch
do_configure
do_build
do_install "${1:-}"
}
do_shell() {
do_installdepends
do_fetch
do_patch
cd "$workdir"
bash
echo "End of package shell. Back to the User shell."
}
do_generate_patch_readme() {
if [ ! -d patches ]; then
>&2 echo "Error: Port $port does not have any patches"
exit 1
fi
if [ -f patches/ReadMe.md ]; then
read -N1 -rp \
"A ReadMe.md already exists, overwrite? (N/y) " should_overwrite
echo
if [ "${should_overwrite,,}" != y ]; then
>&2 echo "Not overwriting Ports/$port/patches/ReadMe.md"
exit 0
fi
fi
rm -fr .patches.tmp
mkdir .patches.tmp
echo "# Patches for $port on SerenityOS" > patches/ReadMe.md
echo >> patches/ReadMe.md
pushd patches
local tempdir="../.patches.tmp"
local count=0
for patch in *.patch; do
git mailinfo \
"$tempdir/$patch.msg" \
/dev/null \
< "$patch" \
> "$tempdir/$patch.info" \
2> "$tempdir/$patch.error" \
|| {
rc=$?
>&2 echo "Failed to extract patch info from $patch"
>&2 echo "git returned $rc and said:"
>&2 cat "$tempdir/$patch.error"
exit 1
}
(
grep 'Subject: ' "$tempdir/$patch.info" | sed -e 's/Subject: \(.*\)$/\1/'
echo
cat "$tempdir/$patch.msg"
) > "$tempdir/$patch.desc"
if [ ! -s "$tempdir/$patch.desc" ]; then
>&2 echo "WARNING: $patch does not contain a valid git patch or is missing a commit message, and is going to be skipped!"
continue
fi
{
echo "## \`$patch\`"
echo
cat "$tempdir/$patch.desc"
echo
} >> ReadMe.md
count=$((count + 1))
done
popd
>&2 echo "Successfully generated entries for $count patch(es) in patches/ReadMe.md."
}
launch_user_shell() {
env \
IN_SERENITY_PORT_DEV="$port" \
"${SHELL:-bash}" || \
true
}
prompt_yes_no() {
read -N1 -rp \
"$1 (N/y) " result
2>&1 echo
if [ "${result,,}" == y ]; then
return 0
else
return 1
fi
}
do_dev() {
if [ -n "${IN_SERENITY_PORT_DEV:-}" ]; then
>&2 echo "Error: Already in dev environment for $IN_SERENITY_PORT_DEV"
exit 1
fi
git_repo=".$workdir-git"
[ -d "$git_repo" ] || (
mv "$workdir" "$git_repo"
pushd "$git_repo"
if [ ! -d "$git_repo/.git" ]; then
git init .
git add .
git commit -a -m 'Initial import'
fi
# Make it allow pushes from other local checkouts
git config receive.denyCurrentBranch ignore
# Import patches as commits, or ask the user to commit them
# if they're not git patches already.
if [ -d ../patches ] && [ -n "$(find ../patches -maxdepth 1 -name '*.patch' -print -quit)" ]; then
for patch in ../patches/*.patch; do
if [ -f "$workdir/.$(basename $patch).applied" ]; then
continue
fi
echo "Importing patch $patch..."
git am "$patch" >/dev/null 2>&1 || {
git am --abort >/dev/null 2>&1 || true
if git apply < $patch; then
git add -A
if prompt_yes_no "- This patch does not appear to be a git patch, would you like to modify its changes before continuing?"; then
>&2 echo "Apply any changes you want, commit them into the current repo and quit this shell to continue."
launch_user_shell
fi
git commit --verbose
else
# The patch didn't apply, oh no!
# Ask the user to figure it out :shrug:
git am "$patch" || true
>&2 echo "- This patch does not apply, you'll be dropped into a shell to investigate and fix this, quit the shell when the problem is resolved."
>&2 echo "Note that the patch needs to be committed into the current repository!"
launch_user_shell
fi
if ! git diff --quiet >/dev/null 2>&1; then
>&2 echo "- It appears that there are uncommitted changes from applying the previous patch:"
for line in $(git diff --color=always); do
echo "| $line"
done
if prompt_yes_no "- Would you like to drop them before moving on to the next patch?"; then
git clean -xf
else
>&2 echo "- The uncommitted changes will be committed with the next patch or left in the tree."
fi
fi
}
done
fi
popd
)
[ -d "$git_repo" ] && [ ! -d "$workdir" ] && {
git clone "$git_repo" "$workdir"
}
[ -d "$workdir/.git" ] || {
>&2 echo "$workdir does not appear to be a git repository, if you did this manually, you're on your own"
if prompt_yes_no "Otherwise, press 'y' to remove that directory and clone it again"; then
rm -fr "$workdir"
git clone "$git_repo" "$workdir"
else
exit 1
fi
}
local first_hash="$(git -C "$git_repo" rev-list --max-parents=0 HEAD)"
launch_user_shell
local current_hash="$(git -C "$git_repo" rev-parse HEAD)"
# If the hashes are the same, we have no patches, otherwise generate patches
if [ "$first_hash" != "$current_hash" ]; then
>&2 echo "Note: Regenerating patches as there are some commits in the port repo (started at $first_hash, now is $current_hash)"
rm -fr patches/*.patch
git -C "$git_repo" format-patch "$first_hash" -o "$(realpath patches)"
do_generate_patch_readme
fi
}
NO_GPG=false
parse_arguments() {
if [ -z "${1:-}" ]; then
do_all
return
fi
case "$1" in
fetch|patch|shell|configure|build|install|installdepends|clean|clean_dist|clean_all|uninstall|showproperty|generate_patch_readme)
method=$1
shift
do_${method} "$@"
;;
--auto)
do_all $1
;;
--no-gpg-verification)
NO_GPG=true
shift
parse_arguments $@
;;
interactive)
export PS1="(serenity):\w$ "
bash --norc
;;
dev)
shift
if [ "${1:-}" != "--no-depends" ]; then
do_installdepends
fi
if [ -d "$workdir" ] && [ ! -d "$workdir/.git" ]; then
if prompt_yes_no "- Would you like to clean the working direcory (i.e. ./package.sh clean)?"; then
do_clean
fi
fi
do_fetch
do_dev
;;
*)
>&2 echo "I don't understand $1! Supported arguments: fetch, patch, configure, build, install, installdepends, interactive, clean, clean_dist, clean_all, uninstall, showproperty, generate_patch_readme, dev."
exit 1
;;
esac
}
parse_arguments $@
|