优化代码

This commit is contained in:
Hyy2001X 2021-06-17 17:55:08 +08:00
parent 990d01c510
commit a735dc95dd
1 changed files with 54 additions and 75 deletions

View File

@ -5,21 +5,17 @@
GET_INFO() {
Diy_Core
Home="${GITHUB_WORKSPACE}/openwrt"
[ -f "${GITHUB_WORKSPACE}/Openwrt.info" ] && source ${GITHUB_WORKSPACE}/Openwrt.info
[[ "${Short_Firmware_Date}" == true ]] && Compile_Date="$(echo ${Compile_Date} | cut -c1-8)"
[[ -f ${GITHUB_WORKSPACE}/Openwrt.info ]] && source ${GITHUB_WORKSPACE}/Openwrt.info
[[ ${Short_Firmware_Date} == true ]] && Compile_Date="$(echo ${Compile_Date} | cut -c1-8)"
User_Repo="$(grep "https://github.com/[a-zA-Z0-9]" ${GITHUB_WORKSPACE}/.git/config | cut -c8-100 | sed 's/^[ \t]*//g')"
[[ -z "${Author}" ]] && {
Author="$(echo "${User_Repo}" | cut -d "/" -f4)"
}
[[ -z ${Author} ]] && Author="$(echo "${User_Repo}" | cut -d "/" -f4)"
Openwrt_Author="$(echo "${Openwrt_Repo}" | cut -d "/" -f4)"
Openwrt_Repo_Name="$(echo "${Openwrt_Repo}" | cut -d "/" -f5)"
Openwrt_Branch="$(GET_BRANCH)"
[[ ! ${Openwrt_Branch} == master ]] && {
Openwrt_Branch="$(echo ${Openwrt_Branch} | egrep -o "[0-9]+.[0-9]+")"
Openwrt_Version_="R${Openwrt_Branch}-"
} || {
Openwrt_Version_="R$(date +%y.%m)-"
}
} || Openwrt_Version_="R$(date +%y.%m)-"
case "${Openwrt_Author}" in
coolsnowwolf)
Version_File=package/lean/default-settings/files/zzz-default-settings
@ -34,26 +30,21 @@ GET_INFO() {
CURRENT_Version="${Openwrt_Version_}${Compile_Date}"
;;
esac
while [[ -z "${x86_Test}" ]]
do
while [[ -z ${x86_Test} ]];do
x86_Test="$(egrep -o "CONFIG_TARGET.*DEVICE.*=y" .config | sed -r 's/CONFIG_TARGET_(.*)_DEVICE_(.*)=y/\1/')"
[[ -n "${x86_Test}" ]] && break
[[ -n ${x86_Test} ]] && break
x86_Test="$(egrep -o "CONFIG_TARGET.*Generic=y" .config | sed -r 's/CONFIG_TARGET_(.*)_Generic=y/\1/')"
[[ -z "${x86_Test}" ]] && TIME "[ERROR] Can not obtain the TARGET_PROFILE !" && exit 1
[[ -z ${x86_Test} ]] && TIME "[ERROR] Can not obtain the TARGET_PROFILE !" && exit 1
done
[[ "${x86_Test}" == x86_64 ]] && {
[[ ${x86_Test} == x86_64 ]] && {
TARGET_PROFILE=x86_64
} || {
TARGET_PROFILE="$(egrep -o "CONFIG_TARGET.*DEVICE.*=y" .config | sed -r 's/.*DEVICE_(.*)=y/\1/')"
}
[[ -z "${TARGET_PROFILE}" ]] && TARGET_PROFILE="${Default_Device}"
[[ -z "${Default_Device}" ]] && Default_Device="${TARGET_PROFILE}"
[[ "${TARGET_PROFILE}" == x86_64 ]] && {
[[ "$(cat ${Home}/.config)" =~ "CONFIG_TARGET_IMAGES_GZIP=y" ]] && {
Firmware_Type=img.gz
} || {
Firmware_Type=img
}
[[ -z ${TARGET_PROFILE} ]] && TARGET_PROFILE="${Default_Device}"
[[ -z ${Default_Device} ]] && Default_Device="${TARGET_PROFILE}"
[[ ${TARGET_PROFILE} == x86_64 ]] && {
[[ $(cat ${Home}/.config) =~ CONFIG_TARGET_IMAGES_GZIP=y ]] && Firmware_Type=img.gz || Firmware_Type=img
}
TARGET_BOARD="$(awk -F '[="]+' '/TARGET_BOARD/{print $2}' .config)"
case "${TARGET_BOARD}" in
@ -128,7 +119,6 @@ EOF
INCLUDE_Obsolete_PKG_Compatible=${INCLUDE_Obsolete_PKG_Compatible}
Home=${Home}
Firmware_Path=${Firmware_Path}
Firmware_Head=${Firmware_Head}
EOF
case "${TARGET_PROFILE}" in
@ -156,18 +146,17 @@ Firmware-Diy_Base() {
mkdir -p package/base-files/files/etc/AutoBuild
[ -f VARIABLE_FILE_Main ] && cp VARIABLE_FILE_Main package/base-files/files/etc/AutoBuild/Default_Variable
Replace_File CustomFiles/Depends/Custom_Variable package/base-files/files/etc/AutoBuild
Auto_AddPackage
AddPackage_List ${GITHUB_WORKSPACE}/CustomPackages/Common
AddPackage_List ${GITHUB_WORKSPACE}/CustomPackages/${TARGET_PROFILE}
chmod +x -R ${GITHUB_WORKSPACE}/Scripts
chmod 777 -R ${GITHUB_WORKSPACE}/CustomFiles
chmod 777 -R ${GITHUB_WORKSPACE}/CustomPackages
[[ "${INCLUDE_AutoBuild_Tools}" == true ]] && {
[[ ${INCLUDE_AutoBuild_Features} == true ]] && {
Replace_File Scripts/AutoBuild_Tools.sh package/base-files/files/bin
}
[[ "${INCLUDE_AutoUpdate}" == true ]] && {
AddPackage git lean luci-app-autoupdate Hyy2001X main
Replace_File Scripts/AutoUpdate.sh package/base-files/files/bin
}
[[ "${INCLUDE_Theme_Argon}" == true ]] && {
[[ ${INCLUDE_Argon} == true ]] && {
case "${Openwrt_Author}" in
coolsnowwolf)
AddPackage git lean luci-theme-argon jerrykuku 18.06
@ -189,16 +178,17 @@ Firmware-Diy_Base() {
esac
;;
esac
AddPackage git other luci-app-argon-config jerrykuku
}
New_IP_Address="${Default_IP_Address}"
if [[ -n "${Defined_IP_Address}" ]];then
[[ -n ${Defined_IP_Address} ]] && {
TIME "Using defined IP Address [${Defined_IP_Address}] ..."
New_IP_Address="${Defined_IP_Address}"
fi
[[ -n "${New_IP_Address}" ]] && [[ "${New_IP_Address}" != false ]] && {
if [[ "${New_IP_Address}" =~ ^[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}$ ]];then
}
[[ -n ${New_IP_Address} && ${New_IP_Address} != false ]] && {
if [[ ${New_IP_Address} =~ ^[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}$ ]];then
Old_IP_Address=$(awk -F '[="]+' '/ipaddr:-/{print $3}' package/base-files/files/bin/config_generate | awk 'NR==1')
if [[ ! "${New_IP_Address}" == "${Old_IP_Address}" ]];then
if [[ ! ${New_IP_Address} == ${Old_IP_Address} ]];then
TIME "Setting default IP Address to ${New_IP_Address} ..."
sed -i "s/${Old_IP_Address}/${New_IP_Address}/g" package/base-files/files/bin/config_generate
a=$(echo ${Old_IP_Address} | egrep -o "[0-9]+.[0-9]+." | awk 'NR==1')
@ -225,14 +215,14 @@ Firmware-Diy_Base() {
sed -i 's/143/143,8080/' $(PKG_Finder d package luci-app-ssr-plus)/root/etc/init.d/shadowsocksr
sed -i "s?iptables?#iptables?g" ${Version_File}
sed -i "s?${Old_Version}?${Old_Version} @ ${Author} [${Display_Date}]?g" ${Version_File}
# [[ "${INCLUDE_DRM_I915}" == true ]] && Replace_File CustomFiles/Depends/i915-5.4 target/linux/x86 config-5.4
# [[ ${INCLUDE_DRM_I915} == true ]] && Replace_File CustomFiles/Depends/i915-5.4 target/linux/x86 config-5.4
;;
immortalwrt)
Replace_File CustomFiles/Depends/coremark_ImmortalWrt.sh package/base-files/files/etc coremark.sh
Replace_File CustomFiles/Depends/ImmortalWrt package/base-files/files/etc openwrt_release
Replace_File CustomFiles/Depends/cpuinfo_x86 package/lean/autocore/files/x86/sbin cpuinfo
sed -i "s?Template?Compiled by ${Author} [${Display_Date}]?g" ${Version_File}
# [[ "${INCLUDE_DRM_I915}" == true ]] && Replace_File CustomFiles/Depends/i915-4.19 target/linux/x86 config-4.19
# [[ ${INCLUDE_DRM_I915} == true ]] && Replace_File CustomFiles/Depends/i915-4.19 target/linux/x86 config-4.19
;;
esac
case "${Openwrt_Author}" in
@ -264,9 +254,9 @@ Other_Scripts() {
INCLUDE_Obsolete_PKG_Compatible=true
;;
esac
if [[ "${INCLUDE_Obsolete_PKG_Compatible}" == true ]];then
if [[ ${INCLUDE_Obsolete_PKG_Compatible} == true ]];then
TIME "Start to run Obsolete_Package_Compatible Scripts ..."
if [[ ${Openwrt_Author} == openwrt ]] || [[ "${Force_mode}" == 1 ]];then
if [[ ${Openwrt_Author} == openwrt || ${Force_mode} == 1 ]];then
case "${Openwrt_Branch}" in
19.07 | 21.02)
Replace_File CustomFiles/Patches/0003-upx-ucl-${Openwrt_Branch}.patch ./
@ -284,35 +274,34 @@ Other_Scripts() {
TIME "Current source: [${Openwrt_Author}] is not supported,skip..."
fi
fi
if [ -s $GITHUB_WORKSPACE/Configs/Common ];then
[[ -s $GITHUB_WORKSPACE/Configs/Common ]] && {
TIME "Merging Common_Config to .config ..."
echo -e "\n$(cat $GITHUB_WORKSPACE/Configs/Common)" >> .config
fi
}
}
PS_Firmware() {
source ./VARIABLE_FILE_Sec
rm -rf ${Firmware_Path}/packages
mkdir -p bin/Firmware
cd ${Firmware_Path}
case "${TARGET_PROFILE}" in
x86_64)
if [ -f "${Default_Legacy_Firmware}" ];then
[[ -f ${Default_Legacy_Firmware} ]] && {
cp ${Default_Legacy_Firmware} $(EVAL_FW x86_64 Legacy ${Home}/VARIABLE_FILE_Sec)
TIME "Legacy Firmware: [${Default_Legacy_Firmware}] is detected !"
fi
if [ -f "${Default_UEFI_Firmware}" ];then
}
[[ -f ${Default_UEFI_Firmware} ]] && {
cp ${Default_UEFI_Firmware} $(EVAL_FW x86_64 UEFI ${Home}/VARIABLE_FILE_Sec)
TIME "UEFI Firmware: [${Default_UEFI_Firmware}] is detected !"
fi
}
;;
*)
if [ -f "${Default_Firmware}" ];then
[[ -f ${Default_Firmware} ]] && {
cp ${Default_Firmware} $(EVAL_FW common ${Home}/VARIABLE_FILE_Sec)
TIME "Firmware: [${Default_Firmware}] is detected !"
else
} || {
TIME "[ERROR] Firmware is not detected !"
fi
}
;;
esac
mv -f AutoBuild-* ${Home}/bin/Firmware
@ -324,11 +313,11 @@ EVAL_FW() {
case "$1" in
x86_64)
x86_64_Boot=$2
SHA5BIT=$(GET_SHA5BIT $(GET_VARIABLE Default_$2_Firmware= $3))
SHA5BIT=$(GET_SHA5BIT $(GET_VARIABLE Default_$2_Firmware= $3) 5)
EVAL_VARIABLE $(GET_VARIABLE AutoBuild_Firmware= $3)
;;
common)
SHA5BIT=$(GET_SHA5BIT $(GET_VARIABLE Default_Firmware= $2))
SHA5BIT=$(GET_SHA5BIT $(GET_VARIABLE Default_Firmware= $2) 5)
EVAL_VARIABLE $(GET_VARIABLE AutoBuild_Firmware= $2)
;;
esac
@ -336,16 +325,16 @@ EVAL_FW() {
EVAL_VARIABLE() {
eval OUTPUT=$1
echo -e "${OUTPUT}"
echo "${OUTPUT}"
}
GET_SHA5BIT() {
grep "$1" sha256sums | cut -c1-5
grep "$1" sha256sums | cut -c1-$2
}
GET_BRANCH() {
Folder="$(pwd)"
[ -n "$1" ] && Folder="$1"
[[ -n $1 ]] && Folder="$1"
git -C "${Folder}" rev-parse --abbrev-ref HEAD | grep -v HEAD || \
git -C "${Folder}" describe --exact-match HEAD || \
git -C "${Folder}" rev-parse HEAD
@ -356,7 +345,7 @@ GET_VARIABLE() {
}
TIME() {
echo "[$(date "+%H:%M:%S")] ${*}"
echo "[$(date "+%H:%M:%S")] $*"
}
PKG_Finder() {
@ -367,22 +356,17 @@ PKG_Finder() {
find $2 -name $3 -type $1 -depth -exec echo {} \;
}
Auto_AddPackage() {
Auto_AddPackage_mod ${GITHUB_WORKSPACE}/CustomPackages/Common
Auto_AddPackage_mod ${GITHUB_WORKSPACE}/CustomPackages/${TARGET_PROFILE}
}
Auto_AddPackage_mod() {
AddPackage_List() {
[[ $# != 1 ]] && {
TIME "[ERROR] Error options: [$#] [$*] !"
return 0
}
echo "" >> $1
[ -s "$1" ] && {
[[ -s $1 ]] && {
TIME "Loading Custom Packages list: [$1]..."
cat $1 | sed '/^$/d' | while read X
do
[[ -n "${X}" ]] && AddPackage ${X}
[[ -n ${X} && ! $* =~ "#" ]] && AddPackage ${X}
done
}
}
@ -392,14 +376,15 @@ AddPackage() {
TIME "[ERROR] Error options: [$#] [$*] !"
return 0
}
[[ $* =~ "#" ]] && return 0
PKG_PROTO="$1"
PKG_DIR="$2"
PKG_NAME="$3"
REPO_URL="https://github.com/${4}"
[[ -z "$5" ]] && REPO_BRANCH=master || REPO_BRANCH="$5"
REPO_URL="https://github.com/$4"
[[ -z $5 ]] && REPO_BRANCH=master || REPO_BRANCH="$5"
mkdir -p package/${PKG_DIR}
[ -d "package/${PKG_DIR}/${PKG_NAME}" ] && {
[[ -d package/${PKG_DIR}/${PKG_NAME} ]] && {
TIME "Removing old package: [${PKG_NAME}] ..."
rm -rf package/${PKG_DIR}/${PKG_NAME}
}
@ -414,12 +399,9 @@ AddPackage() {
svn checkout ${REPO_URL}/${PKG_NAME} ${PKG_NAME} > /dev/null 2>&1
;;
esac
[ -f ${PKG_NAME}/Makefile ] || [ -f ${PKG_NAME}/README* ] || [[ -n "$(ls -A ${PKG_NAME})" ]] && {
[[ -f ${PKG_NAME}/Makefile || -f ${PKG_NAME}/README* || -n $(ls -A ${PKG_NAME}) ]] && {
mv -f "${PKG_NAME}" "package/${PKG_DIR}"
} || {
TIME "[ERROR] Package [${PKG_NAME}] is not detected!"
}
unset PKG_PROTO PKG_DIR PKG_NAME REPO_URL REPO_BRANCH
} || TIME "[ERROR] Package [${PKG_NAME}] is not detected!"
}
Replace_File() {
@ -432,16 +414,13 @@ Replace_File() {
FILE_RENAME=$3
mkdir -p ${PATCH_DIR}
[ -f "${GITHUB_WORKSPACE}/${FILE_NAME}" ] && _TYPE1="f" && _TYPE2="File"
[ -d "${GITHUB_WORKSPACE}/${FILE_NAME}" ] && _TYPE1="d" && _TYPE2="Folder"
[[ -f ${GITHUB_WORKSPACE}/${FILE_NAME} ]] && _TYPE1=f && _TYPE2=File
[[ -d ${GITHUB_WORKSPACE}/${FILE_NAME} ]] && _TYPE1=d && _TYPE2=Folder
[ -${_TYPE1} "${GITHUB_WORKSPACE}/${FILE_NAME}" ] && {
[[ -n "${FILE_RENAME}" ]] && _RENAME="${FILE_RENAME}" || _RENAME=""
[[ -n ${FILE_RENAME} ]] && _RENAME="${FILE_RENAME}" || _RENAME=""
[ -${_TYPE1} "${GITHUB_WORKSPACE}/${FILE_NAME}" ] && {
TIME "Moving [${_TYPE2}] ${FILE_NAME} to $2/${FILE_RENAME} ..."
mv -f "${GITHUB_WORKSPACE}/${FILE_NAME}" "${PATCH_DIR}/${_RENAME}"
} || {
TIME "CustomFiles ${_TYPE2} [${FILE_NAME}] is not detected !"
} || TIME "CustomFiles ${_TYPE2} [${FILE_NAME}] is not detected !"
}
}
unset FILE_NAME PATCH_DIR FILE_RENAME
}