ventoy-hook.sh 6.38 KB
Newer Older
longpanda's avatar
longpanda committed
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
#!/ventoy/busybox/sh
#************************************************************************************
# Copyright (c) 2020, longpanda <admin@ventoy.net>
# 
# 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 3 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, see <http://www.gnu.org/licenses/>.
# 
#************************************************************************************

. $VTOY_PATH/hook/ventoy-os-lib.sh

longpanda's avatar
longpanda committed
22
23
#ventoy_systemd_udevd_work_around
#ventoy_add_udev_rule "$VTOY_PATH/hook/default/udev_disk_hook.sh %k noreplace"
longpanda's avatar
longpanda committed
24

longpanda's avatar
longpanda committed
25
26
if [ -f $VTOY_PATH/autoinstall ]; then
    VTKS="inst.ks=file:$VTOY_PATH/autoinstall"
27
    cp -a $VTOY_PATH/hook/rhel7/ventoy-autoexp.sh /lib/dracut/hooks/pre-mount/99-ventoy-autoexp.sh
longpanda's avatar
longpanda committed
28
29
else
    for vtParam in $($CAT /proc/cmdline); do
30
31
32
33
        if echo $vtParam | $GREP -q 'ks=file:/'; then
            continue
        fi
    
longpanda's avatar
longpanda committed
34
        if echo $vtParam | $GREP -q 'inst.ks=hd:LABEL='; then
35
            vtRawKsFull="$vtParam"
longpanda's avatar
longpanda committed
36
            vtRawKs=$(echo $vtParam | $AWK -F: '{print $NF}')
longpanda's avatar
longpanda committed
37
            VTKS="inst.ks=hd:/dev/ventoy:$vtRawKs"
longpanda's avatar
longpanda committed
38
39
            break
        fi
longpanda's avatar
longpanda committed
40
41
        
        if echo $vtParam | $GREP -q '^ks=.*:/'; then
42
            vtRawKsFull="$vtParam"
longpanda's avatar
longpanda committed
43
            vtRawKs=$(echo $vtParam | $AWK -F: '{print $NF}')
longpanda's avatar
longpanda committed
44
            VTKS="ks=hd:/dev/ventoy:$vtRawKs"
longpanda's avatar
longpanda committed
45
46
            break
        fi
47
48
        
        if echo $vtParam | $GREP -q '^inst.ks=.*:/'; then
49
            vtRawKsFull="$vtParam"
50
            vtRawKs=$(echo $vtParam | $AWK -F: '{print $NF}')
longpanda's avatar
longpanda committed
51
            VTKS="inst.ks=hd:/dev/ventoy:$vtRawKs"
52
53
            break
        fi
longpanda's avatar
longpanda committed
54
    done
longpanda's avatar
longpanda committed
55
56
fi

57
58
59
60
61
if [ -f $VTOY_PATH/ventoy_persistent_map ]; then
    VTOVERLAY="rd.live.overlay=/dev/dm-1:/vtoyoverlayfs/overlayfs"
    
    if [ -e /sbin/dmsquash-live-root ]; then
        echo "patch /sbin/dmsquash-live-root for persistent ..." >> $VTLOG
longpanda's avatar
longpanda committed
62
63
        $SED "/mount.*devspec.*\/run\/initramfs\/overlayfs/a . /ventoy/hook/rhel7/ventoy-overlay.sh" -i /sbin/dmsquash-live-root        
        $SED "s/osmin.img/osmin.imgxxxx/g" -i /sbin/dmsquash-live-root
64
65
66
67
68
69
70
71
72
73
74
75
    fi
    
    #close selinux
    $BUSYBOX_PATH/mkdir -p $VTOY_PATH/selinuxfs
    if $BUSYBOX_PATH/mount -t selinuxfs selinuxfs $VTOY_PATH/selinuxfs; then
        echo 1 > $VTOY_PATH/selinuxfs/disable
        $BUSYBOX_PATH/umount $VTOY_PATH/selinuxfs
    fi    
    $BUSYBOX_PATH/rm -rf $VTOY_PATH/selinuxfs
fi

echo "VTKS=$VTKS  VTOVERLAY=$VTOVERLAY" >> $VTLOG
longpanda's avatar
longpanda committed
76

longpanda's avatar
longpanda committed
77
if [ -n "$vtRawKs" ]; then
78
79
80
81
82
83
84
    if echo $vtRawKsFull | $EGREP -q "=http|=https|=ftp|=nfs|=hmc"; then
        echo "vtRawKsFull=$vtRawKsFull no patch needed." >> $VTLOG
        vtRawKs=""
        VTKS=""
    else
        echo "$vtRawKs" > $VTOY_PATH/ventoy_ks_rootpath
    fi    
longpanda's avatar
longpanda committed
85
86
fi

longpanda's avatar
longpanda committed
87
88
89
90
91
92
93
if ls $VTOY_PATH | $GREP -q 'ventoy_dud[0-9]'; then
    for vtDud in $(ls $VTOY_PATH/ventoy_dud*); do
        vtInstDD="$vtInstDD inst.dd=file:$vtDud"
    done
fi
echo "vtInstDD=$vtInstDD" >> $VTLOG

longpanda's avatar
longpanda committed
94

longpanda's avatar
longpanda committed
95

96
97
vtNeedRepo=
if [ -f /etc/system-release ]; then
longpanda's avatar
longpanda committed
98
    if $GREP -q 'RED OS' /etc/system-release; then
