Skip to content

Commit 4f2e7ba

Browse files
committed
Script: modify common.sh
1 parent 42262b0 commit 4f2e7ba

8 files changed

Lines changed: 44 additions & 37 deletions

File tree

Script/build_android.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ fi
1212

1313
source $(dirname $(readlink -f $0))/common.sh
1414
detect_os_info
15+
check_echo_color_with_tput
1516

1617
# modify follow value
1718
Qt6_DIR=/opt/Qt/6.6.3/android_x86_64

Script/build_appimage.sh

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ fi
1515

1616
source $(dirname $(readlink -f $0))/common.sh
1717
detect_os_info
18+
check_echo_color_with_tput
1819

1920
usage_long() {
2021
echo "$0 [--install=<install directory>] [ [-h|--help] [-v|--verbose[=0|1]] --source=<source directory>] [--tools=<tools directory>] [--build=<build directory>]"
@@ -41,7 +42,7 @@ if command -V getopt >/dev/null; then
4142
OPTS=help,verbose::,install:,source:,tools:,build:
4243
ARGS=`getopt -o h,v:: -l $OPTS -n $(basename $0) -- "$@"`
4344
if [ $? != 0 ]; then
44-
log_fail "exec getopt fail: $?"
45+
echo_error "exec getopt fail: $?"
4546
exit 1
4647
fi
4748
#echo "ARGS=[$ARGS]"

Script/build_debpackage.sh

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ INSTALL_BUILD_DEPEND=0
1414

1515
source $(dirname $(readlink -f $0))/common.sh
1616
detect_os_info
17+
check_echo_color_with_tput
1718

1819
usage_long() {
1920
echo "$0 [-h|--help] [-v|--verbose[=0|1]] [--install=<install directory>] [--rabbitcommon<RabbitCommon directory>"
@@ -38,7 +39,7 @@ if command -V getopt >/dev/null; then
3839
OPTS=help,verbose::,install:,rabbitcommon::,install-build-depend::
3940
ARGS=`getopt -o h,v:: -l $OPTS -n $(basename $0) -- "$@"`
4041
if [ $? != 0 ]; then
41-
log_fail "exec getopt fail: $?"
42+
echo_error "exec getopt fail: $?"
4243
exit 1
4344
fi
4445
#echo "ARGS=[$ARGS]"

Script/build_depend.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ fi
1313

1414
source $(dirname $(readlink -f $0))/common.sh
1515
detect_os_info
16+
check_echo_color_with_tput
1617

1718
install_gnu_getopt
1819
if [ "$DISTRO" = "macOS" ]; then

Script/build_linux.sh

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ parse_with_getopt() {
8484
OPTS=help,verbose::,docker::,deb::,rpm::,appimage::,macos::,docker-image:,docker-platform::,qt:,install:,source:,tools:,build:
8585
ARGS=`getopt -o h,v:: -l $OPTS -n $(basename $0) -- "$@"`
8686
if [ $? != 0 ]; then
87-
log_fail "exec getopt fail: $?"
87+
echo_error "exec getopt fail: $?"
8888
exit 1
8989
fi
9090
#echo "ARGS=[$ARGS]"
@@ -263,7 +263,7 @@ validate_parameters() {
263263
for var in DEB RPM DOCKER APPIMAGE; do
264264
local value="${!var}"
265265
if [ "$value" != "0" ] && [ "$value" != "1" ]; then
266-
log_fail "Error: Parameter $var must be 0 or 1" >&2
266+
echo_error "Error: Parameter $var must be 0 or 1" >&2
267267
exit 1
268268
fi
269269
done
@@ -274,23 +274,23 @@ validate_parameters() {
274274
;;
275275
ubuntu*|debian*|kali*|*kylin*|*deepin*)
276276
if [ $RPM -eq 1 ]; then
277-
log_fail "Error: Not recommended build rpm package in $DOCKER_IMAGE"
277+
echo_error "Error: Not recommended build rpm package in $DOCKER_IMAGE"
278278
exit 1
279279
fi
280280
;;
281281
fedora*|rhel*|centos*|almalinux*|rocky*)
282282
if [ $DEB -eq 1 ]; then
283-
log_fail "Error: Not recommended build deb package in $DOCKER_IMAGE"
283+
echo_error "Error: Not recommended build deb package in $DOCKER_IMAGE"
284284
exit 1
285285
fi
286286
;;
287287
*)
288288
if [ $RPM -eq 1 ]; then
289-
log_fail "Error: Not recommended build rpm package in $DOCKER_IMAGE"
289+
echo_error "Error: Not recommended build rpm package in $DOCKER_IMAGE"
290290
exit 1
291291
fi
292292
if [ $DEB -eq 1 ]; then
293-
log_fail "Error: Not recommended build deb package in $DOCKER_IMAGE"
293+
echo_error "Error: Not recommended build deb package in $DOCKER_IMAGE"
294294
exit 1
295295
fi
296296
;;
@@ -343,7 +343,7 @@ if [ $DOCKER -eq 1 ]; then
343343
ARCH=`dpkg --print-architecture`
344344
echo "The host arch: $ARCH"
345345
if [ -z "$DOCKER_IMAGE" ]; then
346-
log_fail "DOCKER_IMAGE is empty. please set --docker-image"
346+
echo_error "DOCKER_IMAGE is empty. please set --docker-image"
347347
exit 1
348348
fi
349349
## Copy the source code to build directory

Script/build_macos.sh

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,8 @@ if [ -z "$BUILD_VERBOSE" ]; then
1111
fi
1212

1313
source $(dirname $(readlink -f $0))/common.sh
14-
1514
detect_os_info
16-
15+
check_echo_color_with_tput
1716
setup_macos
1817

1918
usage_long() {
@@ -41,7 +40,7 @@ if command -V getopt >/dev/null; then
4140
OPTS=help,verbose::,install:,source:,tools:,build:
4241
ARGS=`getopt -o h,v:: -l $OPTS -n $(basename $0) -- "$@"`
4342
if [ $? != 0 ]; then
44-
echo "exec getopt fail: $?"
43+
echo_error "exec getopt fail: $?"
4544
exit 1
4645
fi
4746
#echo "ARGS=[$ARGS]"

Script/build_rpm_package.sh

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ fi
1212

1313
source $(dirname $(readlink -f $0))/common.sh
1414
detect_os_info
15+
check_echo_color_with_tput
1516

1617
usage_long() {
1718
echo "$0 [-h|--help] [-v|--verbose[=0|1]] [--install=<install directory>]"
@@ -28,7 +29,7 @@ usage_long() {
2829
# [如何使用getopt和getopts命令解析命令行选项和参数](https://zhuanlan.zhihu.com/p/673908518)
2930
# [【Linux】Shell命令 getopts/getopt用法详解](https://blog.csdn.net/arpospf/article/details/103381621)
3031
if command -V getopt >/dev/null; then
31-
echo "getopt is exits"
32+
echo_error "getopt is exits"
3233
#echo "original parameters=[$@]"
3334
# -o 或 --options 选项后面是可接受的短选项,如 ab:c:: ,表示可接受的短选项为 -a -b -c ,
3435
# 其中 -a 选项不接参数,-b 选项后必须接参数,-c 选项的参数为可选的

Script/common.sh

Lines changed: 27 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -127,18 +127,21 @@ log_error() {
127127
echo -e "${RED}[X]${NC} $(date '+%Y-%m-%d %H:%M:%S') - $1" >&2
128128
}
129129
log_success() {
130+
echo -e "${GREEN}[✓]${NC} $(date '+%Y-%m-%d %H:%M:%S') - $1"
131+
}
132+
echo_success() {
130133
echo -e "${GREEN}[✓]${NC} $1"
131134
}
132-
log_fail() {
135+
echo_error() {
133136
echo -e "${RED}[X]${NC} $1" >&2
134137
}
135-
echo_success() {
138+
echo_color_success() {
136139
echo -e "${GREEN} $1 ${NC}"
137140
}
138-
echo_warn() {
141+
echo_color_warn() {
139142
echo -e "${YELLOW} $1 ${NC}"
140143
}
141-
echo_error() {
144+
echo_color_error() {
142145
echo -e "${RED} $1 ${NC}" >&2
143146
}
144147

@@ -149,7 +152,7 @@ validate_directory() {
149152

150153
if [ -n "$dir" ]; then
151154
if [[ "$dir" =~ ^- ]]; then
152-
log_fail "Error: $type directory parameter '$dir' cannot start with '-'"
155+
echo_error "Error: $type directory parameter '$dir' cannot start with '-'"
153156
exit 1
154157
fi
155158
fi
@@ -304,7 +307,7 @@ create_debian_folder() {
304307
echo "ln -s $control_source $repo_root/debian/control"
305308
fi
306309
else
307-
log_fail "Error: $control_source is not exist"
310+
echo_error "Error: $control_source is not exist"
308311
fi
309312
fi
310313

@@ -329,7 +332,7 @@ install_debian_depend() {
329332
# grep -v '^$' | \
330333
# xargs sudo apt install -y
331334
else
332-
log_fail "Error: $repo_root/debian/control is not exist"
335+
echo_error "Error: $repo_root/debian/control is not exist"
333336
fi
334337
}
335338

@@ -504,7 +507,7 @@ version_compare() {
504507
# Function to check if git is installed
505508
check_git() {
506509
if ! command -v git >/dev/null 2>&1; then
507-
echo_error "X Git is not installed" >&2
510+
echo_color_error "X Git is not installed" >&2
508511
echo " Git is required for this script to work." >&2
509512
echo "" >&2
510513
echo " Please install Git using one of the following commands:" >&2
@@ -537,10 +540,10 @@ check_git() {
537540
local git_version=$(git --version | cut -d' ' -f3)
538541

539542
if ! version_compare "$git_version" "$min_version"; then
540-
echo_warn "!️ Git version $git_version is installed, but version $min_version or higher is recommended" >&2
543+
echo_color_warn "!️ Git version $git_version is installed, but version $min_version or higher is recommended" >&2
541544
# Continue anyway, just a warning
542545
else
543-
echo_success "√ Git $git_version is installed"
546+
echo_color_success "√ Git $git_version is installed"
544547
fi
545548
fi
546549

@@ -550,7 +553,7 @@ check_git() {
550553
# Option to automatically install git (with user confirmation)
551554
install_git_if_missing() {
552555
if ! command -v git >/dev/null 2>&1; then
553-
echo_warn "!️ Git is required but not installed." >&2
556+
echo_color_warn "!️ Git is required but not installed." >&2
554557
read -p "Would you like to install Git now? (y/n): " -n 1 -r
555558
echo
556559
if [[ $REPLY =~ ^[Yy]$ ]]; then
@@ -567,23 +570,23 @@ install_git_if_missing() {
567570
if command -v brew >/dev/null 2>&1; then
568571
brew install git
569572
else
570-
echo_error "X Homebrew not found. Please install Git manually from https://git-scm.com/download/mac" >&2
573+
echo_color_error "X Homebrew not found. Please install Git manually from https://git-scm.com/download/mac" >&2
571574
return 1
572575
fi
573576
else
574-
echo_error "X Unsupported OS. Please install Git manually." >&2
577+
echo_color_error "X Unsupported OS. Please install Git manually." >&2
575578
return 1
576579
fi
577580

578581
# Verify installation
579582
if command -v git >/dev/null 2>&1; then
580-
echo_success "√ Git installed successfully!"
583+
echo_color_success "√ Git installed successfully!"
581584
else
582-
echo_error "X Git installation failed. Please install manually." >&2
585+
echo_color_error "X Git installation failed. Please install manually." >&2
583586
return 1
584587
fi
585588
else
586-
echo_error "X Git is required. Exiting." >&2
589+
echo_color_error "X Git is required. Exiting." >&2
587590
return 1
588591
fi
589592
fi
@@ -606,17 +609,17 @@ test_sed_pattern() {
606609

607610
# Test with -E flag
608611
if echo "$test_string" | sed -E "s/${VERSION_PATTERN}/REPLACED/g" | grep -q "REPLACED"; then
609-
echo_success " √ -E flag: Matches"
612+
echo_color_success " √ -E flag: Matches"
610613
else
611-
echo_error " X -E flag: No match"
614+
echo_color_error " X -E flag: No match"
612615
fi
613616

614617
# Convert to BRE and test
615618
BRE_PATTERN=$(sed_safe_pattern "$VERSION_PATTERN")
616619
if echo "$test_string" | sed "s/${BRE_PATTERN}/REPLACED/g" | grep -q "REPLACED"; then
617-
echo_success " √ BRE: Matches"
620+
echo_color_success " √ BRE: Matches"
618621
else
619-
echo_error " X BRE: No match"
622+
echo_color_error " X BRE: No match"
620623
fi
621624
}
622625

@@ -665,7 +668,7 @@ version_parser() {
665668
return 0
666669
fi
667670

668-
log_fail "ERROR: Unable to parse version number '$version'" >&2
671+
echo_error "ERROR: Unable to parse version number '$version'" >&2
669672
return 1
670673
}
671674

@@ -686,7 +689,7 @@ display_version_info() {
686689
是否包含构建: ${data[7]}
687690
EOF
688691
else
689-
log_fail "数据不完整"
692+
echo_error "数据不完整"
690693
fi
691694
}
692695

@@ -711,7 +714,7 @@ parse_version_assoc() {
711714
version_array[build]="${BASH_REMATCH[10]:-}"
712715
return 0
713716
else
714-
log_fail "ERROR: Unable to parse version number '$version'" >&2
717+
echo_error "ERROR: Unable to parse version number '$version'" >&2
715718
return 1
716719
fi
717720
}
@@ -781,7 +784,7 @@ compare_versions() {
781784

782785
# 检查数组元素个数
783786
if [ ${#parts1[@]} -lt 3 ] || [ ${#parts2[@]} -lt 3 ]; then
784-
log_fail "version format error" >&2
787+
echo_error "version format error" >&2
785788
return 3
786789
fi
787790

0 commit comments

Comments
 (0)