mirror of
https://gitee.com/amber-ce/amber-pm
synced 2025-12-17 10:51:36 +08:00
init
This commit is contained in:
0
ace-env/etc/resolv.conf
Normal file
0
ace-env/etc/resolv.conf
Normal file
140
ace-run
Executable file
140
ace-run
Executable file
@@ -0,0 +1,140 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
chrootEnvPath=$(pwd)/ace-env
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
non_root_user=$(who | awk '{print $1}' | head -n 1)
|
||||||
|
uid=$(id -u $non_root_user)
|
||||||
|
|
||||||
|
|
||||||
|
#### This part is for args pharm
|
||||||
|
if [ "$1" = "" ];then
|
||||||
|
container_command="bash"
|
||||||
|
else
|
||||||
|
container_command="$1"
|
||||||
|
shift
|
||||||
|
for arg in "$@"; do
|
||||||
|
arg="$(echo "${arg}x" | sed 's|'\''|'\'\\\\\'\''|g')"
|
||||||
|
arg="${arg%x}"
|
||||||
|
container_command="${container_command} '${arg}'"
|
||||||
|
done
|
||||||
|
fi
|
||||||
|
#########################################################################################
|
||||||
|
##########合成bwrap 1. 基础函数配置段
|
||||||
|
# 初始化 EXEC_COMMAND 为 bwrap 基础指令
|
||||||
|
EXEC_COMMAND="bwrap --dev-bind / / bwrap"
|
||||||
|
|
||||||
|
# add_command 函数定义
|
||||||
|
function add_command() {
|
||||||
|
# 参数拼接,考虑到转义和空格的处理
|
||||||
|
for arg in "$@"; do
|
||||||
|
EXEC_COMMAND="${EXEC_COMMAND} ${arg}"
|
||||||
|
done
|
||||||
|
}
|
||||||
|
|
||||||
|
function add_env_var() {
|
||||||
|
local var_name="${1}"
|
||||||
|
local var_value="${2}"
|
||||||
|
if [ "$var_value" != "" ]; then
|
||||||
|
add_command "--setenv $var_name $var_value"
|
||||||
|
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
##########合成bwrap 2. 特殊需求函数配置段
|
||||||
|
function cursor_theme_dir_integration() {
|
||||||
|
|
||||||
|
local directory=""
|
||||||
|
if [ "$(id -u)" = "0" ]; then #####We don't want bother root to install themes,but will try to fix the unwriteable issue
|
||||||
|
mkdir -p $chrootEnvPath/usr/share/icons
|
||||||
|
chmod 777 -R $chrootEnvPath/usr/share/icons
|
||||||
|
return
|
||||||
|
fi
|
||||||
|
|
||||||
|
for directory in "/usr/share/icons"/*; do
|
||||||
|
# 检查是否为目录
|
||||||
|
if [ -d "$directory" ]; then
|
||||||
|
# 检查目录中是否存在 cursors 文件
|
||||||
|
if [ -d "$directory/cursors" ]; then
|
||||||
|
if [ -w $chrootEnvPath/usr/share/icons ];then
|
||||||
|
add_command "--ro-bind-try $directory $directory"
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
done
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
##########合成bwrap 3. 环境变量和目录绑定配置段
|
||||||
|
# 添加环境变量和其他初始设置
|
||||||
|
ENV_VARS=(
|
||||||
|
"FAKEROOTDONTTRYCHOWN 1"
|
||||||
|
"PULSE_SERVER /run/user/\$uid/pulse/native"
|
||||||
|
"PATH /amber-ce-tools/bin-override:\$PATH"
|
||||||
|
"IS_ACE_ENV 1"
|
||||||
|
"XDG_DATA_DIRS /amber-ce-tools/additional-data-dir-in-container:\$XDG_DATA_DIRS"
|
||||||
|
)
|
||||||
|
|
||||||
|
BIND_DIRS=(
|
||||||
|
"--dev-bind $chrootEnvPath/ /"
|
||||||
|
"--dev-bind-try /media /media"
|
||||||
|
"--dev-bind-try /mnt /mnt"
|
||||||
|
"--dev-bind-try /tmp /tmp"
|
||||||
|
"--dev-bind-try /data /data"
|
||||||
|
"--dev-bind-try /dev /dev"
|
||||||
|
"--proc /proc"
|
||||||
|
"--dev-bind /sys /sys"
|
||||||
|
"--dev-bind /run /run"
|
||||||
|
"--dev-bind-try /run/user/\$uid/pulse /run/user/\$uid/pulse"
|
||||||
|
"--dev-bind / /host"
|
||||||
|
"--ro-bind-try /usr/share/themes /usr/local/share/themes"
|
||||||
|
"--ro-bind-try /usr/share/icons /usr/local/share/icons"
|
||||||
|
"--ro-bind-try /usr/share/fonts /usr/local/share/fonts"
|
||||||
|
"--dev-bind-try /etc/resolv.conf /etc/resolv.conf"
|
||||||
|
"--dev-bind-try /home /home"
|
||||||
|
)
|
||||||
|
EXTRA_ARGS=(
|
||||||
|
"--hostname Amber-PM"
|
||||||
|
"--unshare-uts"
|
||||||
|
"--cap-add CAP_SYS_ADMIN"
|
||||||
|
)
|
||||||
|
|
||||||
|
EXTRA_SCRIPTS=(
|
||||||
|
cursor_theme_dir_integration
|
||||||
|
)
|
||||||
|
|
||||||
|
##########合成bwrap 4. 合成并执行指令
|
||||||
|
# 逐一添加到 EXEC_COMMAND
|
||||||
|
for var in "${ENV_VARS[@]}"; do
|
||||||
|
add_env_var $var
|
||||||
|
done
|
||||||
|
|
||||||
|
for var in "${BIND_DIRS[@]}"; do
|
||||||
|
add_command "$var"
|
||||||
|
done
|
||||||
|
|
||||||
|
for var in "${EXTRA_ARGS[@]}"; do
|
||||||
|
add_command "$var"
|
||||||
|
done
|
||||||
|
|
||||||
|
for var in "${EXTRA_SCRIPTS[@]}"; do
|
||||||
|
$var
|
||||||
|
done
|
||||||
|
|
||||||
|
# 添加最终的 bash 命令
|
||||||
|
add_command "bash -c \"${container_command}\""
|
||||||
|
|
||||||
|
# 输出完整的 EXEC_COMMAND 以查看
|
||||||
|
# echo "${EXEC_COMMAND}"
|
||||||
|
|
||||||
|
# 注意: 实际执行时,请确保所有变量(如 $uid, $chrootEnvPath 等)都已正确定义
|
||||||
|
eval ${EXEC_COMMAND}
|
||||||
|
|
||||||
|
|
||||||
107
apm.sh
Executable file
107
apm.sh
Executable file
@@ -0,0 +1,107 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
VERSION=0.1
|
||||||
|
# 获取脚本名称用于帮助信息
|
||||||
|
SCRIPT_NAME=$(basename "$0")
|
||||||
|
|
||||||
|
# 帮助信息函数
|
||||||
|
show_help() {
|
||||||
|
cat <<EOF
|
||||||
|
APM - Amber Package Manager ${VERSION}
|
||||||
|
|
||||||
|
Usage:
|
||||||
|
$SCRIPT_NAME [COMMAND] [OPTIONS] [PACKAGES...]
|
||||||
|
|
||||||
|
Commands:
|
||||||
|
install 安装软件包
|
||||||
|
remove 卸载软件包
|
||||||
|
autoremove 自动移除不需要的包
|
||||||
|
full-upgrade 完全升级软件包
|
||||||
|
run <package> 运行指定软件包的可执行文件
|
||||||
|
debug 显示调试系统信息
|
||||||
|
-h, --help 显示此帮助信息
|
||||||
|
--amber 彩蛋功能
|
||||||
|
|
||||||
|
EOF
|
||||||
|
}
|
||||||
|
|
||||||
|
# 调试信息函数
|
||||||
|
debug_info() {
|
||||||
|
echo "======= APM Debug Information ======="
|
||||||
|
echo "User: $(whoami)"
|
||||||
|
echo "Hostname: $(hostname)"
|
||||||
|
echo "OS: $(lsb_release -ds 2>/dev/null || uname -om)"
|
||||||
|
echo "Kernel: $(uname -sr)"
|
||||||
|
echo "Bash Version: ${BASH_VERSION}"
|
||||||
|
echo "APT Version: $(apt --version | head -n1)"
|
||||||
|
echo "====================================="
|
||||||
|
}
|
||||||
|
|
||||||
|
# 彩蛋函数
|
||||||
|
amber_egg() {
|
||||||
|
cat <<EOF
|
||||||
|
_ _ _ _ _____ ______
|
||||||
|
| | | | \ | | __ \| ___ \
|
||||||
|
| | | | \| | | \/| |_/ /
|
||||||
|
| |/\| | . \` | | __ | ___ \
|
||||||
|
\ /\ / |\ | |_\ \| |_/ /
|
||||||
|
\/ \/\_| \_/\____/\____/
|
||||||
|
|
||||||
|
Amber Package Manager - Sparkling with magic!
|
||||||
|
💎 Nothing is impossible for APM!
|
||||||
|
EOF
|
||||||
|
}
|
||||||
|
|
||||||
|
# 主命令处理
|
||||||
|
case "$1" in
|
||||||
|
install|remove|autoremove|full-upgrade)
|
||||||
|
# 特殊APT命令:移除第一个参数后传递其余参数
|
||||||
|
command=$1
|
||||||
|
shift
|
||||||
|
sudo apt "$command" "$@"
|
||||||
|
;;
|
||||||
|
run)
|
||||||
|
# 运行包命令:第二个参数必须是包名
|
||||||
|
if [ -z "$2" ]; then
|
||||||
|
echo "Error: Package name required for 'run' command"
|
||||||
|
show_help
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
# 检查包是否已安装
|
||||||
|
pkg="$2"
|
||||||
|
shift 2 # 移除 'run' 和包名
|
||||||
|
|
||||||
|
if ! dpkg -l | grep "^ii $1 " > /dev/null; then
|
||||||
|
echo "Package not installed: $pkg"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
# 检测是否有额外命令参数
|
||||||
|
if [ $# -gt 0 ]; then
|
||||||
|
# 有额外参数:执行用户提供的命令
|
||||||
|
echo "Running user command: $*"
|
||||||
|
exec "$@"
|
||||||
|
else
|
||||||
|
# 没有额外参数:执行包的主程序
|
||||||
|
bin_path=$(dpkg -L "$pkg" | grep -m1 -E '/bin/|/sbin/|/games/')
|
||||||
|
if [ -z "$bin_path" ]; then
|
||||||
|
echo "Error: No executable found in package '$pkg'"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
echo "Running package executable: $bin_path"
|
||||||
|
exec "$bin_path"
|
||||||
|
fi
|
||||||
|
;;
|
||||||
|
debug)
|
||||||
|
debug_info
|
||||||
|
;;
|
||||||
|
-h|--help)
|
||||||
|
show_help
|
||||||
|
;;
|
||||||
|
--amber)
|
||||||
|
amber_egg
|
||||||
|
;;
|
||||||
|
*)
|
||||||
|
show_help
|
||||||
|
;;
|
||||||
|
esac
|
||||||
1
merge.sh
Normal file
1
merge.sh
Normal file
@@ -0,0 +1 @@
|
|||||||
|
fuse-overlayfs -o lowerdir=base/,upperdir=core/,workdir=temp/ ./ace-env/
|
||||||
22
备忘录.txt
Normal file
22
备忘录.txt
Normal file
@@ -0,0 +1,22 @@
|
|||||||
|
sudo mount -t overlay overlay -o lowerdir='/var/lib/apm/amber-pm-trixie/files/ace-env',upperdir=core/,workdir=work/ ./ace-env
|
||||||
|
|
||||||
|
随后chroot进入进行安装操作,完成后
|
||||||
|
|
||||||
|
core: 保存新增文件
|
||||||
|
work: 保存变更信息
|
||||||
|
需把这两个文件的权限换成755
|
||||||
|
|
||||||
|
|
||||||
|
fuse-overlayfs -o lowerdir='/var/lib/apm/amber-pm-trixie/files/ace-env',upperdir=core/,workdir=work/ ./ace-env
|
||||||
|
|
||||||
|
即可只读挂载并进行ace操作
|
||||||
|
|
||||||
|
计划:
|
||||||
|
|
||||||
|
/var/lib/apm/包名/files/core是upperdir
|
||||||
|
/var/lib/apm/包名/files/work是upperdir
|
||||||
|
/var/lib/apm/包名/files/ace-env是chroot进的目录
|
||||||
|
/var/lib/apm/包名/info是配置信息
|
||||||
|
|
||||||
|
|
||||||
|
apm run 包名: 寻找 /var/lib/apm/包名/是否存在。若存在,根据info文件合成 fuser-overlayfs(ll-killer) 参数进行挂载,随后用ACE工具chroot进入进行启动
|
||||||
Reference in New Issue
Block a user