99
100
101
        vtNeedRepo="yes"
    fi
fi
longpanda's avatar
longpanda committed
102
103

if $GREP -q 'el[89]' /proc/version; then
104
105
106
    vtNeedRepo="yes"
fi

107
108
109
110
111
112
if $GREP -i -q Fedora /proc/version; then
    if $GREP -q 'Server Edition' /etc/os-release; then
        vtNeedRepo="yes"
    fi
fi

113
114
115
116
117
118
if $GREP -i -q Fedora /etc/os-release; then
    if $GREP -q 'Server Edition' /etc/os-release; then
        vtNeedRepo="yes"
    fi
fi

longpanda's avatar
longpanda committed
119
120
echo "vtNeedRepo=$vtNeedRepo" >> $VTLOG

121
122
123
124
if [ "$vtNeedRepo" = "yes" ]; then
    $BUSYBOX_PATH/cp -a $VTOY_PATH/hook/rhel7/ventoy-repo.sh /lib/dracut/hooks/pre-pivot/99-ventoy-repo.sh
fi

125
126
127

#iso-scan (currently only for Fedora)
if $GREP -q Fedora /etc/os-release; then
128
if /ventoy/tool/vtoydump -a /ventoy/ventoy_os_param; then
129
130
131
132
133
134
135
136
137
138
139
140
141
142
    if ventoy_iso_scan_check; then
        echo "iso_scan process ..." >> $VTLOG
        
        vtIsoPath=$(/ventoy/tool/vtoydump -p /ventoy/ventoy_os_param)
        VTISO_SCAN="iso-scan/filename=$vtIsoPath"    
        echo -n $vtIsoPath > /ventoy/vtoy_iso_scan

        $SED "s#printf\(.*\)\$CMDLINE#printf\1\$CMDLINE $VTISO_SCAN $VTKS $VTOVERLAY $vtInstDD#" -i /lib/dracut-lib.sh    
        if [ "$VTOY_LINUX_REMOUNT" = "01" -a "$vtNeedRepo" != "yes" ]; then
            ventoy_rw_iso_scan
        fi

        exit 0
    fi
143
fi    
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
fi


echo "common process ..." >> $VTLOG
if $GREP -q 'root=live' /proc/cmdline; then
    $SED "s#printf\(.*\)\$CMDLINE#printf\1\$CMDLINE root=live:/dev/ventoy $VTKS $VTOVERLAY $VTISO_SCAN $vtInstDD#" -i /lib/dracut-lib.sh
else
    $SED "s#printf\(.*\)\$CMDLINE#printf\1\$CMDLINE inst.stage2=hd:/dev/ventoy $VTKS $VTOVERLAY $VTISO_SCAN $vtInstDD#" -i /lib/dracut-lib.sh
fi


ventoy_set_inotify_script  rhel7/ventoy-inotifyd-hook.sh

#Fedora
if $BUSYBOX_PATH/which dmsquash-live-root > /dev/null; then
    vtPriority=99
else
    vtPriority=01
fi

$BUSYBOX_PATH/cp -a $VTOY_PATH/hook/rhel7/ventoy-inotifyd-start.sh /lib/dracut/hooks/pre-udev/${vtPriority}-ventoy-inotifyd-start.sh
$BUSYBOX_PATH/cp -a $VTOY_PATH/hook/rhel7/ventoy-timeout.sh /lib/dracut/hooks/initqueue/timeout/${vtPriority}-ventoy-timeout.sh


longpanda's avatar
longpanda committed
168
169
170
171
172
if [ -e /sbin/dmsquash-live-root ]; then
    echo "patch /sbin/dmsquash-live-root ..." >> $VTLOG
    $SED "1 a $BUSYBOX_PATH/sh $VTOY_PATH/hook/rhel7/ventoy-make-link.sh" -i /sbin/dmsquash-live-root
fi

longpanda's avatar
longpanda committed
173
174
175
176
# suppress write protected mount warning
if [ -e /usr/sbin/anaconda-diskroot ]; then
    $SED  's/^mount $dev $repodir/mount -oro $dev $repodir/' -i /usr/sbin/anaconda-diskroot
fi
longpanda's avatar
longpanda committed
177

longpanda's avatar
longpanda committed
178
179
180
181
182
183
#For Fedora CoreOS
if $GREP -i -q 'fedora.*coreos' /etc/os-release; then
    $SED "s#isosrc=.*#isosrc=/dev/mapper/ventoy#" -i /lib/systemd/system-generators/live-generator
    cp -a $VTOY_PATH/hook/rhel7/ventoy-make-link.sh /lib/dracut/hooks/pre-mount/99-ventoy-premount-mklink.sh
fi

longpanda's avatar
longpanda committed
184
185
186
187
188
189
190
191

#special distro magic
$BUSYBOX_PATH/mkdir -p $VTOY_PATH/distmagic
if $GREP -q SCRE /proc/cmdline; then
    echo 1 > $VTOY_PATH/distmagic/SCRE
fi

if $GREP -qw 'SA[.]1' /proc/cmdline; then
192
if $GREP -qw 'writable.fsimg' /proc/cmdline; then
longpanda's avatar
longpanda committed
193
194
195
196
197
198
if $GREP -qw 'rw'     /proc/cmdline; then
    echo 1 > $VTOY_PATH/distmagic/DELL_PER
fi
fi
fi