X-OpenWrt/Scripts/AutoBuild_Function.sh

438 lines
15 KiB
Bash
Raw Normal View History

2021-01-05 23:38:00 +00:00
#!/bin/bash
2021-06-06 05:55:56 +00:00
# AutoBuild Module by Hyy2001 <https://github.com/Hyy2001X/AutoBuild-Actions>
2021-01-05 23:38:00 +00:00
# AutoBuild Functions
2021-06-06 05:55:56 +00:00
GET_INFO() {
Diy_Core
2021-04-16 10:57:19 +00:00
Home="${GITHUB_WORKSPACE}/openwrt"
2021-06-17 09:55:08 +00:00
[[ -f ${GITHUB_WORKSPACE}/Openwrt.info ]] && source ${GITHUB_WORKSPACE}/Openwrt.info
[[ ${Short_Firmware_Date} == true ]] && Compile_Date="$(echo ${Compile_Date} | cut -c1-8)"
2021-05-12 13:15:10 +00:00
User_Repo="$(grep "https://github.com/[a-zA-Z0-9]" ${GITHUB_WORKSPACE}/.git/config | cut -c8-100 | sed 's/^[ \t]*//g')"
2021-06-17 09:55:08 +00:00
[[ -z ${Author} ]] && Author="$(echo "${User_Repo}" | cut -d "/" -f4)"
2021-07-02 15:51:31 +00:00
Openwrt_Maintainer="$(echo "${Openwrt_Repo}" | cut -d "/" -f4)"
2021-06-06 05:55:56 +00:00
Openwrt_Repo_Name="$(echo "${Openwrt_Repo}" | cut -d "/" -f5)"
Openwrt_Branch="$(GET_BRANCH)"
2021-07-02 15:51:31 +00:00
if [[ ${Openwrt_Branch} == master || ${Openwrt_Branch} == main ]];then
Openwrt_Version_Head="R$(date +%y.%m)-"
else
2021-06-06 05:55:56 +00:00
Openwrt_Branch="$(echo ${Openwrt_Branch} | egrep -o "[0-9]+.[0-9]+")"
2021-07-02 15:51:31 +00:00
Openwrt_Version_Head="R${Openwrt_Branch}-"
fi
2021-07-02 15:51:31 +00:00
case "${Openwrt_Maintainer}" in
coolsnowwolf)
2021-04-16 10:57:19 +00:00
Version_File=package/lean/default-settings/files/zzz-default-settings
2021-07-02 15:51:31 +00:00
zzz_Default_Version="$(egrep -o "R[0-9]+\.[0-9]+\.[0-9]+" ${Version_File})"
CURRENT_Version="${zzz_Default_Version}-${Compile_Date}"
;;
immortalwrt)
2021-04-16 10:57:19 +00:00
Version_File=package/base-files/files/etc/openwrt_release
2021-07-02 15:51:31 +00:00
CURRENT_Version="${Openwrt_Version_Head}${Compile_Date}"
;;
*)
2021-07-02 15:51:31 +00:00
CURRENT_Version="${Openwrt_Version_Head}${Compile_Date}"
;;
esac
2021-06-17 09:55:08 +00:00
while [[ -z ${x86_Test} ]];do
x86_Test="$(egrep -o "CONFIG_TARGET.*DEVICE.*=y" .config | sed -r 's/CONFIG_TARGET_(.*)_DEVICE_(.*)=y/\1/')"
2021-06-17 09:55:08 +00:00
[[ -n ${x86_Test} ]] && break
x86_Test="$(egrep -o "CONFIG_TARGET.*Generic=y" .config | sed -r 's/CONFIG_TARGET_(.*)_Generic=y/\1/')"
[[ -z ${x86_Test} ]] && break
done
2021-06-17 09:55:08 +00:00
[[ ${x86_Test} == x86_64 ]] && {
2021-06-06 05:55:56 +00:00
TARGET_PROFILE=x86_64
2021-04-16 10:57:19 +00:00
} || {
2021-02-19 08:17:31 +00:00
TARGET_PROFILE="$(egrep -o "CONFIG_TARGET.*DEVICE.*=y" .config | sed -r 's/.*DEVICE_(.*)=y/\1/')"
2021-04-16 10:57:19 +00:00
}
[[ -z ${TARGET_PROFILE} ]] && {
if [[ -n ${Default_TARGET_PROFILE} && ${Default_TARGET_PROFILE} != auto ]];then
TARGET_PROFILE="${Default_TARGET_PROFILE}"
else
2021-07-02 15:28:23 +00:00
TIME "[ERROR] Can not get TARGET_PROFILE,please check!"
exit 1
fi
}
2021-06-17 09:55:08 +00:00
[[ ${TARGET_PROFILE} == x86_64 ]] && {
[[ $(cat ${Home}/.config) =~ CONFIG_TARGET_IMAGES_GZIP=y ]] && Firmware_Type=img.gz || Firmware_Type=img
2021-04-16 17:38:13 +00:00
}
TARGET_BOARD="$(awk -F '[="]+' '/TARGET_BOARD/{print $2}' .config)"
2021-06-06 05:55:56 +00:00
case "${TARGET_BOARD}" in
2021-04-16 17:38:13 +00:00
ramips | reltek | ipq40xx | ath79)
2021-04-16 10:57:19 +00:00
Firmware_Type=bin
2021-02-19 08:17:31 +00:00
;;
2021-04-16 17:38:13 +00:00
rockchip)
Firmware_Type=img.gz
;;
2021-02-19 08:17:31 +00:00
esac
TARGET_SUBTARGET="$(awk -F '[="]+' '/TARGET_SUBTARGET/{print $2}' .config)"
2021-07-02 15:51:31 +00:00
case "${Openwrt_Maintainer}" in
2021-06-06 05:55:56 +00:00
immortalwrt)
Firmware_Head=immortalwrt
;;
*)
Firmware_Head=openwrt
;;
esac
case "${Openwrt_Branch}" in
19.07 | 18.06)
2021-07-02 15:51:31 +00:00
case "${Openwrt_Maintainer}" in
2021-06-06 05:55:56 +00:00
immortalwrt)
Legacy_Tail=combined-squashfs
UEFI_Tail=uefi-gpt-squashfs
;;
*)
Legacy_Tail=combined-squashfs
UEFI_Tail=combined-squashfs-efi
;;
esac
;;
*)
Legacy_Tail=generic-squashfs-combined
UEFI_Tail=generic-squashfs-combined-efi
;;
esac
2021-06-06 05:55:56 +00:00
case "${TARGET_PROFILE}" in
x86_64)
Default_Legacy_Firmware="${Firmware_Head}-${TARGET_BOARD}-${TARGET_SUBTARGET}-${Legacy_Tail}.${Firmware_Type}"
Default_UEFI_Firmware="${Firmware_Head}-${TARGET_BOARD}-${TARGET_SUBTARGET}-${UEFI_Tail}.${Firmware_Type}"
AutoBuild_Firmware='AutoBuild-${Openwrt_Repo_Name}-${TARGET_PROFILE}-${CURRENT_Version}-${x86_64_Boot}-${SHA5BIT}.${Firmware_Type}'
2021-07-01 09:14:44 +00:00
Egrep_Firmware='AutoBuild-${Openwrt_Repo_Name}-${TARGET_PROFILE}-R[0-9.]+-[0-9]+-${x86_64_Boot}.[0-9a-z]+.${Firmware_Type}'
2021-06-06 05:55:56 +00:00
;;
*)
case "${TARGET_SUBTARGET}" in
generic)
Default_Firmware="${Firmware_Head}-${TARGET_BOARD}-${TARGET_PROFILE}-squashfs-sysupgrade.${Firmware_Type}"
;;
*)
Default_Firmware="${Firmware_Head}-${TARGET_BOARD}-${TARGET_SUBTARGET}-${TARGET_PROFILE}-squashfs-sysupgrade.${Firmware_Type}"
;;
esac
2021-06-06 05:55:56 +00:00
AutoBuild_Firmware='AutoBuild-${Openwrt_Repo_Name}-${TARGET_PROFILE}-${CURRENT_Version}-${SHA5BIT}.${Firmware_Type}'
2021-07-01 09:14:44 +00:00
Egrep_Firmware='AutoBuild-${Openwrt_Repo_Name}-${TARGET_PROFILE}-R[0-9.]+-[0-9]+-[0-9a-z]+.${Firmware_Type}'
2021-06-06 05:55:56 +00:00
;;
esac
Firmware_Path="bin/targets/${TARGET_BOARD}/${TARGET_SUBTARGET}"
cat >> VARIABLE_FILE_Main <<EOF
Author=${Author}
Github=${User_Repo}
TARGET_PROFILE=${TARGET_PROFILE}
TARGET_BOARD=${TARGET_BOARD}
TARGET_SUBTARGET=${TARGET_SUBTARGET}
Firmware_Type=${Firmware_Type}
CURRENT_Version=${CURRENT_Version}
2021-07-02 15:51:31 +00:00
Openwrt_Maintainer=${Openwrt_Maintainer}
2021-06-06 05:55:56 +00:00
Openwrt_Branch=${Openwrt_Branch}
AutoBuild_Firmware=${AutoBuild_Firmware}
Openwrt_Repo_Name=${Openwrt_Repo_Name}
Egrep_Firmware=${Egrep_Firmware}
EOF
cat >> VARIABLE_FILE_Sec <<EOF
INCLUDE_Obsolete_PKG_Compatible=${INCLUDE_Obsolete_PKG_Compatible}
Home=${Home}
Firmware_Path=${Firmware_Path}
EOF
2021-06-06 05:55:56 +00:00
case "${TARGET_PROFILE}" in
x86_64)
cat >> VARIABLE_FILE_Sec <<EOF
Default_Legacy_Firmware=${Default_Legacy_Firmware}
Default_UEFI_Firmware=${Default_UEFI_Firmware}
Legacy_Tail=${Legacy_Tail}
UEFI_Tail=${UEFI_Tail}
EOF
;;
*)
cat >> VARIABLE_FILE_Sec <<EOF
Default_Firmware=${Default_Firmware}
EOF
;;
esac
echo "$(cat VARIABLE_FILE_Main)" >> VARIABLE_FILE_Sec
echo -e "### Variable list ###\n$(cat VARIABLE_FILE_Sec)\n"
TIME "[Load variable info] All done !"
2021-01-11 13:44:45 +00:00
}
Firmware-Diy_Base() {
2021-06-06 05:55:56 +00:00
GET_INFO
mkdir -p package/base-files/files/etc/AutoBuild
[ -f VARIABLE_FILE_Main ] && cp VARIABLE_FILE_Main package/base-files/files/etc/AutoBuild/Default_Variable
2021-06-18 02:08:35 +00:00
Copy CustomFiles/Depends/Custom_Variable package/base-files/files/etc/AutoBuild
2021-06-24 16:08:51 +00:00
[[ ! "$(cat ${GITHUB_WORKSPACE}/Configs/${TARGET_PROFILE})" =~ "## DO NOT MERGE" ]] && AddPackage_List ${GITHUB_WORKSPACE}/CustomPackages/Common
2021-06-17 09:55:08 +00:00
AddPackage_List ${GITHUB_WORKSPACE}/CustomPackages/${TARGET_PROFILE}
2021-03-27 16:43:55 +00:00
chmod +x -R ${GITHUB_WORKSPACE}/Scripts
2021-06-06 05:55:56 +00:00
chmod 777 -R ${GITHUB_WORKSPACE}/CustomFiles
chmod 777 -R ${GITHUB_WORKSPACE}/CustomPackages
2021-06-17 09:55:08 +00:00
[[ ${INCLUDE_AutoBuild_Features} == true ]] && {
2021-06-18 02:08:35 +00:00
Copy Scripts/AutoBuild_Tools.sh package/base-files/files/bin
2021-05-18 02:10:29 +00:00
AddPackage git lean luci-app-autoupdate Hyy2001X main
2021-06-18 02:08:35 +00:00
Copy Scripts/AutoUpdate.sh package/base-files/files/bin
2021-04-16 10:57:19 +00:00
}
2021-06-17 09:55:08 +00:00
[[ ${INCLUDE_Argon} == true ]] && {
2021-07-02 15:51:31 +00:00
case "${Openwrt_Maintainer}" in
2021-04-09 15:12:34 +00:00
coolsnowwolf)
2021-05-18 02:10:29 +00:00
AddPackage git lean luci-theme-argon jerrykuku 18.06
2021-04-09 15:12:34 +00:00
;;
*)
2021-06-06 05:55:56 +00:00
case "${Openwrt_Branch}" in
2021-04-09 15:12:34 +00:00
19.07)
2021-05-18 02:10:29 +00:00
AddPackage git other luci-theme-argon jerrykuku v2.2.5
2021-04-09 15:12:34 +00:00
;;
21.02)
AddPackage git other luci-theme-argon jerrykuku master
2021-04-09 15:12:34 +00:00
;;
18.06)
2021-05-18 02:10:29 +00:00
AddPackage git other luci-theme-argon jerrykuku 18.06
2021-04-09 15:12:34 +00:00
;;
*)
2021-06-06 05:55:56 +00:00
TIME "[ERROR] Unknown Openwrt branch: [${Openwrt_Branch}] !"
2021-04-09 15:12:34 +00:00
;;
esac
;;
esac
2021-06-17 09:55:08 +00:00
AddPackage git other luci-app-argon-config jerrykuku
2021-05-09 13:16:10 +00:00
}
2021-06-22 09:20:40 +00:00
[[ -n ${Defined_IP_Address} ]] && Default_LAN_IP="${Defined_IP_Address}"
[[ -n ${Default_LAN_IP} && ${Default_LAN_IP} != false ]] && {
if [[ ${Default_LAN_IP} =~ ^[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')
2021-06-22 09:20:40 +00:00
if [[ ! ${Default_LAN_IP} == ${Old_IP_Address} ]];then
TIME "Setting default IP Address to ${Default_LAN_IP} ..."
sed -i "s/${Old_IP_Address}/${Default_LAN_IP}/g" package/base-files/files/bin/config_generate
fi
else
2021-06-22 09:20:40 +00:00
TIME "[ERROR] ${Default_LAN_IP} is not an IP Address !"
fi
2021-04-16 10:57:19 +00:00
}
2021-06-19 13:01:56 +00:00
[[ ${INCLUDE_DRM_I915} == true && ${TARGET_PROFILE} == x86_64 ]] && {
2021-06-19 12:59:19 +00:00
Copy CustomFiles/Depends/DRM-I915 target/linux/x86
for X in $(ls -1 target/linux/x86 | grep "config-"); do echo -e "\n$(cat target/linux/x86/DRM-I915)" >> target/linux/x86/${X}; done
2021-06-19 12:59:19 +00:00
}
2021-04-16 10:57:19 +00:00
[ -f package/base-files/files/bin/AutoUpdate.sh ] && {
2021-06-06 05:55:56 +00:00
AutoUpdate_Version=$(egrep -o "V[0-9].+" package/base-files/files/bin/AutoUpdate.sh | awk 'END{print}')
2021-04-16 10:57:19 +00:00
} || AutoUpdate_Version=OFF
2021-06-18 02:08:35 +00:00
Copy CustomFiles/Depends/profile package/base-files/files/etc
Copy CustomFiles/Depends/base-files-essential package/base-files/files/lib/upgrade/keep.d
2021-07-02 15:51:31 +00:00
case "${Openwrt_Maintainer}" in
coolsnowwolf)
sed -i "/dns_caching_dns/d" $(PKG_Finder d package luci-app-turboacc)/root/etc/config/turboacc/turboacc
echo " option dns_caching_dns '223.5.5.5,114.114.114.114'" >> $(PKG_Finder d package luci-app-turboacc)/root/etc/config/turboacc/turboacc
Copy CustomFiles/Depends/coremark.sh $(PKG_Finder d "package feeds" coremark)
2021-07-02 15:28:23 +00:00
Copy CustomFiles/Depends/cpuinfo_x86 $(PKG_Finder d package autocore | awk 'NR==1')/files/x86/sbin cpuinfo
2021-05-18 02:10:29 +00:00
AddPackage git other helloworld fw876 master
2021-04-16 10:57:19 +00:00
sed -i 's/143/143,8080/' $(PKG_Finder d package luci-app-ssr-plus)/root/etc/init.d/shadowsocksr
2021-04-29 02:06:39 +00:00
sed -i "s?iptables?#iptables?g" ${Version_File}
2021-07-02 15:51:31 +00:00
sed -i "s?${zzz_Default_Version}?${zzz_Default_Version} @ ${Author} [${Display_Date}]?g" ${Version_File}
;;
immortalwrt)
sed -i "/dns_caching_dns/d" $(PKG_Finder d "package feeds" luci-app-turboacc)/root/etc/config/turboacc/turboacc
echo " option dns_caching_dns '223.5.5.5,114.114.114.114'" >> $(PKG_Finder d "package feeds" luci-app-turboacc)/root/etc/config/turboacc/turboacc
2021-07-02 15:51:31 +00:00
Copy CustomFiles/Depends/openwrt_release_${Openwrt_Maintainer} package/base-files/files/etc openwrt_release
2021-07-02 15:28:23 +00:00
Copy CustomFiles/Depends/cpuinfo_x86 $(PKG_Finder d package autocore | awk 'NR==1')/files/x86/sbin cpuinfo
sed -i "s?ImmortalWrt?ImmortalWrt @ ${Author} [${Display_Date}]?g" ${Version_File}
2021-02-24 23:51:13 +00:00
;;
esac
2021-07-02 15:51:31 +00:00
case "${Openwrt_Maintainer}" in
immortalwrt)
2021-07-02 15:28:23 +00:00
Copy CustomFiles/Depends/banner $(PKG_Finder d package default-settings)/files openwrt_banner
sed -i "s?By?By ${Author}?g" $(PKG_Finder d package default-settings)/files/openwrt_banner
sed -i "s?Openwrt?Openwrt ${CURRENT_Version} / AutoUpdate ${AutoUpdate_Version}?g" $(PKG_Finder d package default-settings)/files/openwrt_banner
;;
*)
2021-06-18 02:08:35 +00:00
Copy CustomFiles/Depends/banner package/base-files/files/etc
sed -i "s?By?By ${Author}?g" package/base-files/files/etc/banner
2021-06-06 05:55:56 +00:00
sed -i "s?Openwrt?Openwrt ${CURRENT_Version} / AutoUpdate ${AutoUpdate_Version}?g" package/base-files/files/etc/banner
;;
esac
TIME "[Firmware-Diy_Base] All done !"
}
Other_Scripts() {
2021-06-06 05:55:56 +00:00
source ./VARIABLE_FILE_Sec
case "${INCLUDE_Obsolete_PKG_Compatible}" in
19.07)
2021-06-06 05:55:56 +00:00
Openwrt_Branch=19.07
Force_mode=1
INCLUDE_Obsolete_PKG_Compatible=true
;;
21.02)
2021-06-06 05:55:56 +00:00
Openwrt_Branch=21.02
Force_mode=1
INCLUDE_Obsolete_PKG_Compatible=true
;;
esac
2021-06-17 09:55:08 +00:00
if [[ ${INCLUDE_Obsolete_PKG_Compatible} == true ]];then
2021-04-08 08:45:11 +00:00
TIME "Start to run Obsolete_Package_Compatible Scripts ..."
2021-07-02 15:51:31 +00:00
if [[ ${Openwrt_Maintainer} == openwrt || ${Force_mode} == 1 ]];then
2021-06-06 05:55:56 +00:00
case "${Openwrt_Branch}" in
19.07 | 21.02)
2021-06-18 02:08:35 +00:00
Copy CustomFiles/Patches/0003-upx-ucl-${Openwrt_Branch}.patch ./
2021-06-06 05:55:56 +00:00
cat 0003-upx-ucl-${Openwrt_Branch}.patch | patch -p1 > /dev/null 2>&1
2021-06-21 02:28:27 +00:00
# AddPackage svn feeds/packages golang coolsnowwolf/packages/trunk/lang
TIME "Start to convert zh-cn translation files to zh_Hans ..."
2021-06-18 02:08:35 +00:00
Copy Scripts/Convert_Translation.sh package
cd ./package && bash ./Convert_Translation.sh && cd ..
;;
*)
2021-06-06 05:55:56 +00:00
TIME "Current branch: [${Openwrt_Branch}] is not supported,skip..."
;;
esac
else
2021-07-02 15:51:31 +00:00
TIME "Current source: [${Openwrt_Maintainer}] is not supported,skip..."
fi
fi
2021-06-21 02:28:27 +00:00
if [[ -s $GITHUB_WORKSPACE/Configs/Common ]];then
[[ ! "$(cat .config)" =~ "## DO NOT MERGE" ]] && {
TIME "Merging [Configs/Common] to .config ..."
cat $GITHUB_WORKSPACE/Configs/Common >> .config
} || {
TIME "Skip merge [Configs/Common] ..."
sed -i '/## DO NOT MERGE/d' .config >/dev/null 2>&1
}
fi
2021-01-11 13:44:45 +00:00
}
PS_Firmware() {
2021-06-06 05:55:56 +00:00
source ./VARIABLE_FILE_Sec
mkdir -p bin/Firmware
cd ${Firmware_Path}
2021-06-19 16:05:22 +00:00
echo -e "### Firmware Output ###\n$(ls -1)\n"
2021-02-19 08:17:31 +00:00
case "${TARGET_PROFILE}" in
x86_64)
2021-06-17 09:55:08 +00:00
[[ -f ${Default_Legacy_Firmware} ]] && {
2021-06-06 05:55:56 +00:00
cp ${Default_Legacy_Firmware} $(EVAL_FW x86_64 Legacy ${Home}/VARIABLE_FILE_Sec)
TIME "Legacy Firmware: [${Default_Legacy_Firmware}] is detected !"
2021-06-17 09:55:08 +00:00
}
[[ -f ${Default_UEFI_Firmware} ]] && {
2021-06-06 05:55:56 +00:00
cp ${Default_UEFI_Firmware} $(EVAL_FW x86_64 UEFI ${Home}/VARIABLE_FILE_Sec)
TIME "UEFI Firmware: [${Default_UEFI_Firmware}] is detected !"
2021-06-17 09:55:08 +00:00
}
2021-02-19 08:17:31 +00:00
;;
*)
2021-06-17 09:55:08 +00:00
[[ -f ${Default_Firmware} ]] && {
2021-06-06 05:55:56 +00:00
cp ${Default_Firmware} $(EVAL_FW common ${Home}/VARIABLE_FILE_Sec)
TIME "Firmware: [${Default_Firmware}] is detected !"
2021-06-17 09:55:08 +00:00
} || {
2021-06-19 16:05:22 +00:00
TIME "Firmware is not detected !"
2021-06-21 02:28:27 +00:00
Error_Output=1
2021-06-17 09:55:08 +00:00
}
2021-02-19 08:17:31 +00:00
;;
esac
2021-06-21 02:28:27 +00:00
[[ ${Error_Output} != 1 ]] && mv -f AutoBuild-* ${Home}/bin/Firmware
2021-02-19 08:17:31 +00:00
cd ${Home}
echo "[$(date "+%H:%M:%S")] Actions Avaliable: $(df -h | grep "/dev/root" | awk '{printf $4}')"
2021-01-11 13:44:45 +00:00
}
2021-06-06 05:55:56 +00:00
EVAL_FW() {
case "$1" in
x86_64)
x86_64_Boot=$2
2021-06-17 09:55:08 +00:00
SHA5BIT=$(GET_SHA5BIT $(GET_VARIABLE Default_$2_Firmware= $3) 5)
2021-06-06 05:55:56 +00:00
EVAL_VARIABLE $(GET_VARIABLE AutoBuild_Firmware= $3)
;;
common)
2021-06-17 09:55:08 +00:00
SHA5BIT=$(GET_SHA5BIT $(GET_VARIABLE Default_Firmware= $2) 5)
2021-06-06 05:55:56 +00:00
EVAL_VARIABLE $(GET_VARIABLE AutoBuild_Firmware= $2)
;;
esac
}
EVAL_VARIABLE() {
eval OUTPUT=$1
2021-06-17 09:55:08 +00:00
echo "${OUTPUT}"
2021-06-06 05:55:56 +00:00
}
GET_SHA5BIT() {
2021-06-17 09:55:08 +00:00
grep "$1" sha256sums | cut -c1-$2
2021-06-06 05:55:56 +00:00
}
2021-05-19 01:03:41 +00:00
GET_BRANCH() {
2021-06-06 05:55:56 +00:00
Folder="$(pwd)"
2021-06-17 09:55:08 +00:00
[[ -n $1 ]] && Folder="$1"
2021-05-19 01:03:41 +00:00
git -C "${Folder}" rev-parse --abbrev-ref HEAD | grep -v HEAD || \
git -C "${Folder}" describe --exact-match HEAD || \
git -C "${Folder}" rev-parse HEAD
}
2021-06-06 05:55:56 +00:00
GET_VARIABLE() {
echo -e "$(grep "$1" $2 | cut -c$(echo $1 | wc -c)-200 | cut -d ":" -f2)"
2021-04-08 08:45:11 +00:00
}
2021-06-06 05:55:56 +00:00
TIME() {
2021-06-17 09:55:08 +00:00
echo "[$(date "+%H:%M:%S")] $*"
2021-01-05 23:38:00 +00:00
}
2021-02-23 11:44:45 +00:00
PKG_Finder() {
local Result
2021-04-16 10:57:19 +00:00
[[ $# -ne 3 ]] && {
TIME "Usage: PKG_Finder <f | d> Search_Path Target_Name/Target_Path"
2021-04-16 10:57:19 +00:00
return 0
}
Result=$(find $2 -name $3 -type $1 -exec echo {} \;)
[[ -n ${Result} ]] && echo "${Result}"
2021-02-23 11:44:45 +00:00
}
2021-06-17 09:55:08 +00:00
AddPackage_List() {
2021-04-16 13:37:28 +00:00
[[ $# != 1 ]] && {
TIME "[ERROR] Error options: [$#] [$*] !"
return 0
}
2021-06-06 05:55:56 +00:00
echo "" >> $1
2021-06-17 09:55:08 +00:00
[[ -s $1 ]] && {
2021-06-06 05:55:56 +00:00
TIME "Loading Custom Packages list: [$1]..."
2021-06-18 02:08:35 +00:00
cat $1 | sed '/^$/d' | while read X;do
[[ -n ${X} && ! $* =~ '#' ]] && AddPackage ${X}
2021-04-29 02:06:39 +00:00
done
2021-04-16 10:57:19 +00:00
}
}
AddPackage() {
2021-04-16 10:57:19 +00:00
[[ $# -lt 4 ]] && {
TIME "[ERROR] Error options: [$#] [$*] !"
return 0
}
2021-06-17 09:55:08 +00:00
[[ $* =~ "#" ]] && return 0
2021-06-06 05:55:56 +00:00
PKG_PROTO="$1"
PKG_DIR="$2"
PKG_NAME="$3"
2021-06-17 09:55:08 +00:00
REPO_URL="https://github.com/$4"
[[ -z $5 ]] && REPO_BRANCH=master || REPO_BRANCH="$5"
2021-07-02 15:51:31 +00:00
[[ ${REPO_URL} =~ "${Openwrt_Maintainer}/${Openwrt_Repo_Name}" ]] && return 0
2021-06-06 05:55:56 +00:00
mkdir -p package/${PKG_DIR}
2021-06-17 09:55:08 +00:00
[[ -d package/${PKG_DIR}/${PKG_NAME} ]] && {
2021-04-16 13:37:28 +00:00
TIME "Removing old package: [${PKG_NAME}] ..."
2021-06-06 05:55:56 +00:00
rm -rf package/${PKG_DIR}/${PKG_NAME}
2021-04-16 10:57:19 +00:00
}
2021-04-08 08:45:11 +00:00
TIME "Checking out package [${PKG_NAME}] to package/${PKG_DIR} ..."
2021-03-04 03:48:24 +00:00
case "${PKG_PROTO}" in
git)
2021-06-06 05:55:56 +00:00
2021-04-15 07:12:03 +00:00
PKG_URL="$(echo ${REPO_URL}/${PKG_NAME} | sed s/[[:space:]]//g)"
git clone -b ${REPO_BRANCH} ${PKG_URL} ${PKG_NAME} > /dev/null 2>&1
2021-03-04 03:48:24 +00:00
;;
svn)
svn checkout ${REPO_URL}/${PKG_NAME} ${PKG_NAME} > /dev/null 2>&1
;;
esac
[[ -f ${PKG_NAME}/Makefile || -n $(ls -A ${PKG_NAME}) ]] && {
2021-04-16 10:57:19 +00:00
mv -f "${PKG_NAME}" "package/${PKG_DIR}"
2021-06-18 02:08:35 +00:00
}
2021-01-05 23:38:00 +00:00
}
2021-06-18 02:08:35 +00:00
Copy() {
2021-04-16 10:57:19 +00:00
[[ $# -lt 2 ]] && {
TIME "[ERROR] Error options: [$#] [$*] !"
return 0
}
2021-06-21 02:28:27 +00:00
[[ ! -f ${GITHUB_WORKSPACE}/$1 ]] && [[ ! -d ${GITHUB_WORKSPACE}/$1 ]] && {
2021-06-24 16:08:51 +00:00
TIME "CustomFiles/$1 is not detected !"
2021-06-18 02:08:35 +00:00
return 0
2021-04-16 10:57:19 +00:00
}
2021-06-18 02:08:35 +00:00
[[ ! -d ${GITHUB_WORKSPACE}/openwrt/$2 ]] && mkdir -p ${GITHUB_WORKSPACE}/openwrt/$2
[[ -n $3 ]] && RENAME="$3" || RENAME=""
TIME "Copying $1 to $2 ${RENAME} ..."
cp -a "${GITHUB_WORKSPACE}/$1" "${GITHUB_WORKSPACE}/openwrt/$2/${RENAME}"
}