我错误地备份到 NTFS 驱动器。恢复后所有权限都设置为777。
我修复了一些重要文件,例如 sudo 和 su。我现在无法重新安装,因为我的互联网连接受到限制,至少在接下来的一周内。
我记得pacman以gzipped格式存储每个包的mtree文件中与文件相关的元数据。我尝试用这个公用事业但似乎 bsdtar mtree 格式有问题,所以我决定编写自己的 bash 脚本,它只是 chmods 文件。
这是acl的mtree供参考 -
gzip -cd /var/lib/pacman/local/acl-2.2.52-3/mtree
输出 -
#mtree
/set type=file uid=0 gid=0 mode=644
./.BUILDINFO time=1478441026.526890249 size=3111 md5digest=80956213c6346f28d8f1b5a9165b952d sha256digest=5e56cab859054c2ca7759cbe50adbc0b6352f78fad3b051bb9174f3bf17f9c21
./.PKGINFO time=1478441026.513556943 size=434 md5digest=8e7df6a965b196aa5564786f022d068d sha256digest=504c99ff77ddb0d2847d7e8c85f637ad78edd78db3ee91a6b491bee5884ebb22
/set mode=755
./usr time=1478441025.433559189 type=dir
./usr/bin time=1478441026.323557338 type=dir
./usr/bin/chacl time=1478441026.323557338 size=14672 md5digest=69332d6d57c153ad21ecf1c09381363d sha256digest=faafbb9420403fb13d4207e986ee0ba940a97b1feb3fcde453669912afeaa340
./usr/bin/getfacl time=1478441026.313557360 size=23680 md5digest=ef23d3c7676198e08d71530c58f44026 sha256digest=f22b3fd68e46d767e7f255be7427cebde9f7539357b2625fade7fa86fbb60743
./usr/bin/setfacl time=1478441026.320224012 size=36224 md5digest=9f6a5f7ddcb08b787b39bcfda4047828 sha256digest=4ac33e394ec50676af4015498fecc867802de3f14f7a589c7d972fcc2b720b4d
./usr/include time=1478441025.466892453 type=dir
./usr/include/acl time=1478441025.473559107 type=dir
./usr/include/acl/libacl.h time=1478441025.473559107 mode=644 size=2590 md5digest=9cd8a73452e0cf899928b27b20b02d6e sha256digest=21366c9f8ffe4018cc3753a73e0c81f0c54102435031de8f5325675f55a42bf2
./usr/include/sys time=1478441025.460225800 type=dir
./usr/include/sys/acl.h time=1478441025.460225800 mode=644 size=3755 md5digest=8ea51961753fc1da4cae7fd48d2068c0 sha256digest=287dbc9269df3fe9e6b0a1dc6c0aac8e90b925867bf235a554a02414f6fcedfd
/set mode=777
./usr/lib time=1478441025.996891351 mode=755 type=dir
./usr/lib/libacl.so time=1478441025.483559085 type=link link=libacl.so.1
./usr/lib/libacl.so.1 time=1478441025.463559127 type=link link=libacl.so.1.1.0
./usr/lib/libacl.so.1.1.0 time=1478441025.996891351 mode=644 size=35456 md5digest=3e5e200ae58fdf7f4558ef863b11d9a6 sha256digest=f8c7e1c06646c5d46725cbc4d0c7290b35d4d2c4203df2a0ccb42e7635be6ce6
/set mode=755
./usr/share time=1478441025.353559356 type=dir
为简洁起见进行了修剪。
我的做法是这样的 -
- 逐行读取此输出
- 如果我们遇到“/set mode=”行,则解析 mode 的值
- 解析文件名并继续 chmodding。
- 如果文件具有单独模式,请使用该模式而不是全局模式。
所以,对于第一步(逐行阅读)我做了 -
file = "$1"
while read var
do
echo "$var"
done < "$file"
但这给了我
=: cannot open `=' (No such file or directory)
: cannot open `' (No such file or directory)
./test: line 5: : No such file or directory
任何帮助是极大的赞赏。
答案1
因为我想为这个问题提供帮助,所以我编写了一些 Bash 脚本来修复基于 MTREE 的文件权限......
curl https://xgit.ddns.net/ergotamin/ShellScripting/raw/master/fix-permissions \
>fix-permissions && chmod 0775 fix-permissions
Usage:
fix-permissions --all -- to fix all permissions of whole FS
fix-permission "/var/lib/pacman/local/PKGNAME -- to fix only this mtree
无关:
这里:点击我你可以找到一个用 C 编码的解决方案,它比 Bash 版本快得多......
用法:
use-mtree /path/to/*/mtree
源代码可用这里...这里(所需的标题可在我的网站上找到):
/*******************************************
* ! Copyright (C)2018
* ! Marcel Bobolz
*
* $ Copying and distribution of this file, with or without modification,
* $ are permitted in any medium without royalty provided the copyright
* $ notice and this notice are preserved. This file is offered as-is,
* $ without any warranty.
*
*
* @ Code-Information :
*
* => % MTree-Parser
*
*******************************************/
#include <xstdarchive.h
>
__attribute__((flatten)) __bool_t main(__i32_t ArgC, __charr_t ArgV){
ArgC--;
ArgV++;
__u64_t BytesRead = ZERO;
static __file_t PFile;
static __uch_t MTreeBuf[BUF1MB];
foreach(ArgV){
((PFile = popen(StrForm("%s%s", "gzip -cd ", *ArgV), "r")) == NULL) ? \
(exit(ERROR)) : (BytesRead = fread(MTreeBuf, ONE, BUF1MB - ONE, PFile));
(BytesRead > ZERO) ? (pclose(PFile)) : (exit(ERROR));
MTreeBuf[BytesRead] = ZERO;
ArchiveListArchive(((__str_t)MTreeBuf), 'x');
memset(MTreeBuf, ZERO, BUF1MB);
PFile = NU(__file_t);
}
return(SUCCESS);
}