-
Notifications
You must be signed in to change notification settings - Fork 1
/
install.sh
executable file
·1296 lines (1245 loc) · 45.6 KB
/
install.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
# -*- mode: sh; indent-tabs-mode: nil; sh-basic-offset: 2; -*-
# vim: et sts=2 sw=2
set -euo pipefail
NONINTERACTIVE="${NONINTERACTIVE:-}"
NOGUI="${NOGUI:-}"
NOAUTOUPDATE="${NOAUTOUPDATE:-}"
NOCONVERTHOME="${NOCONVERTHOME:-}"
CUSTOMPROMPT="${CUSTOMPROMPT:-}"
STEAMOS_BTRFS_HOME_MOUNT_OPTS="${STEAMOS_BTRFS_HOME_MOUNT_OPTS:-}"
STEAMOS_BTRFS_HOME_MOUNT_SUBVOL="${STEAMOS_BTRFS_HOME_MOUNT_SUBVOL:-}"
STEAMOS_BTRFS_ROOTFS_PACMAN_EXTRA_PKGS="${STEAMOS_BTRFS_ROOTFS_PACMAN_EXTRA_PKGS:-}"
# Defaults
STEAMOS_BTRFS_INSTALL_PATH='/usr/share/steamos-btrfs'
NONINTERACTIVE_DEFAULT=0
NOGUI_DEFAULT=0
NOAUTOUPDATE_DEFAULT=0
NOAUTOUPDATE_FILE_FLAG="${STEAMOS_BTRFS_INSTALL_PATH}/disableautoupdate"
NOCONVERTHOME_DEFAULT=0
NOCONVERTHOME_FILE_FLAG="${STEAMOS_BTRFS_INSTALL_PATH}/disableconverthome"
STEAMOS_BTRFS_HOME_MOUNT_OPTS_DEFAULT='defaults,nofail,x-systemd.growfs,noatime,lazytime,compress-force=zstd,space_cache=v2,autodefrag,nodiscard'
STEAMOS_BTRFS_HOME_MOUNT_SUBVOL_DEFAULT='@'
STEAMOS_BTRFS_ROOTFS_PACMAN_EXTRA_PKGS_DEFAULT=''
CONFIGFILE='/etc/default/steamos-btrfs'
LOGFILE='/var/log/steamos-btrfs.log'
PKGS=(f2fs-tools reiserfsprogs kdialog wmctrl patch exfatprogs compsize rmlint duperemove)
PKGS_SIZE="${#PKGS[@]}"
ROOTFS_DEVICES=('/dev/disk/by-partsets/self/rootfs')
ROOTFS_DEVICE='/dev/disk/by-partsets/self/rootfs'
ROOTFS_MOUNTPOINT=''
VAR_DEVICE=''
VAR_MOUNTPOINT=''
HOME_DEVICE='/dev/disk/by-partsets/shared/home'
HOME_DEVICE_STATIC='/dev/disk/by-partsets/shared/home'
HOME_MOUNTPOINT='/home'
PACMAN_CACHE=''
GIT_BRANCH='main'
UPDATER_PATH=''
oPATH="${PATH:-}"
oLD_LIBRARY_PATH="${LD_LIBRARY_PATH:-/usr/local/lib:/usr/lib}"
SCRIPT="$0"
SCRIPT_ARGS=("$@")
WORKDIR="$(realpath "$(dirname "$0")")"
eprint() {
echo -e ":: $*" >&2
}
cmd() {
eprint '[$]' "${@@Q}"
"$@"
}
is_true() {
local v="${1:-}"
v="${v//[[:space:]]/}"
v="${v,,}"
if [[ -n "${v}" && "${v}" != '0' && "${v}" != 'n' && "${v}" != 'no' && "${v}" != 'false' ]]; then
return 0
else
return 1
fi
}
# Prompt the user for input
# $1 Title
# $2 Message
# $3 Yes label (optional)
# $4 No label (optional)
# $5 Cancel label (optional)
#
# env var EPROMPT_VALUE_DEFAULT to specify the default truth value that is asked for
#
# Returns 0 => OK
# 1 => No
# 2 => Cancel
eprompt() {
local title="${1:-}"
if [[ -n "${title}" ]]; then
title="SteamOS Btrfs - ${title}"
else
title='SteamOS Btrfs'
fi
local msg="${2:-}"
local yeslabel="${3:-Yes}"
local nolabel="${4:-No}"
local cancellabel="${5:-Cancel}"
local defaultvalue="${EPROMPT_VALUE_DEFAULT:-1}"
local resp
eprint "(${title}) ${msg}"
if is_true "${NONINTERACTIVE}" || [[ ! -t 0 ]]; then
if is_true "${defaultvalue}"; then
eprint '[Y/n]: y'
return 0
else
eprint '[N/y]: n'
return 1
fi
elif [[ -n "${CUSTOMPROMPT}" ]]; then
if EPROMPT_VALUE_DEFAULT="${defaultvalue}" "${CUSTOMPROMPT}" "${title}" "${msg}" "${yeslabel}" "${nolabel}" "${cancellabel}"; then
return 0
elif [[ "$?" -eq 1 ]]; then
return 1
else
return 2
fi
elif is_true "${NOGUI}" || [[ -z "${DISPLAY:-}" ]]; then
local prompt
if is_true "${defaultvalue}"; then
prompt='[Y/n]: '
else
prompt='[N/y]: '
fi
if read -r -p "${prompt}" resp; then
if [[ -z "${resp//[[:space:]]/}" ]]; then
if is_true "${defaultvalue}"; then
return 0
else
return 1
fi
elif is_true "${resp}"; then
return 0
else
return 1
fi
else
return 2
fi
elif command -v kdialog &>/dev/null; then
if XDG_CONFIG_DIRS="${XDG_CONFIG_DIRS:-/home/deck/.config/kdedefaults:/etc/xdg}" XDG_CURRENT_DESKTOP="${XDG_CURRENT_DESKTOP:-KDE}" QT_QPA_PLATFORMTHEME="${QT_QPA_PLATFORMTHEME:-kde}" kdialog --title "${title}" --yes-label "${yeslabel}" --no-label "${nolabel}" --cancel-label "${cancellabel}" --yesnocancel "${msg}" &>/dev/null; then
return 0
elif [[ "$?" -eq 1 ]]; then
return 1
else
return 2
fi
elif command -v zenity &>/dev/null; then
if resp="$(zenity --title "${title}" --question --ok-label "${yeslabel}" --cancel-label "${nolabel}" --extra-button "${cancellabel}" --no-wrap --text "${msg}" 2>/dev/null)"; then
return 0
elif [[ "${resp}" == "${cancellabel}" ]]; then
return 2
else
return 1
fi
else
NOGUI=1
eprompt "$@"
return "$?"
fi
}
# $1 Title
# $2 Header
# $3... [+]Option
#
# Returns 1 if cancelled
eprompt_list() {
local title="${1:-}"
if [[ -n "${title}" ]]; then
title="SteamOS Btrfs - ${title}"
else
title='SteamOS Btrfs'
fi
local header="${2:-}"
if is_true "${NOGUI}" || [[ -z "${DISPLAY:-}" ]] || is_true "${NONINTERACTIVE}" || [[ ! -t 0 ]]; then
for opt in "${@:3}"; do
if [[ "${opt}" == '+'* ]]; then
echo "${opt#+}"
fi
done
elif command -v kdialog &>/dev/null; then
local list=()
for opt in "${@:3}"; do
if [[ "${opt}" == '+'* ]]; then
list+=("${opt#+}" "${opt#+}" on)
else
list+=("${opt}" "${opt}" off)
fi
done
if XDG_CONFIG_DIRS="${XDG_CONFIG_DIRS:-/home/deck/.config/kdedefaults:/etc/xdg}" XDG_CURRENT_DESKTOP="${XDG_CURRENT_DESKTOP:-KDE}" QT_QPA_PLATFORMTHEME="${QT_QPA_PLATFORMTHEME:-kde}" kdialog --title "${title}" --separate-output --checklist "${header}" "${list[@]}" 2>/dev/null; then
return 0
else
return 2
fi
elif command -v zenity &>/dev/null; then
local list=()
for opt in "${@:3}"; do
if [[ "${opt}" == '+'* ]]; then
list+=(TRUE "${opt#+}")
else
list+=(FALSE "${opt}")
fi
done
if zenity --title "${title}" --list --text="${header}" --column='' --column='' --checklist --separator=$'\n' --multiple --hide-header "${list[@]}" 2>/dev/null; then
return 0
else
return 2
fi
else
NOGUI=1 eprompt_list "$@"
return "$?"
fi
}
eprompt_error() {
local title="${1:-}"
if [[ -n "${title}" ]]; then
title="SteamOS Btrfs - ${title}"
else
title='SteamOS Btrfs'
fi
local msg="${2:-}"
eprint "(${title}) ${msg}"
if is_true "${NOGUI}" || [[ -z "${DISPLAY:-}" ]] || is_true "${NONINTERACTIVE}" || [[ ! -t 0 ]]; then
:
elif command -v kdialog &>/dev/null; then
if XDG_CONFIG_DIRS="${XDG_CONFIG_DIRS:-/home/deck/.config/kdedefaults:/etc/xdg}" XDG_CURRENT_DESKTOP="${XDG_CURRENT_DESKTOP:-KDE}" QT_QPA_PLATFORMTHEME="${QT_QPA_PLATFORMTHEME:-kde}" kdialog --title "${title}" --error "${msg}" &>/dev/null; then
:
fi
elif command -v zenity &>/dev/null; then
if zenity --error --title "${title}" --no-wrap --text "${msg}" &>/dev/null; then
:
fi
else
NOGUI=1 eprompt_error "$@"
fi
}
eprompt_password() {
local title="${1:-}"
if [[ -n "${title}" ]]; then
title="SteamOS Btrfs - ${title}"
else
title='SteamOS Btrfs'
fi
local msg="${2:-}"
eprint "(${title}) ${msg}"
local pass=''
if is_true "${NOGUI}" || [[ -z "${DISPLAY:-}" ]] || is_true "${NONINTERACTIVE}" || [[ ! -t 0 ]]; then
passwd
return 0
elif command -v kdialog &>/dev/null; then
if pass="$(XDG_CONFIG_DIRS="${XDG_CONFIG_DIRS:-/home/deck/.config/kdedefaults:/etc/xdg}" XDG_CURRENT_DESKTOP="${XDG_CURRENT_DESKTOP:-KDE}" QT_QPA_PLATFORMTHEME="${QT_QPA_PLATFORMTHEME:-kde}" kdialog --title "${title}" --newpassword "${msg}" 2>/dev/null)"; then
:
else
return 2
fi
elif command -v zenity &>/dev/null; then
local resp=''
while true; do
if resp="$(zenity --title "${title}" --forms --separator $'\n' --text "${msg}" --add-password Password --add-password 'Confirm Password' 2>/dev/null)"; then
local pass1='' pass2='' i=0
while read -r line; do
if [[ "${i}" -eq 0 ]]; then
pass1="${line}"
elif [[ "${i}" -eq 1 ]]; then
pass2="${line}"
fi
i=$((i + 1))
done < <(echo "${resp}")
if [[ "${pass1}" == "${pass2}" ]]; then
pass="${pass1}"
break
else
eprompt_error 'Password error' 'The passwords do not match'
fi
else
return 2
fi
done
else
NOGUI=1 eprompt_password "$@"
return "$?"
fi
local err=''
if [[ -z "${pass}" ]]; then
eprompt_error 'Password error' 'Empty password'
return 1
elif ! err="$(passwd -q < <(yes "${pass}") 2>&1 >/dev/null)"; then
eprompt_error 'Password error' "${err}"
return 1
fi
}
config_load() {
local v='' \
TMP_NONINTERACTIVE='' \
TMP_NOGUI='' \
TMP_NOAUTOUPDATE='' \
TMP_NOCONVERTHOME='' \
TMP_STEAMOS_BTRFS_HOME_MOUNT_OPTS='' \
TMP_STEAMOS_BTRFS_HOME_MOUNT_SUBVOL='' \
TMP_STEAMOS_BTRFS_ROOTFS_PACMAN_EXTRA_PKGS=''
if [[ -f "${NOAUTOUPDATE_FILE_FLAG}" ]]; then
TMP_NOAUTOUPDATE=1
fi
if [[ -f "${NOCONVERTHOME_FILE_FLAG}" ]]; then
TMP_NOCONVERTHOME=1
fi
for f in "${STEAMOS_BTRFS_INSTALL_PATH}/files/${CONFIGFILE#/}" "${WORKDIR}/files/${CONFIGFILE#/}" "${CONFIGFILE}"; do
if [[ -f "${f}" ]]; then
{
read -r v
TMP_NONINTERACTIVE="${v:-"${TMP_NONINTERACTIVE}"}"
read -r v
TMP_NOGUI="${v:-"${TMP_NOGUI}"}"
read -r v
TMP_NOAUTOUPDATE="${v:-"${TMP_NOAUTOUPDATE}"}"
read -r v
TMP_NOCONVERTHOME="${v:-"${TMP_NOCONVERTHOME}"}"
read -r v
TMP_STEAMOS_BTRFS_HOME_MOUNT_OPTS="${v:-"${TMP_STEAMOS_BTRFS_HOME_MOUNT_OPTS}"}"
read -r v
TMP_STEAMOS_BTRFS_HOME_MOUNT_SUBVOL="${v:-"${TMP_STEAMOS_BTRFS_HOME_MOUNT_SUBVOL}"}"
read -r v
TMP_STEAMOS_BTRFS_ROOTFS_PACMAN_EXTRA_PKGS="${v:-"${TMP_STEAMOS_BTRFS_ROOTFS_PACMAN_EXTRA_PKGS}"}"
} < <(
# shellcheck source=files/etc/default/steamos-btrfs
source "${f}"
echo "${NONINTERACTIVE:-}"
echo "${NOGUI:-}"
echo "${NOAUTOUPDATE:-}"
echo "${NOCONVERTHOME:-}"
echo "${STEAMOS_BTRFS_HOME_MOUNT_OPTS:-}"
echo "${STEAMOS_BTRFS_HOME_MOUNT_SUBVOL:-}"
echo "${STEAMOS_BTRFS_ROOTFS_PACMAN_EXTRA_PKGS:-}"
)
fi
done
NONINTERACTIVE="${NONINTERACTIVE:-"${TMP_NONINTERACTIVE:-"${NONINTERACTIVE_DEFAULT}"}"}"
NOGUI="${NOGUI:-"${TMP_NOGUI:-"${NOGUI_DEFAULT}"}"}"
NOAUTOUPDATE="${NOAUTOUPDATE:-"${TMP_NOAUTOUPDATE:-"${NOAUTOUPDATE_DEFAULT}"}"}"
NOCONVERTHOME="${NOCONVERTHOME:-"${TMP_NOCONVERTHOME:-"${NOCONVERTHOME_DEFAULT}"}"}"
STEAMOS_BTRFS_HOME_MOUNT_OPTS="${STEAMOS_BTRFS_HOME_MOUNT_OPTS:-"${TMP_STEAMOS_BTRFS_HOME_MOUNT_OPTS:-"${STEAMOS_BTRFS_HOME_MOUNT_OPTS_DEFAULT}"}"}"
STEAMOS_BTRFS_HOME_MOUNT_SUBVOL="${STEAMOS_BTRFS_HOME_MOUNT_SUBVOL:-"${TMP_STEAMOS_BTRFS_HOME_MOUNT_SUBVOL:-"${STEAMOS_BTRFS_HOME_MOUNT_SUBVOL_DEFAULT}"}"}"
STEAMOS_BTRFS_ROOTFS_PACMAN_EXTRA_PKGS="${STEAMOS_BTRFS_ROOTFS_PACMAN_EXTRA_PKGS:-"${TMP_STEAMOS_BTRFS_ROOTFS_PACMAN_EXTRA_PKGS:-"${STEAMOS_BTRFS_ROOTFS_PACMAN_EXTRA_PKGS_DEFAULT}"}"}"
PKGS=("${PKGS[@]:0:${PKGS_SIZE}}")
readarray -d' ' -O"${PKGS_SIZE}" -t PKGS < <(echo -n "${STEAMOS_BTRFS_ROOTFS_PACMAN_EXTRA_PKGS}")
}
root_handler() {
if [[ "${EUID}" -eq 0 ]]; then
return
fi
if { is_true "${NONINTERACTIVE}" || [[ ! -t 0 ]]; } && ! sudo -n -v &>/dev/null; then
eprint 'Please run as root.'
return 1
fi
if [[ "$(passwd -S | cut -d' ' -f2)" == 'NP' ]] && ! sudo -n -v &>/dev/null; then
# user needs to set their password
eprompt_password 'Set the password' 'Set a new user password'
fi
local sudo_args=(
NONINTERACTIVE="${NONINTERACTIVE}"
NOGUI="${NOGUI}"
NOAUTOUPDATE="${NOAUTOUPDATE}"
NOCONVERTHOME="${NOCONVERTHOME}"
CUSTOMPROMPT="${CUSTOMPROMPT}"
STEAMOS_BTRFS_HOME_MOUNT_OPTS="${STEAMOS_BTRFS_HOME_MOUNT_OPTS}"
STEAMOS_BTRFS_HOME_MOUNT_SUBVOL="${STEAMOS_BTRFS_HOME_MOUNT_SUBVOL}"
STEAMOS_BTRFS_ROOTFS_PACMAN_EXTRA_PKGS="${STEAMOS_BTRFS_ROOTFS_PACMAN_EXTRA_PKGS}")
# not root, ask for password if needed
if ! is_true "${NOGUI}" && [[ -n "${DISPLAY:-}" ]]; then
sudo_args=(-A "${sudo_args[@]}")
if [[ -z "${SUDO_ASKPASS:-}" ]]; then
for ap in ksshaskpass kdialog ssh-askpass zenity; do
if apc="$(command -v "${ap}")"; then
if [[ "${ap}" == 'kdialog' ]]; then
cat <<'EOF' >/tmp/kdialog-askpass
#!/bin/sh
exec kdialog --title Password --password "$1"
EOF
chmod +x /tmp/kdialog-askpass
apc="/tmp/kdialog-askpass"
elif [[ "${ap}" = "zenity" ]]; then
cat <<'EOF' >/tmp/zenity-askpass
#!/bin/sh
exec zenity --password --title="$1"
EOF
chmod +x /tmp/zenity-askpass
apc="/tmp/zenity-askpass"
fi
export SUDO_ASKPASS="${apc}"
break
fi
done
fi
fi
exec sudo "${sudo_args[@]}" -- "${SCRIPT}" "${SCRIPT_ARGS[@]}"
}
find_partset_rootfs() {
local rootfs_dev="${1:?'Missing rootfs'}"
local vrootfs_dev=''
vrootfs_dev="$(find /dev/disk/by-partsets/{self,other,shared,*} \
-mindepth 1 \
-maxdepth 1 \
-name rootfs \
-exec sh -c '[ "$(realpath "$1")" = "$2" ]' _ '{}' "$(realpath "${rootfs_dev}")" \; \
-print \
-quit)"
if [[ -n "${vrootfs_dev}" ]]; then
echo "${vrootfs_dev}"
elif [[ "$(blkid -o value -s LABEL "${rootfs_dev}")" == 'rootfs' && "$(blkid -o value -s TYPE "${rootfs_dev}")" == 'btrfs' ]]; then
echo "${rootfs_dev}"
fi
}
help() {
echo "SteamOS Btrfs" >&2
if [[ -f "${WORKDIR}/version" ]]; then
echo "Version: $(head -n 1 "${WORKDIR}/version")" >&2
fi
cat <<EOF >&2
Usage: '${SCRIPT}' [OPTION]... [rootfs dev]...
Example: '${SCRIPT}' --nogui /dev/disk/by-partsets/self/rootfs
--help show help
--noninteractive run in noninteractive mode
apply options from config files, env vars or defaults
(env var: 'NONINTERACTIVE')
(default: ${NONINTERACTIVE_DEFAULT})
--nogui run without gui prompts, force text prompts
(env var: 'NOGUI')
(default: ${NOGUI_DEFAULT})
--noautoupdate disable automatic fetching of the latest script version when updating the system, changing channels or on version check
(env var: 'NOAUTOUPDATE')
(file flag: '${NOAUTOUPDATE_FILE_FLAG}')
(default: ${NOAUTOUPDATE_DEFAULT})
--noconverthome disable home conversion
(env var: 'NOCONVERTHOME')
(file flag: '${NOCONVERTHOME_FILE_FLAG}')
(default: ${NOCONVERTHOME_DEFAULT})
--customprompt PATH set path to a custom prompt script or executable
First argument supplied is the title, second argument the message to display, third argument label for yes, fourth argument label for no, fifth argument label for cancel
Env var 'EPROMPT_VALUE_DEFAULT' holds the default value
Should return 0 if OK, 1 if not, 2 if cancelled
(env var: 'CUSTOMPROMPT')
(default: '')
Expert config options:
--STEAMOS_BTRFS_HOME_MOUNT_OPTS OPTS set the /home mount options to use
(env var: 'STEAMOS_BTRFS_HOME_MOUNT_OPTS')
(default: '${STEAMOS_BTRFS_HOME_MOUNT_OPTS_DEFAULT}')
--STEAMOS_BTRFS_HOME_MOUNT_SUBVOL SUBVOL set the /home subvolume name to use
(env var: 'STEAMOS_BTRFS_HOME_MOUNT_SUBVOL')
(default: '${STEAMOS_BTRFS_HOME_MOUNT_SUBVOL_DEFAULT}')
--STEAMOS_BTRFS_ROOTFS_PACMAN_EXTRA_PKGS PKGS set the extra pacman packages to install
(env var: 'STEAMOS_BTRFS_ROOTFS_PACMAN_EXTRA_PKGS')
(default: '${STEAMOS_BTRFS_ROOTFS_PACMAN_EXTRA_PKGS_DEFAULT}')
You can specify multiple 'rootfs dev's or none and it will default to '${ROOTFS_DEVICE}'.
Order of priority from highest to lowest for options is: command line flags, env vars, config files ('${STEAMOS_BTRFS_INSTALL_PATH}/files/${CONFIGFILE#/}', '${WORKDIR}/files/${CONFIGFILE#/}', '${CONFIGFILE}'), flag files ('${NOCONVERTHOME_FILE_FLAG}', '${NOAUTOUPDATE_FILE_FLAG}').
A log file will be created at '${LOGFILE}'.
EOF
}
cmd_handler() {
local i=0
local skip=0
local TMP_ROOTFS_DEVICES=()
for arg in "${SCRIPT_ARGS[@]}"; do
if [[ "${skip}" -eq 1 ]]; then
skip=0
continue
fi
if [[ "${arg}" == '--'* ]]; then
arg="${arg#--}"
if [[ "${arg^^}" == 'HELP' ]]; then
help
exit 0
elif [[ "${arg^^}" == 'NONINTERACTIVE' ]]; then
NONINTERACTIVE=1
elif [[ "${arg^^}" == 'NOGUI' ]]; then
NOGUI=1
elif [[ "${arg^^}" == 'NOAUTOUPDATE' ]]; then
NOAUTOUPDATE=1
elif [[ "${arg^^}" == 'NOCONVERTHOME' ]]; then
NOCONVERTHOME=1
elif [[ "${arg^^}" == 'CUSTOMPROMPT' ]]; then
if [[ "$((i + 1))" -ge "${#SCRIPT_ARGS[@]}" ]]; then
eprint "Missing argument for '${arg^^}'."
return 1
fi
CUSTOMPROMPT="${SCRIPT_ARGS[$((i + 1))]}"
skip=1
elif [[ "${arg^^}" == 'STEAMOS_BTRFS_HOME_MOUNT_OPTS' ]]; then
if [[ "$((i + 1))" -ge "${#SCRIPT_ARGS[@]}" ]]; then
eprint "Missing argument for '${arg^^}'."
return 1
fi
STEAMOS_BTRFS_HOME_MOUNT_OPTS="${SCRIPT_ARGS[$((i + 1))]}"
skip=1
elif [[ "${arg^^}" == 'STEAMOS_BTRFS_HOME_MOUNT_SUBVOL' ]]; then
if [[ "$((i + 1))" -ge "${#SCRIPT_ARGS[@]}" ]]; then
eprint "Missing argument for '${arg^^}'."
return 1
fi
STEAMOS_BTRFS_HOME_MOUNT_SUBVOL="${SCRIPT_ARGS[$((i + 1))]}"
skip=1
elif [[ "${arg^^}" == 'STEAMOS_BTRFS_ROOTFS_PACMAN_EXTRA_PKGS' ]]; then
if [[ "$((i + 1))" -ge "${#SCRIPT_ARGS[@]}" ]]; then
eprint "Missing argument for '${arg^^}'."
return 1
fi
STEAMOS_BTRFS_ROOTFS_PACMAN_EXTRA_PKGS="${SCRIPT_ARGS[$((i + 1))]}"
PKGS=("${PKGS[@]:0:${PKGS_SIZE}}")
readarray -d' ' -O"${PKGS_SIZE}" -t PKGS < <(echo -n "${STEAMOS_BTRFS_ROOTFS_PACMAN_EXTRA_PKGS}")
skip=1
else
eprint "Unknown flag '${arg}'."
help
return 1
fi
else
local rootfs
rootfs="$(find_partset_rootfs "${arg}")"
if [[ -z "${rootfs}" ]]; then
eprint "'${arg}' is not an acceptable rootfs device."
return 1
fi
local found=0
for rd in "${TMP_ROOTFS_DEVICES[@]}"; do
if [[ "${rd}" == "${rootfs}" ]]; then
found=1
break
fi
done
if [[ "${found}" -eq 0 ]]; then
TMP_ROOTFS_DEVICES+=("${rootfs}")
fi
fi
i=$((i + 1))
done
if [[ "${#TMP_ROOTFS_DEVICES[@]}" -gt 0 ]]; then
ROOTFS_DEVICES=("${TMP_ROOTFS_DEVICES[@]}")
fi
}
epatch_comment() {
awk '{\
if ($0 ~ /^[@+-]/) {\
comm = substr(comm, 1, i);\
if (comm ~ /\n\n$/) {\
gsub(/^[[:space:]]+|[[:space:]]+$/, "", comm);\
print comm;\
}\
exit;\
}\
else {\
comm = comm $0 "\n";\
if (comm ~ /\n\n$/)\
i=length(comm);\
}\
}' <"$1"
}
epatch() {
local tpatch="$1"
local patches=()
for p in "${tpatch}".old.*; do
if [[ -f "${p}" ]]; then
patches=("${p}" "${patches[@]}")
fi
done
patches=("${tpatch}" "${patches[@]}")
for p in "${patches[@]}"; do
if patch --dry-run -Rlfsp1 -i "${p}" &>/dev/null; then
cmd patch --no-backup-if-mismatch -Rlfsp1 -i "${p}"
break
fi
done
for p in "${patches[@]}"; do
if patch --dry-run -Nlfsp1 -i "${p}" &>/dev/null; then
tpatch="${p}"
break
fi
done
# try to parse the comment if available
local comment
comment="$(epatch_comment "${tpatch}")"
if [[ -n "${comment}" ]]; then
eprint "${comment}"
fi
if cmd patch --no-backup-if-mismatch -Nlfp1 -i "${tpatch}"; then
return 0
fi
return 1
}
factory_pacman() {
if [[ ! -f etc/pacman.conf.orig ]]; then
cmd cp -a etc/pacman.conf{,.orig}
fi
cmd sed -i -e 's/^SigLevel\s*=.*$/SigLevel = Never/g' -e 's/^LocalFileSigLevel\s*=.*$/LocalFileSigLevel = Never/g' etc/pacman.conf
local pacman_args=(--root .
--config etc/pacman.conf
--cachedir "${PACMAN_CACHE}"
--gpgdir etc/pacman.d/gnupg
--logfile /dev/null
--disable-download-timeout)
local pacman_dbpath
# parse DBPath from the pacman.conf
pacman_dbpath="$(sed -n 's|^DBPath\s*=\s*\(\S*\)|\1|p' etc/pacman.conf)"
if [[ -n "${pacman_dbpath}" ]]; then
# strip the starting / to make the path relative
pacman_dbpath="${pacman_dbpath:1}"
if [[ ! -d "${pacman_dbpath}" ]]; then
cmd mkdir -p "${pacman_dbpath}"
fi
pacman_args+=(--dbpath "${pacman_dbpath}")
# check for the old pacman database factory location
elif [[ -d usr/share/factory/var/lib/pacman ]]; then
pacman_args+=(--dbpath usr/share/factory/var/lib/pacman)
fi
# Set LC_ALL=C to force yes prompt to 'y'
if LC_ALL=C cmd pacman "${pacman_args[@]}" \
"$@" < <(yes 'y'); then
cmd mv -vf etc/pacman.conf{.orig,}
return 0
else
cmd mv -vf etc/pacman.conf{.orig,}
return 1
fi
}
list_rootfs_devices() {
local rootfs_devs=()
readarray -d '' -t rootfs_devs < <(find /dev/disk/by-partsets/{self,other,shared,*} -mindepth 1 -maxdepth 1 -name rootfs -print0)
local i=0
while [[ "${i}" -lt "${#rootfs_devs[@]}" ]]; do
local rfs_dev="${rootfs_devs[${i}]}"
local found=0
for rfs_dev_o in "${rootfs_devs[@]:0:${i}}"; do
if [[ "${rfs_dev_o}" == "${rfs_dev}" ]]; then
found=1
break
fi
done
if [[ "${found}" -eq 1 ]]; then
rootfs_devs=("${rootfs_devs[@]:0:${i}}" "${rootfs_devs[@]:$((i + 1))}")
else
i=$((i + 1))
fi
done
local rootfs_devs_x=()
readarray -t rootfs_devs_x < <(blkid | grep '\b\(PART\)\?LABEL="rootfs\(-[a-zA-Z]\+\)\?"' | cut -d: -f1 | sort)
for rfs_dev_x in "${rootfs_devs_x[@]}"; do
if [[ "$(blkid -o value -s TYPE "${rfs_dev_x}")" != 'btrfs' ]]; then
continue
fi
local found=0
for rfs_dev in "${rootfs_devs[@]}"; do
if [[ "$(realpath "${rfs_dev}")" == "$(realpath "${rfs_dev_x}")" ]]; then
found=1
break
fi
done
if [[ "${found}" -ne 1 ]]; then
rootfs_devs+=("${rfs_dev_x}")
fi
done
(
IFS=$'\n'
echo "${rootfs_devs[*]}"
)
}
# $1 rootfs device
#
# Returns associated var device
determine_var_device() {
local rootfs_dev=''
rootfs_dev="$(realpath "$1")"
local rootfs_devs=()
local var_devs=()
readarray -t rootfs_devs < <(blkid | grep '\b\(PART\)\?LABEL="rootfs\(-[a-zA-Z]\+\)\?"' | cut -d: -f1 | grep '^'"${rootfs_dev%[[:digit:]]*}" | sort -u)
readarray -t var_devs < <(blkid | grep '\b\(PART\)\?LABEL="var\(-[a-zA-Z]\+\)\?"' | cut -d: -f1 | grep '^'"${rootfs_dev%[[:digit:]]*}" | sort -u)
local pos=0
for rfs_d in "${rootfs_devs[@]}"; do
if [[ "${rfs_d}" == "${rootfs_dev}" ]]; then
break
fi
pos=$((pos + 1))
done
local var_dev="${var_devs[${pos}]}"
local vvar_dev=''
vvar_dev="$(find /dev/disk/by-partsets/{self,other,shared,*} -mindepth 1 -maxdepth 1 -name var -exec sh -c '[ "$(realpath "$1")" = "$2" ]' _ '{}' "${var_dev}" \; -print -quit)"
if [[ -n "${vvar_dev}" ]]; then
echo "${vvar_dev}"
else
echo "${var_dev}"
fi
}
# $1 rootfs device
#
# Returns associated home device
determine_home_device() {
local rootfs_dev=''
rootfs_dev="$(realpath "$1")"
local rootfs_devs=()
local home_devs=()
readarray -t rootfs_devs < <(blkid | grep '\b\(PART\)\?LABEL="rootfs\(-[a-zA-Z]\+\)\?"' | cut -d: -f1 | grep '^'"${rootfs_dev%[[:digit:]]*}" | sort -u)
readarray -t home_devs < <(blkid | grep '\b\(PART\)\?LABEL="home\(-[a-zA-Z]\+\)\?"' | cut -d: -f1 | grep '^'"${rootfs_dev%[[:digit:]]*}" | sort -u)
local home_dev="${home_devs[0]}"
local vhome_dev=''
vhome_dev="$(find /dev/disk/by-partsets/{self,other,shared,*} -mindepth 1 -maxdepth 1 -name home -exec sh -c '[ "$(realpath "$1")" = "$2" ]' _ '{}' "${home_dev}" \; -print -quit)"
if [[ -n "${vhome_dev}" ]]; then
echo "${vhome_dev}"
else
echo "${home_dev}"
fi
}
log_truncate() {
local log_bms=()
readarray -t log_bms < <(grep -n '^#\+\s*[-0-9]\+\s\+[0-9:.]\+\s*#\+' "${LOGFILE}" | tail -n 6 | cut -d: -f1)
if [[ "${#log_bms[@]}" -lt 6 ]]; then
return
fi
eprint "Truncating log file: ${LOGFILE}"
tail -n +"${log_bms[0]}" "${LOGFILE}" >"${LOGFILE}.new"
mv -f "${LOGFILE}.new" "${LOGFILE}"
}
log_handler() {
if mkdir -p "$(dirname "${LOGFILE}")" && touch "${LOGFILE}"; then
log_truncate
exec &> >(tee -a "${LOGFILE}")
printf '#### %(%F %T)T ####\n'
if [[ -f "${WORKDIR}/version" ]]; then
eprint "Version: $(head -n 1 "${WORKDIR}/version")"
fi
eprint "Command-line arguments: ${SCRIPT_ARGS[*]@Q}"
eprint 'Env vars:'
eprint "\tNONINTERACTIVE: ${NONINTERACTIVE}"
eprint "\tNOGUI: ${NOGUI}"
eprint "\tNOAUTOUPDATE: ${NOAUTOUPDATE}"
eprint "\tNOCONVERTHOME: ${NOCONVERTHOME}"
eprint "\tSTEAMOS_BTRFS_HOME_MOUNT_OPTS: ${STEAMOS_BTRFS_HOME_MOUNT_OPTS}"
eprint "\tSTEAMOS_BTRFS_HOME_MOUNT_SUBVOL: ${STEAMOS_BTRFS_HOME_MOUNT_SUBVOL}"
eprint "\tSTEAMOS_BTRFS_ROOTFS_PACMAN_EXTRA_PKGS: ${STEAMOS_BTRFS_ROOTFS_PACMAN_EXTRA_PKGS}"
if [[ -f "${CONFIGFILE}" ]]; then
eprint "${CONFIGFILE}:"
cat "${CONFIGFILE}"
fi
if [[ -f '/etc/os-release' ]]; then
eprint '/etc/os-release:'
cat '/etc/os-release'
fi
fi
}
rootfs_device_selection() {
local ALL_ROOTFS_DEVICES=()
readarray -d$'\n' -t ALL_ROOTFS_DEVICES < <(list_rootfs_devices)
if [[ "${#ALL_ROOTFS_DEVICES[@]}" -eq 0 ]]; then
eprompt_error 'No rootfs devices' 'No available rootfs devices.'
return 1
fi
local i=0
for rd in "${ALL_ROOTFS_DEVICES[@]}"; do
for rdo in "${ROOTFS_DEVICES[@]}"; do
if [[ "${rd}" == "${rdo}" ]]; then
ALL_ROOTFS_DEVICES[i]="+${rd}"
break
fi
done
i=$((i + 1))
done
ROOTFS_DEVICES=()
local ret
ret="$(eprompt_list 'Rootfs devices' 'Select the rootfs devices to install into:' "${ALL_ROOTFS_DEVICES[@]}")"
readarray -d$'\n' -t ROOTFS_DEVICES < <(echo -n "${ret}")
if [[ "${#ROOTFS_DEVICES[@]}" -eq 0 ]]; then
eprompt_error 'No rootfs devices' 'No rootfs devices selected.'
return 1
fi
}
ONEXITERR=()
ONEXITRESTORE=()
err() {
echo >&2
eprint 'Installation error occured, see above and restart process.'
eprint 'Cleaning up...'
for func in "${ONEXITERR[@]}"; do
"${func}" || true
done
ONEXITERR=()
for func in "${ONEXITRESTORE[@]}"; do
"${func}" || true
done
ONEXITRESTORE=()
eprompt_error 'Installation error occured' "An installation error occured, check the log at '${LOGFILE}' and report any issues." || true
}
quit() {
local last_status_code="$?"
if [[ "${last_status_code}" -ne 0 ]]; then
err
return
fi
echo >&2
eprint 'Quit signal received.'
eprint 'Cleaning up...'
for func in "${ONEXITERR[@]}"; do
"${func}" || true
done
ONEXITERR=()
for func in "${ONEXITRESTORE[@]}"; do
"${func}" || true
done
ONEXITRESTORE=()
}
update_check_cleanup() {
if [[ -d "${UPDATER_PATH}" ]]; then
cmd rm -rf "${UPDATER_PATH}" || true
fi
}
update_check() {
local version=''
if [[ -f "${WORKDIR}/version" ]]; then
version="$(head -n 1 "${WORKDIR}/version")"
fi
local remote_version
remote_version="$({ curl -sLf "https://gitlab.com/popsulfr/steamos-btrfs/-/raw/${GIT_BRANCH}/version" || true; } | head -n 1)"
if [[ "${version}" != "${remote_version}" ]]; then
local update
if is_true "${NOAUTOUPDATE}"; then
update=0
else
update=1
fi
if EPROMPT_VALUE_DEFAULT="${update}" eprompt 'New update!' "A newer update '${remote_version}' is available" 'Update' 'Continue'; then
ONEXITERR=(update_check_cleanup "${ONEXITERR[@]}")
UPDATER_PATH="$(mktemp -d)"
cmd curl -sSL "https://gitlab.com/popsulfr/steamos-btrfs/-/archive/${GIT_BRANCH}/steamos-btrfs-${GIT_BRANCH}.tar.gz" | cmd tar -xzf - -C "${UPDATER_PATH}" --strip-components=1
exec "${UPDATER_PATH}/install.sh" "${SCRIPT_ARGS[@]}"
elif [[ "$?" -eq 1 ]]; then
return 0
else
return 1
fi
fi
}
rootfs_install_packages_cleanup() {
if [[ -d "${VAR_MOUNTPOINT}" ]]; then
if mountpoint -q "${VAR_MOUNTPOINT}"; then
cmd umount -l "${VAR_MOUNTPOINT}" || true
fi
cmd rmdir "${VAR_MOUNTPOINT}" || true
fi
if [[ -d "${PACMAN_CACHE}" ]]; then
cmd rm -rf "${PACMAN_CACHE}" || true
fi
}
pacman_repos_check_and_fix() {
local repos=()
readarray -t repos < <(sed -n 's/^\[\([^]]\+\)\]/\1/p' etc/pacman.conf | grep -v '^options$')
for r in "${repos[@]}"; do
local ret_code='200'
ret_code="$(curl -sSLIo /dev/null -w '%{http_code}' "https://steamdeck-packages.steamos.cloud/archlinux-mirror/${r}/os/x86_64/${r}.db")"
if [[ "${ret_code}" != '200' ]]; then
local nr
nr="${r%-main}"
nr="${nr%-beta}"
nr="${nr%-rel}"
nr="${nr%-3.3}"
nr="${nr%-3.3.3}"
local trepos=()
if [[ "${r}" == *-beta ]]; then
trepos=("${nr}-rel" "${nr}-main")
else
trepos=("${nr}" "${nr}-3.3.3" "${nr}-3.3")
fi
for r2 in "${trepos[@]}"; do
if [[ "${r}" == "${r2}" ]]; then
continue
fi
ret_code="$(curl -sSLIo /dev/null -w '%{http_code}' "https://steamdeck-packages.steamos.cloud/archlinux-mirror/${r2}/os/x86_64/${r2}.db")"
if [[ "${ret_code}" == '200' ]]; then
eprint "Replace non-existing '${r}' repo with '${r2}' in /etc/pacman.conf"
cmd sed -i 's/^\['"${r}"'\]/['"${r2}"']/' etc/pacman.conf
break
fi
done
fi
done
}
rootfs_install_packages() {
ONEXITERR=(rootfs_install_packages_cleanup "${ONEXITERR[@]}")
eprint "Install the needed arch packages: ${PKGS[*]}"
pacman_repos_check_and_fix
PACMAN_CACHE="$(mktemp -d)"
factory_pacman --cachedir "${PACMAN_CACHE}" -Sy --needed --overwrite='*' "${PKGS[@]}"
# install rmlint version that is at least 2.10.2
if ! sort -C -V < <(echo '2.10.2-1' ;
factory_pacman -Qiq rmlint | sed -n 's/^Version\s*:\s*\(\S\+\)\s*$/\1/p'); then
eprint "Force install rmlint-2.10.2-1"
factory_pacman --cachedir "${PACMAN_CACHE}" -U "${WORKDIR}/data/rmlint-2.10.2-1-x86_64.pkg.tar.zst"
fi
# install duperemove version that is at least 0.14.1
if ! sort -C -V < <(echo '0.14.1-1' ;
factory_pacman -Qiq duperemove | sed -n 's/^Version\s*:\s*\(\S\+\)\s*$/\1/p'); then
eprint "Force install duperemove-0.14.1-1"
factory_pacman --cachedir "${PACMAN_CACHE}" -U "${WORKDIR}/data/duperemove-0.14.1-1-x86_64.pkg.tar.zst"
fi
# patch the /usr/lib/manifest.pacman with the new packages
if [[ -f usr/lib/manifest.pacman ]]; then
eprint 'Patch the /usr/lib/manifest.pacman with the new packages'
cmd cp -a usr/lib/manifest.pacman{,.orig}
head -n 1 usr/lib/manifest.pacman | wc -c | xargs -I'{}' truncate -s '{}' usr/lib/manifest.pacman
factory_pacman -Qiq |
sed -n 's/^\(Name\|Version\)\s*:\s*\(\S\+\)\s*$/\2/p' |
xargs -d'\n' -n 2 printf '%s %s\n' >>usr/lib/manifest.pacman
fi
cmd rm -rf "${PACMAN_CACHE}"
# synchronize the /var partition with the new pacman state if needed
eprint 'Synchronize the /var partition with the new pacman state if needed'
VAR_MOUNTPOINT="$(mktemp -d)"
cmd mount "${VAR_DEVICE}" "${VAR_MOUNTPOINT}"
if [[ -d "${VAR_MOUNTPOINT}"/lib/pacman ]]; then
# parse DBPath from the pacman.conf
local pacman_dbpath
pacman_dbpath="$(sed -n 's|^DBPath\s*=\s*\(\S*\)|\1|p' etc/pacman.conf)"
if [[ -n "${pacman_dbpath}" ]]; then
# strip the starting / to make the path relative
pacman_dbpath="${pacman_dbpath:1}"
if [[ -d "${pacman_dbpath}" ]]; then
cmd rsync -a --inplace --delete "${pacman_dbpath}/" "${VAR_MOUNTPOINT}"/lib/pacman/
fi
# check for the old pacman database factory location
elif [[ -d usr/share/factory/var/lib/pacman ]]; then
cmd rsync -a --inplace --delete usr/share/factory/var/lib/pacman/ "${VAR_MOUNTPOINT}"/lib/pacman/
fi
fi
cmd umount -l "${VAR_MOUNTPOINT}"
cmd rmdir "${VAR_MOUNTPOINT}" || true
ONEXITERR=("${ONEXITERR[@]:1}")
}
rootfs_fstab_patch_cleanup() {
if [[ -d "${VAR_MOUNTPOINT}" ]]; then
if [[ "$(blkid -o value -s TYPE "${HOME_DEVICE}")" != 'btrfs' ]]; then
cmd mv -vf "${VAR_MOUNTPOINT}/lib/overlays/etc/upper/fstab"{.orig,} || true
fi
if mountpoint -q "${VAR_MOUNTPOINT}"; then
cmd umount -l "${VAR_MOUNTPOINT}" || true
fi
cmd rmdir "${VAR_MOUNTPOINT}" || true
fi
if [[ "$(blkid -o value -s TYPE "${HOME_DEVICE}")" != 'btrfs' ]]; then
cmd mv -vf etc/fstab{.orig,} || true
fi
}
rootfs_fstab_patch_restore() {
VAR_MOUNTPOINT="$(mktemp -d)" || true
cmd mount "${VAR_DEVICE}" "${VAR_MOUNTPOINT}" || true
rootfs_fstab_patch_cleanup
}
rootfs_fstab_patch() {
if { is_true "${NOCONVERTHOME}" && [[ "$(blkid -o value -s TYPE "${HOME_DEVICE}")" != 'btrfs' ]] ;} || [[ ! -f 'etc/fstab' ]]; then
return
fi
ONEXITERR=(rootfs_fstab_patch_cleanup "${ONEXITERR[@]}")
# patch /etc/fstab to use temporary tmpfs /home
if [[ ! -f 'etc/fstab.orig' ]]; then
eprint "Backing up '/etc/fstab' to '/etc/fstab.orig'"
cmd cp -a etc/fstab{,.orig}
fi
fstab_files=(etc/fstab)
# if the user modified the fstab we will need to patch the one on the var partition too
VAR_MOUNTPOINT="$(mktemp -d)"
cmd mount "${VAR_DEVICE}" "${VAR_MOUNTPOINT}"
if [[ -f "${VAR_MOUNTPOINT}/lib/overlays/etc/upper/fstab" ]]; then
fstab_files+=("${VAR_MOUNTPOINT}/lib/overlays/etc/upper/fstab")
if [[ ! -f "${VAR_MOUNTPOINT}/lib/overlays/etc/upper/fstab.orig" ]]; then
eprint "Backing up '${VAR_MOUNTPOINT}/lib/overlays/etc/upper/fstab' to '${VAR_MOUNTPOINT}/lib/overlays/etc/upper/fstab.orig'"
cmd cp -a "${VAR_MOUNTPOINT}/lib/overlays/etc/upper/fstab"{,.orig}
fi
fi
if [[ "$(blkid -o value -s TYPE "${HOME_DEVICE}")" != 'ext4' ]]; then
eprint "Patch /etc/fstab to use btrfs for ${HOME_MOUNTPOINT}"
cmd sed -i 's#^\S\+\s\+'"${HOME_MOUNTPOINT}"'\s\+\S\+\s\+.*$#'"${HOME_DEVICE_STATIC}"' '"${HOME_MOUNTPOINT}"' btrfs '"${STEAMOS_BTRFS_HOME_MOUNT_OPTS}"',subvol='"${STEAMOS_BTRFS_HOME_MOUNT_SUBVOL}"' 0 0#' "${fstab_files[@]}"
else
eprint "Patch /etc/fstab to use temporary ${HOME_MOUNTPOINT} in tmpfs"