Skip to content

Commit 06a3dfd

Browse files
committed
refactor(diy-part2.sh): improve xray-core Makefile handling
- Rename variables for better readability - Add version comparison before copying Makefile - Update log messages for clarity - Simplify conditional statements
1 parent 51718ac commit 06a3dfd

File tree

1 file changed

+11
-13
lines changed

1 file changed

+11
-13
lines changed

diy-part2.sh

+11-13
Original file line numberDiff line numberDiff line change
@@ -93,23 +93,21 @@ else
9393
echo "[ERROR] Failed to replace luci-theme-argon."
9494
fi
9595

96-
# 8. Copy xray-core Makefile from helloworld to packages
97-
SOURCE_MAKEFILE="feeds/helloworld/xray-core/Makefile"
98-
TARGET_MAKEFILE="feeds/packages/net/xray-core/Makefile"
96+
# 8. Compare xray-core Makefile versions and copy the higher version
97+
SRC_MAKEFILE="feeds/helloworld/xray-core/Makefile"
98+
DST_MAKEFILE="feeds/packages/net/xray-core/Makefile"
9999

100-
if [ -f "$SOURCE_MAKEFILE" ]; then
101-
if [ -f "$TARGET_MAKEFILE" ]; then
102-
cp "$SOURCE_MAKEFILE" "$TARGET_MAKEFILE"
103-
if [ $? -eq 0 ]; then
104-
echo "[SUCCESS] Copied $SOURCE_MAKEFILE to $TARGET_MAKEFILE."
105-
else
106-
echo "[ERROR] Failed to copy $SOURCE_MAKEFILE to $TARGET_MAKEFILE."
107-
fi
100+
if [ -f "$SRC_MAKEFILE" ] && [ -f "$DST_MAKEFILE" ]; then
101+
SRC_VERSION=$(grep -Po 'PKG_VERSION:=\K[0-9.]*' "$SRC_MAKEFILE")
102+
DST_VERSION=$(grep -Po 'PKG_VERSION:=\K[0-9.]*' "$DST_MAKEFILE")
103+
if [ "$(printf '%s\n%s' "$SRC_VERSION" "$DST_VERSION" | sort -V | tail -n1)" == "$SRC_VERSION" ]; then
104+
cp "$SRC_MAKEFILE" "$DST_MAKEFILE"
105+
echo "[INFO] Copied higher version of xray-core Makefile from $SRC_MAKEFILE to $DST_MAKEFILE."
108106
else
109-
echo "[WARNING] Target file not found: $TARGET_MAKEFILE."
107+
echo "[INFO] Destination Makefile version is higher or the same. No copy needed."
110108
fi
111109
else
112-
echo "[WARNING] Source file not found: $SOURCE_MAKEFILE."
110+
echo "[WARNING] Makefile not found: Source ($SRC_MAKEFILE) or Destination ($DST_MAKEFILE)."
113111
fi
114112

115113
echo "[INFO] Script execution completed."

0 commit comments

Comments
 (0)