Edit File by line
/home/barbar84/www/wp-conte.../plugins/sujqvwi/ShExBy/shex_roo.../lib/dracut/modules..../30conver...
File: convertfs.sh
#!/bin/bash
[0] Fix | Delete
[1] Fix | Delete
ROOT="$1"
[2] Fix | Delete
[3] Fix | Delete
if [[ ! -d "$ROOT" ]]; then
[4] Fix | Delete
echo "Usage: $0 <rootdir>"
[5] Fix | Delete
exit 1
[6] Fix | Delete
fi
[7] Fix | Delete
[8] Fix | Delete
if [[ "$ROOT" -ef / ]]; then
[9] Fix | Delete
echo "Can't convert the running system."
[10] Fix | Delete
echo "Please boot with 'rd.convertfs' on the kernel command line,"
[11] Fix | Delete
echo "to update with the help of the initramfs,"
[12] Fix | Delete
echo "or run this script from a rescue system."
[13] Fix | Delete
exit 1
[14] Fix | Delete
fi
[15] Fix | Delete
[16] Fix | Delete
while [[ "$ROOT" != "${ROOT%/}" ]]; do
[17] Fix | Delete
ROOT=${ROOT%/}
[18] Fix | Delete
done
[19] Fix | Delete
[20] Fix | Delete
if [ ! -L $ROOT/var/run -a -e $ROOT/var/run ]; then
[21] Fix | Delete
echo "Converting /var/run to symlink"
[22] Fix | Delete
mv -f $ROOT/var/run $ROOT/var/run.runmove~
[23] Fix | Delete
ln -sfn ../run $ROOT/var/run
[24] Fix | Delete
fi
[25] Fix | Delete
[26] Fix | Delete
if [ ! -L $ROOT/var/lock -a -e $ROOT/var/lock ]; then
[27] Fix | Delete
echo "Converting /var/lock to symlink"
[28] Fix | Delete
mv -f $ROOT/var/lock $ROOT/var/lock.lockmove~
[29] Fix | Delete
ln -sfn ../run/lock $ROOT/var/lock
[30] Fix | Delete
fi
[31] Fix | Delete
[32] Fix | Delete
needconvert() {
[33] Fix | Delete
for dir in "$ROOT/bin" "$ROOT/sbin" "$ROOT/lib" "$ROOT/lib64"; do
[34] Fix | Delete
if [[ -e "$dir" ]]; then
[35] Fix | Delete
[[ -L "$dir" ]] || return 0
[36] Fix | Delete
fi
[37] Fix | Delete
done
[38] Fix | Delete
return 1
[39] Fix | Delete
}
[40] Fix | Delete
[41] Fix | Delete
if ! [ -e "$ROOT/usr/bin" ]; then
[42] Fix | Delete
echo "$ROOT/usr/bin does not exist!"
[43] Fix | Delete
echo "Make sure, the kernel command line has enough information"
[44] Fix | Delete
echo "to mount /usr (man dracut.cmdline)"
[45] Fix | Delete
exit 1
[46] Fix | Delete
fi
[47] Fix | Delete
[48] Fix | Delete
[49] Fix | Delete
if ! needconvert; then
[50] Fix | Delete
echo "Your system is already converted."
[51] Fix | Delete
exit 0
[52] Fix | Delete
fi
[53] Fix | Delete
[54] Fix | Delete
testfile="$ROOT/.usrmovecheck$$"
[55] Fix | Delete
rm -f -- "$testfile"
[56] Fix | Delete
> "$testfile"
[57] Fix | Delete
if [[ ! -e "$testfile" ]]; then
[58] Fix | Delete
echo "Cannot write to $ROOT/"
[59] Fix | Delete
exit 1
[60] Fix | Delete
fi
[61] Fix | Delete
rm -f -- "$testfile"
[62] Fix | Delete
[63] Fix | Delete
testfile="$ROOT/usr/.usrmovecheck$$"
[64] Fix | Delete
rm -f -- "$testfile"
[65] Fix | Delete
> "$testfile"
[66] Fix | Delete
if [[ ! -e "$testfile" ]]; then
[67] Fix | Delete
echo "Cannot write to $ROOT/usr/"
[68] Fix | Delete
exit 1
[69] Fix | Delete
fi
[70] Fix | Delete
rm -f -- "$testfile"
[71] Fix | Delete
[72] Fix | Delete
find_mount() {
[73] Fix | Delete
local dev mnt etc wanted_dev
[74] Fix | Delete
wanted_dev="$(readlink -e -q $1)"
[75] Fix | Delete
while read dev mnt etc || [ -n "$dev" ]; do
[76] Fix | Delete
[ "$dev" = "$wanted_dev" ] && echo "$dev" && return 0
[77] Fix | Delete
done < /proc/mounts
[78] Fix | Delete
return 1
[79] Fix | Delete
}
[80] Fix | Delete
[81] Fix | Delete
# usage: ismounted <mountpoint>
[82] Fix | Delete
# usage: ismounted /dev/<device>
[83] Fix | Delete
if command -v findmnt >/dev/null; then
[84] Fix | Delete
ismounted() {
[85] Fix | Delete
findmnt "$1" > /dev/null 2>&1
[86] Fix | Delete
}
[87] Fix | Delete
else
[88] Fix | Delete
ismounted() {
[89] Fix | Delete
if [ -b "$1" ]; then
[90] Fix | Delete
find_mount "$1" > /dev/null && return 0
[91] Fix | Delete
return 1
[92] Fix | Delete
fi
[93] Fix | Delete
[94] Fix | Delete
while read a m a || [ -n "$m" ]; do
[95] Fix | Delete
[ "$m" = "$1" ] && return 0
[96] Fix | Delete
done < /proc/mounts
[97] Fix | Delete
return 1
[98] Fix | Delete
}
[99] Fix | Delete
fi
[100] Fix | Delete
[101] Fix | Delete
# clean up after ourselves no matter how we die.
[102] Fix | Delete
cleanup() {
[103] Fix | Delete
echo "Something failed. Move back to the original state"
[104] Fix | Delete
for dir in "$ROOT/bin" "$ROOT/sbin" "$ROOT/lib" "$ROOT/lib64" \
[105] Fix | Delete
"$ROOT/usr/bin" "$ROOT/usr/sbin" "$ROOT/usr/lib" \
[106] Fix | Delete
"$ROOT/usr/lib64"; do
[107] Fix | Delete
[[ -d "${dir}.usrmove-new" ]] && rm -fr -- "${dir}.usrmove-new"
[108] Fix | Delete
if [[ -d "${dir}.usrmove-old" ]]; then
[109] Fix | Delete
mv "$dir" "${dir}.del~"
[110] Fix | Delete
mv "${dir}.usrmove-old" "$dir"
[111] Fix | Delete
rm -fr -- "${dir}.del~"
[112] Fix | Delete
fi
[113] Fix | Delete
done
[114] Fix | Delete
}
[115] Fix | Delete
[116] Fix | Delete
trap 'ret=$?; [[ $ret -ne 0 ]] && cleanup;exit $ret;' EXIT
[117] Fix | Delete
trap 'exit 1;' SIGINT
[118] Fix | Delete
[119] Fix | Delete
ismounted "$ROOT/usr" || CP_HARDLINK="-l"
[120] Fix | Delete
[121] Fix | Delete
set -e
[122] Fix | Delete
[123] Fix | Delete
# merge / and /usr in new dir in /usr
[124] Fix | Delete
for dir in bin sbin lib lib64; do
[125] Fix | Delete
rm -rf -- "$ROOT/usr/${dir}.usrmove-new"
[126] Fix | Delete
[[ -L "$ROOT/$dir" ]] && continue
[127] Fix | Delete
[[ -d "$ROOT/$dir" ]] || continue
[128] Fix | Delete
echo "Make a copy of \`$ROOT/usr/$dir'."
[129] Fix | Delete
[[ -d "$ROOT/usr/$dir" ]] \
[130] Fix | Delete
&& cp -ax -l "$ROOT/usr/$dir" "$ROOT/usr/${dir}.usrmove-new"
[131] Fix | Delete
echo "Merge the copy with \`$ROOT/$dir'."
[132] Fix | Delete
[[ -d "$ROOT/usr/${dir}.usrmove-new" ]] \
[133] Fix | Delete
|| mkdir -p "$ROOT/usr/${dir}.usrmove-new"
[134] Fix | Delete
cp -axT $CP_HARDLINK --backup --suffix=.usrmove~ "$ROOT/$dir" "$ROOT/usr/${dir}.usrmove-new"
[135] Fix | Delete
echo "Clean up duplicates in \`$ROOT/usr/$dir'."
[136] Fix | Delete
# delete all symlinks that have been backed up
[137] Fix | Delete
find "$ROOT/usr/${dir}.usrmove-new" -type l -name '*.usrmove~' -delete || :
[138] Fix | Delete
# replace symlink with backed up binary
[139] Fix | Delete
find "$ROOT/usr/${dir}.usrmove-new" \
[140] Fix | Delete
-name '*.usrmove~' \
[141] Fix | Delete
-type f \
[142] Fix | Delete
-exec bash -c 'p="{}";o=${p%%%%.usrmove~};
[143] Fix | Delete
[[ -L "$o" ]] && mv -f "$p" "$o"' ';' || :
[144] Fix | Delete
done
[145] Fix | Delete
# switch over merged dirs in /usr
[146] Fix | Delete
for dir in bin sbin lib lib64; do
[147] Fix | Delete
[[ -d "$ROOT/usr/${dir}.usrmove-new" ]] || continue
[148] Fix | Delete
echo "Switch to new \`$ROOT/usr/$dir'."
[149] Fix | Delete
rm -fr -- "$ROOT/usr/${dir}.usrmove-old"
[150] Fix | Delete
mv "$ROOT/usr/$dir" "$ROOT/usr/${dir}.usrmove-old"
[151] Fix | Delete
mv "$ROOT/usr/${dir}.usrmove-new" "$ROOT/usr/$dir"
[152] Fix | Delete
done
[153] Fix | Delete
[154] Fix | Delete
# replace dirs in / with links to /usr
[155] Fix | Delete
for dir in bin sbin lib lib64; do
[156] Fix | Delete
[[ -L "$ROOT/$dir" ]] && continue
[157] Fix | Delete
[[ -d "$ROOT/$dir" ]] || continue
[158] Fix | Delete
echo "Create \`$ROOT/$dir' symlink."
[159] Fix | Delete
rm -fr -- "$ROOT/${dir}.usrmove-old" || :
[160] Fix | Delete
mv "$ROOT/$dir" "$ROOT/${dir}.usrmove-old"
[161] Fix | Delete
ln -sfn usr/$dir "$ROOT/$dir"
[162] Fix | Delete
done
[163] Fix | Delete
[164] Fix | Delete
echo "Clean up backup files."
[165] Fix | Delete
# everything seems to work; cleanup
[166] Fix | Delete
for dir in bin sbin lib lib64; do
[167] Fix | Delete
# if we get killed in the middle of "rm -rf", ensure not to leave
[168] Fix | Delete
# an incomplete directory, which is moved back by cleanup()
[169] Fix | Delete
[[ -d "$ROOT/usr/${dir}.usrmove-old" ]] \
[170] Fix | Delete
&& mv "$ROOT/usr/${dir}.usrmove-old" "$ROOT/usr/${dir}.usrmove-old~"
[171] Fix | Delete
[[ -d "$ROOT/${dir}.usrmove-old" ]] \
[172] Fix | Delete
&& mv "$ROOT/${dir}.usrmove-old" "$ROOT/${dir}.usrmove-old~"
[173] Fix | Delete
done
[174] Fix | Delete
[175] Fix | Delete
for dir in bin sbin lib lib64; do
[176] Fix | Delete
[[ -d "$ROOT/usr/${dir}.usrmove-old~" ]] \
[177] Fix | Delete
&& rm -rf -- "$ROOT/usr/${dir}.usrmove-old~" || :
[178] Fix | Delete
[[ -d "$ROOT/${dir}.usrmove-old~" ]] \
[179] Fix | Delete
&& rm -rf -- "$ROOT/${dir}.usrmove-old~" || :
[180] Fix | Delete
done
[181] Fix | Delete
[182] Fix | Delete
for dir in lib lib64; do
[183] Fix | Delete
[[ -d "$ROOT/$dir" ]] || continue
[184] Fix | Delete
for lib in "$ROOT"/usr/${dir}/lib*.so*.usrmove~; do
[185] Fix | Delete
[[ -f $lib ]] || continue
[186] Fix | Delete
mv $lib ${lib/.so/_so}
[187] Fix | Delete
done
[188] Fix | Delete
done
[189] Fix | Delete
[190] Fix | Delete
set +e
[191] Fix | Delete
[192] Fix | Delete
echo "Run ldconfig."
[193] Fix | Delete
ldconfig -r "$ROOT"
[194] Fix | Delete
[195] Fix | Delete
. $ROOT/etc/selinux/config
[196] Fix | Delete
if [ -n "$(command -v setfiles)" ] && [ "$SELINUX" != "disabled" ] && [ -f /etc/selinux/${SELINUXTYPE}/contexts/files/file_contexts ]; then
[197] Fix | Delete
echo "Fixing SELinux labels"
[198] Fix | Delete
setfiles -r $ROOT -p /etc/selinux/${SELINUXTYPE}/contexts/files/file_contexts $ROOT/sbin $ROOT/bin $ROOT/lib $ROOT/lib64 $ROOT/usr/lib $ROOT/usr/lib64 $ROOT/etc/ld.so.cache $ROOT/var/cache/ldconfig || :
[199] Fix | Delete
fi
[200] Fix | Delete
[201] Fix | Delete
echo "Done."
[202] Fix | Delete
exit 0
[203] Fix | Delete
[204] Fix | Delete
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function