]> glassweightruler.freedombox.rocks Git - Ventoy.git/blob - IMG/cpio/ventoy/hook/ventoy-os-lib.sh
added Spanish (Latinoamérica) translation (#1865)
[Ventoy.git] / IMG / cpio / ventoy / hook / ventoy-os-lib.sh
1 #!/ventoy/busybox/sh
2 #************************************************************************************
3 # Copyright (c) 2020, longpanda <admin@ventoy.net>
4 #
5 # This program is free software; you can redistribute it and/or
6 # modify it under the terms of the GNU General Public License as
7 # published by the Free Software Foundation; either version 3 of the
8 # License, or (at your option) any later version.
9 #
10 # This program is distributed in the hope that it will be useful, but
11 # WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 # General Public License for more details.
14 #
15 # You should have received a copy of the GNU General Public License
16 # along with this program; if not, see <http://www.gnu.org/licenses/>.
17 #
18 #************************************************************************************
19
20 VT_RULE_DIR_PREFIX=""
21 VT_PRINTK_LEVEL=0
22 VT_UDEV_RULE_FILE_NAME="99-ventoy.rules"
23 VT_UDEV_RULE_PREFIX="ACTION==\"add\", SUBSYSTEM==\"block\","
24
25 ventoy_close_printk() {
26 VT_PRINTK_LEVEL=$($CAT /proc/sys/kernel/printk | $AWK '{print $1}')
27 if [ -e /proc/sys/kernel/printk ]; then
28 echo 0 > /proc/sys/kernel/printk
29 fi
30 }
31
32 ventoy_restore_printk() {
33 if [ -e /proc/sys/kernel/printk ]; then
34 echo $VT_PRINTK_LEVEL > /proc/sys/kernel/printk
35 fi
36 }
37
38 ventoy_set_rule_dir_prefix() {
39 VT_RULE_DIR_PREFIX=$1
40 }
41
42 ventoy_get_udev_conf_dir() {
43 if [ -d $VT_RULE_DIR_PREFIX/etc/udev/rules.d ]; then
44 VT_RULE_PATH=$VT_RULE_DIR_PREFIX/etc/udev/rules.d
45 elif [ -d $VT_RULE_DIR_PREFIX/lib/udev/rules.d ]; then
46 VT_RULE_PATH=$VT_RULE_DIR_PREFIX/lib/udev/rules.d
47 else
48 $BUSYBOX_PATH/mkdir -p $VT_RULE_DIR_PREFIX/etc/udev/rules.d
49 VT_RULE_PATH=$VT_RULE_DIR_PREFIX/etc/udev/rules.d
50 fi
51 echo -n "$VT_RULE_PATH"
52 }
53
54 ventoy_get_udev_conf_path() {
55 VT_RULE_DIR=$(ventoy_get_udev_conf_dir)
56 echo "$VT_RULE_DIR/$VT_UDEV_RULE_FILE_NAME"
57 }
58
59 ventoy_add_kernel_udev_rule() {
60 VT_UDEV_RULE_PATH=$(ventoy_get_udev_conf_path)
61 echo "KERNEL==\"$1\", $VT_UDEV_RULE_PREFIX RUN+=\"$2\"" >> $VT_UDEV_RULE_PATH
62 }
63
64 ventoy_add_udev_rule_with_name() {
65 VT_UDEV_RULE_DIR=$(ventoy_get_udev_conf_dir)
66 echo "KERNEL==\"*2\", $VT_UDEV_RULE_PREFIX RUN+=\"$1\"" >> $VT_UDEV_RULE_DIR/$2
67 }
68
69 ventoy_add_udev_rule_with_path() {
70 echo "KERNEL==\"*2\", $VT_UDEV_RULE_PREFIX RUN+=\"$1\"" >> $2
71 }
72
73 ventoy_add_udev_rule() {
74 VT_UDEV_RULE_PATH=$(ventoy_get_udev_conf_path)
75 echo "KERNEL==\"*2\", $VT_UDEV_RULE_PREFIX RUN+=\"$1\"" >> $VT_UDEV_RULE_PATH
76 }
77
78 #
79 # It seems there is a bug in somw version of systemd-udevd
80 # https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=869719
81 #
82 ventoy_systemd_udevd_work_around() {
83 for vtdir in 'lib' 'usr/lib'; do
84
85 VTSYSTEMUDEV="$VT_RULE_DIR_PREFIX/$vtdir/systemd/system/systemd-udevd.service"
86 if [ -e $VTSYSTEMUDEV ]; then
87 if $GREP -q 'SystemCallArchitectures.*native' $VTSYSTEMUDEV; then
88 $SED "s/.*\(SystemCallArchitectures.*native\)/#\1/g" -i $VTSYSTEMUDEV
89 break
90 fi
91 fi
92 done
93 }
94
95
96 ventoy_print_yum_repo() {
97 echo "[$1]"
98 echo "name=$1"
99 echo "baseurl=$2"
100 echo "enabled=1"
101 echo "gpgcheck=0"
102 echo "priority=0"
103 }
104
105 ventoy_set_inotify_script() {
106 echo $VTOY_PATH/hook/$1 > $VTOY_PATH/inotifyd-hook-script.txt
107 }
108
109 ventoy_set_loop_inotify_script() {
110 echo $VTOY_PATH/loop/$1 > $VTOY_PATH/inotifyd-loop-script.txt
111 }
112
113 ventoy_check_insmod() {
114 if [ -e $1 ]; then
115 $BUSYBOX_PATH/insmod $1
116 fi
117 }
118
119 ventoy_check_mount() {
120 if [ -e $1 ]; then
121 $BUSYBOX_PATH/mount $1 $2
122 fi
123 }