mirror of
https://github.com/bin456789/reinstall.git
synced 2025-12-10 15:37:43 +08:00
core: 运行出错时,显示出错命令
This commit is contained in:
@ -4,6 +4,7 @@ confhome=https://raw.githubusercontent.com/bin456789/reinstall/main
|
|||||||
localtest_confhome=http://192.168.253.1
|
localtest_confhome=http://192.168.253.1
|
||||||
|
|
||||||
trap 'error line $LINENO return $?' ERR
|
trap 'error line $LINENO return $?' ERR
|
||||||
|
this_script=$(realpath $0)
|
||||||
|
|
||||||
usage_and_exit() {
|
usage_and_exit() {
|
||||||
cat <<EOF
|
cat <<EOF
|
||||||
@ -30,9 +31,11 @@ info() {
|
|||||||
error() {
|
error() {
|
||||||
color='\e[31m'
|
color='\e[31m'
|
||||||
plain='\e[0m'
|
plain='\e[0m'
|
||||||
|
echo -e "${color}Error: $*${plain}"
|
||||||
# 如果从trap调用,显示错误行
|
# 如果从trap调用,显示错误行
|
||||||
[ "$1" = line ] && sed -n "$2"p $0
|
if [ "$1" = line ]; then
|
||||||
echo -e "${color}Error: $*$plain"
|
sed -n "$2"p $this_script
|
||||||
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
error_and_exit() {
|
error_and_exit() {
|
||||||
|
|||||||
8
trans.sh
8
trans.sh
@ -6,6 +6,7 @@
|
|||||||
# 命令出错终止运行,将进入到登录界面,防止失联
|
# 命令出错终止运行,将进入到登录界面,防止失联
|
||||||
set -eE
|
set -eE
|
||||||
trap 'error line $LINENO return $?' ERR
|
trap 'error line $LINENO return $?' ERR
|
||||||
|
this_script=$(realpath $0)
|
||||||
|
|
||||||
catch() {
|
catch() {
|
||||||
if [ "$1" != "0" ]; then
|
if [ "$1" != "0" ]; then
|
||||||
@ -16,10 +17,11 @@ catch() {
|
|||||||
error() {
|
error() {
|
||||||
color='\e[31m'
|
color='\e[31m'
|
||||||
plain='\e[0m'
|
plain='\e[0m'
|
||||||
# 如果从trap调用,显示错误行
|
|
||||||
[ "$1" = line ] && sed -n "$2"p $0
|
|
||||||
echo -e "${color}Error: $*${plain}"
|
echo -e "${color}Error: $*${plain}"
|
||||||
wall "Error: $*"
|
# 如果从trap调用,显示错误行
|
||||||
|
if [ "$1" = line ]; then
|
||||||
|
sed -n "$2"p $this_script
|
||||||
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
error_and_exit() {
|
error_and_exit() {
|
||||||
|
|||||||
Reference in New Issue
Block a user