Skip to content
This repository has been archived by the owner on Oct 11, 2024. It is now read-only.

Commit

Permalink
check_chroot_conf
Browse files Browse the repository at this point in the history
  • Loading branch information
2moe committed Apr 30, 2021
1 parent 1064a7a commit 9e207f9
Show file tree
Hide file tree
Showing 7 changed files with 48 additions and 23 deletions.
2 changes: 1 addition & 1 deletion .mirror/manager
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ check_tmoe_command() {
else
TMOE_TIPS_01="tmoe"
fi
TMOE_TIPS_00="Welcome to tmoe linux manager v1.4596,type ${TMOE_TIPS_01} to start it."
TMOE_TIPS_00="Welcome to tmoe linux manager v1.4597,type ${TMOE_TIPS_01} to start it."
}
#########################
tmoe_manager_env() {
Expand Down
2 changes: 1 addition & 1 deletion .mirror/tool
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ check_tmoe_command() {
else
TMOE_TIPS_01="tmoe t"
fi
TMOE_TIPS_00="Welcome to tmoe linux tool v1.4596,type ${TMOE_TIPS_01} to start this tool."
TMOE_TIPS_00="Welcome to tmoe linux tool v1.4597,type ${TMOE_TIPS_01} to start this tool."
#勿改00变量
}
#########
Expand Down
2 changes: 1 addition & 1 deletion manager.sh
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ check_tmoe_command() {
else
TMOE_TIPS_01="tmoe"
fi
TMOE_TIPS_00="Welcome to tmoe linux manager v1.4596,type ${TMOE_TIPS_01} to start it."
TMOE_TIPS_00="Welcome to tmoe linux manager v1.4597,type ${TMOE_TIPS_01} to start it."
}
#########################
tmoe_manager_env() {
Expand Down
35 changes: 20 additions & 15 deletions share/app/tmoe
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ tmoe_main() {
;;
c* | chroot)
source_tmoe_env
check_chroot_mode
check_chroot_mode_01
TMOE_CHROOT=true
;;
systemd | sd | systemctl | ns | nspawn)
Expand All @@ -20,7 +20,7 @@ tmoe_main() {
;;
ls)
check_manager_dir
check_chroot_mode
check_chroot_mode_02
bash ${MANAGER_DIR}/share/container/debian/lnk-menu
exit 0
;;
Expand Down Expand Up @@ -198,7 +198,7 @@ tmoe_main() {
start_tmoe_container
}
#############
check_chroot_mode() {
check_chroot_mode_02() {
CONFIG_FOLDER=${HOME}/.config/tmoe-linux
if [[ -s ${CONFIG_FOLDER}/chroot.conf ]]; then
if ! egrep -q '^[^#]*SYSTEMD_NSPAWN=' ${CONFIG_FOLDER}/chroot.conf; then
Expand All @@ -209,19 +209,24 @@ check_chroot_mode() {
else
export SYSTEMD_NSPAWN=false
fi

case ${TMOE_CHROOT} in
true)
if [[ -e ${DEBIAN_CHROOT}/usr/local/etc/tmoe-linux/container/chroot.conf ]]; then
unset SYSTEMD_NSPAWN
if ! egrep -q '^[^#]*SYSTEMD_NSPAWN=' ${CONFIG_FOLDER}/chroot.conf; then
SYSTEMD_NSPAWN=false
else
SYSTEMD_NSPAWN=$(egrep '^[^#]*SYSTEMD_NSPAWN=' ${CONFIG_FOLDER}/chroot.conf | awk -F '=' '{print $2}')
fi
}
check_chroot_mode_01() {
CHROOT_CONF=${DEBIAN_CHROOT}/usr/local/etc/tmoe-linux/container/chroot.conf
SYSTEMD_NSPAWN=false
if [[ -s ${CONFIG_FOLDER}/chroot.conf ]]; then
if ! egrep -q '^[^#]*SYSTEMD_NSPAWN=' ${CONFIG_FOLDER}/chroot.conf; then
SYSTEMD_NSPAWN=false
else
SYSTEMD_NSPAWN=$(egrep '^[^#]*SYSTEMD_NSPAWN=' ${CONFIG_FOLDER}/chroot.conf | awk -F '=' '{print $2}')
fi
;;
esac
fi
if [[ -e ${CHROOT_CONF} ]]; then
if ! egrep -q '^[^#]*SYSTEMD_NSPAWN=' ${CHROOT_CONF}; then
SYSTEMD_NSPAWN=false
else
SYSTEMD_NSPAWN=$(egrep '^[^#]*SYSTEMD_NSPAWN=' ${CHROOT_CONF} | awk -F '=' '{print $2}')
fi
fi
}
check_manager_dir() {
MANAGER_DIR_01="${HOME}/.local/share/tmoe-linux/git"
Expand Down
8 changes: 5 additions & 3 deletions share/container/menu
Original file line number Diff line number Diff line change
Expand Up @@ -97,13 +97,14 @@ systemd_nspawn_is_true_or_false() {
# fi
}
switch_chroot_default_mode() {
if (whiptail --title "CHROOT MODE" --yes-button "systemd" --no-button "normal" --yesno "It is recommended to use the systemd mode.\nIf you want to use systemctl in the container,\nyou also need to enable the boot option of nspawn.\nIf you cannot use the systemd mode,\nthen switch it back to the normal mode." 11 50); then
if (whiptail --title "CHROOT MODE" --yes-button "systemd" --no-button "normal" --yesno "It is recommended to use the systemd mode.\nIf you want to use systemctl in the container,\nyou also need to enable the boot mode of nspawn.\nIf you cannot use the systemd mode,\nthen switch it back to the normal mode." 13 50); then
systemd_nspawn_is_true
else
systemd_nspawn_is_false
fi
printf "%s\n" "This feature is only available for uncreated containers."
printf "%s\n" "For the container that has been created, if you want to change the mode, please execute the following commands in the container."
printf "%s\n" ""
printf "${GREEN}%s${RESET}\n" "cd /usr/local/etc/tmoe-linux/container"
printf "%s\n" "If you want to use the systemd mode, you can do so."
printf "${GREEN}%s${RESET}\n" "ln -svf nspawn tmoe-linux-container ; sed -i -E 's@^(SYSTEMD_NSPAWN=).*@\1true@' chroot.conf"
Expand Down Expand Up @@ -141,7 +142,7 @@ chroot_container_menu_multi_langs() {
SELECTED_GNU_LINUX=$(whiptail --title "${CONTAINER_TYPE} container" --menu "Chroot in normal mode is not suitable for production environment,\nit is recommended to use the systemd mode.\n${TMOE_TIPS_04}" 0 50 0 \
"1" "💠 ${TRUE_ARCH_TYPE} distros list" \
"2" "📑 List installed" \
"3" "🥛 alpha:switch chroot mode(systemd/normal)" \
"3" "🥛 beta:switch chroot mode(systemd/normal)" \
"4" "⚔️ Across architectures" \
"5" "🔯 Restore ${CONTAINER_TYPE} container" \
"6" "📕 Configuration & manual" \
Expand All @@ -152,7 +153,7 @@ chroot_container_menu_multi_langs() {
SELECTED_GNU_LINUX=$(whiptail --title "${CONTAINER_TYPE}容器" --menu "由于普通模式的chroot在umount时可能会产生bug,\n故只适用于恢复环境,不适用于生产环境,建议您使用systemd模式。\n${TMOE_TIPS_04}" 0 50 0 \
"1" "💠 ${TRUE_ARCH_TYPE}发行版列表" \
"2" "📑 List installed 当前已安装容器列表" \
"3" "🥛 alpha内测:切换chroot默认模式(systemd/normal)" \
"3" "🥛 beta公测:切换chroot默认模式(systemd/normal)" \
"4" "⚔️ Across architectures 跨CPU架构" \
"5" "🔯 Restore 恢复/还原${CONTAINER_TYPE}容器" \
"6" "📕 配置与手册" \
Expand Down Expand Up @@ -217,6 +218,7 @@ systemd_nspawn_env() {
fi
#double check
if [ ! $(command -v systemd-nspawn) ]; then
printf "%s\n" "Sorry,this feature does not support your ${PURPLE}${LINUX_DISTRO}${RESET} system."
systemd_nspawn_is_false
press_enter_to_return
chroot_container_menu_multi_langs
Expand Down
20 changes: 19 additions & 1 deletion share/container/proot/management
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ proot_management_menu() {
TMOE_CONTAINER_FORTUNE=true
TMOE_CONTAINER_HITOKOTO=true
MACHINE_NAME=$(printf "%s\n" ${DEBIAN_FOLDER} | sed 's@_@-@g')
check_chroot_conf
proot_management_menu_en() {
SELECTED_GNU_LINUX=$(whiptail --title "${DEBIAN_FOLDER_CAPITAL}" --menu "CONTAINER_DIR=${DEBIAN_CHROOT_MIN}\nFor non-special circumstances,please do not run rm -rf \${CONTAINER_DIR} manually." 0 50 0 \
"1" "🌱 start ${DEBIAN_FOLDER}" \
Expand Down Expand Up @@ -101,6 +102,20 @@ proot_management_menu() {
#卸载之后要回到发行版选择菜单,而非当前发行版菜单
}
##############################
check_chroot_conf() {
case ${TMOE_CHROOT} in
true)
CHROOT_CONF=${DEBIAN_CHROOT}/usr/local/etc/tmoe-linux/container/chroot.conf
if [[ -e ${CHROOT_CONF} ]]; then
if ! egrep -q '^[^#]*SYSTEMD_NSPAWN=' ${CHROOT_CONF}; then
SYSTEMD_NSPAWN=false
else
SYSTEMD_NSPAWN=$(egrep '^[^#]*SYSTEMD_NSPAWN=' ${CHROOT_CONF} | awk -F '=' '{print $2}')
fi
fi
;;
esac
}
environment_variables_and_automatic_startup_script_management() {
RETURN_TO_WHERE="environment_variables_and_automatic_startup_script_management"
environment_variables_and_automatic_startup_script_management_menu_en() {
Expand Down Expand Up @@ -444,7 +459,7 @@ kill_container_process() {
case ${TMOE_CHROOT} in
true)
case ${SYSTEMD_NSPAWN} in
true) machinectl terminate ${MACHINE_NAME} || ${TMOE_PREFIX} machinectl terminate ${MACHINE_NAME} ;;
true) machinectl terminate ${MACHINE_NAME} ;;
*) kill_chroot_container_process ;;
esac
;;
Expand Down Expand Up @@ -1010,6 +1025,9 @@ install_weekly_build_container() {
#############
umount_and_remove_gnu_linux_distro() {
kill_container_process
case ${SYSTEMD_NSPAWN} in
true) kill_chroot_container_process ;;
esac
source ${TMOE_SHARE_DIR}/container/remove
}
du_sh_gnu_linux_distro() {
Expand Down
2 changes: 1 addition & 1 deletion tool.sh
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ check_tmoe_command() {
else
TMOE_TIPS_01="tmoe t"
fi
TMOE_TIPS_00="Welcome to tmoe linux tool v1.4596,type ${TMOE_TIPS_01} to start this tool."
TMOE_TIPS_00="Welcome to tmoe linux tool v1.4597,type ${TMOE_TIPS_01} to start this tool."
#勿改00变量
}
#########
Expand Down

0 comments on commit 9e207f9

Please sign in to comment.