#!/bin/bash # AutoBuild Module by Hyy2001 # AutoBuild Functions Firmware_Diy_Before() { ECHO "[Firmware_Diy_Before] Starting ..." Home="${GITHUB_WORKSPACE}/openwrt" CONFIG_TEMP="${GITHUB_WORKSPACE}/openwrt/.config" CD ${Home} Firmware_Diy_Core [[ ${Short_Firmware_Date} == true ]] && Compile_Date="$(echo ${Compile_Date} | cut -c1-8)" Github="$(grep "https://github.com/[a-zA-Z0-9]" ${GITHUB_WORKSPACE}/.git/config | cut -c8-100 | sed 's/^[ \t]*//g')" [[ -z ${Author} || ${Author} == AUTO ]] && Author="$(echo "${Github}" | cut -d "/" -f4)" OP_AUTHOR="$(echo "${REPO_URL}" | cut -d "/" -f4)" OP_REPO="$(echo "${REPO_URL}" | cut -d "/" -f5)" OP_BRANCH="$(GET_Branch)" if [[ ${OP_BRANCH} =~ (master|main) ]] then OP_VERSION_HEAD="R$(date +%y.%m)-" else OP_BRANCH="$(echo ${OP_BRANCH} | egrep -o "[0-9]+.[0-9]+")" OP_VERSION_HEAD="R${OP_BRANCH}-" fi case "${OP_AUTHOR}/${OP_REPO}" in coolsnowwolf/lede) Version_File="package/lean/default-settings/files/zzz-default-settings" zzz_Default_Version="$(egrep -o "R[0-9]+\.[0-9]+\.[0-9]+" ${Version_File})" OP_VERSION="${zzz_Default_Version}-${Compile_Date}" ;; immortalwrt/immortalwrt) Version_File=${BASE_FILES}/etc/openwrt_release OP_VERSION="${OP_VERSION_HEAD}${Compile_Date}" ;; *) OP_VERSION="${OP_VERSION_HEAD}${Compile_Date}" ;; esac while [[ -z ${x86_Test} ]];do x86_Test="$(egrep -o "CONFIG_TARGET.*DEVICE.*=y" ${CONFIG_TEMP} | sed -r 's/CONFIG_TARGET_(.*)_DEVICE_(.*)=y/\1/')" [[ -n ${x86_Test} ]] && break x86_Test="$(egrep -o "CONFIG_TARGET.*Generic=y" ${CONFIG_TEMP} | sed -r 's/CONFIG_TARGET_(.*)_Generic=y/\1/')" [[ -z ${x86_Test} ]] && break done [[ ${x86_Test} == x86_64 ]] && { TARGET_PROFILE=x86_64 } || { TARGET_PROFILE="$(egrep -o "CONFIG_TARGET.*DEVICE.*=y" ${CONFIG_TEMP} | sed -r 's/.*DEVICE_(.*)=y/\1/')" } [[ -z ${TARGET_PROFILE} ]] && ECHO "Unable to get [TARGET_PROFILE] !" TARGET_BOARD="$(awk -F '[="]+' '/TARGET_BOARD/{print $2}' ${CONFIG_TEMP})" TARGET_SUBTARGET="$(awk -F '[="]+' '/TARGET_SUBTARGET/{print $2}' ${CONFIG_TEMP})" [[ -z ${Firmware_Format} || ${Firmware_Format} =~ (false|AUTO) ]] && { case "${TARGET_BOARD}" in ramips | reltek | ipq40xx | ath79 | ipq807x) Firmware_Format=bin ;; rockchip | x86) [[ $(cat ${CONFIG_TEMP}) =~ CONFIG_TARGET_IMAGES_GZIP=y ]] && { Firmware_Format=img.gz } || Firmware_Format=img ;; esac } case "${TARGET_BOARD}" in x86) AutoBuild_Firmware="AutoBuild-${OP_REPO}-${TARGET_PROFILE}-${OP_VERSION}-BOOT-SHA256.FORMAT" ;; *) AutoBuild_Firmware="AutoBuild-${OP_REPO}-${TARGET_PROFILE}-${OP_VERSION}-SHA256.FORMAT" ;; esac cat >> ${GITHUB_ENV} <> ${BASE_FILES}/etc/AutoBuild/Default_Variable <> ${i} <> ${BASE_FILES}/etc/AutoBuild/Custom_Variable <> ${Version_File} < /dev/null)" ] then echo '#iptables -t nat -A PREROUTING -p udp --dport 53 -j REDIRECT --to-ports 53' >> /etc/firewall.user echo '#iptables -t nat -A PREROUTING -p tcp --dport 53 -j REDIRECT --to-ports 53' >> /etc/firewall.user echo '#[ -n "\$(command -v ip6tables)" ] && ip6tables -t nat -A PREROUTING -p udp --dport 53 -j REDIRECT --to-ports 53' >> /etc/firewall.user echo '#[ -n "\$(command -v ip6tables)" ] && ip6tables -t nat -A PREROUTING -p tcp --dport 53 -j REDIRECT --to-ports 53' >> /etc/firewall.user fi exit 0 EOF sed -i "s?${zzz_Default_Version}?${zzz_Default_Version} @ ${Author} [${Display_Date}]?g" ${Version_File} ECHO "Downloading [ShadowSocksR Plus+] for coolsnowwolf/lede ..." AddPackage git other helloworld fw876 master sed -i 's/143/143,8080,8443/' $(PKG_Finder d package luci-app-ssr-plus)/root/etc/init.d/shadowsocksr ;; immortalwrt/immortalwrt) Copy ${CustomFiles}/Depends/openwrt_release_${OP_AUTHOR} ${BASE_FILES}/etc openwrt_release sed -i "s?ImmortalWrt?ImmortalWrt @ ${Author} [${Display_Date}]?g" ${Version_File} ;; esac sed -i "s?By?By ${Author}?g" ${CustomFiles}/Depends/banner sed -i "s?Openwrt?Openwrt ${OP_VERSION} / AutoUpdate ${AutoUpdate_Version}?g" ${CustomFiles}/Depends/banner [[ -n ${Banner_Message} ]] && sed -i "s?Powered by AutoBuild-Actions?${Banner_Message}?g" ${CustomFiles}/Depends/banner case "${OP_AUTHOR}/${OP_REPO}" in immortalwrt/immortalwrt) Copy ${CustomFiles}/Depends/banner ${Home}/$(PKG_Finder d package default-settings)/files openwrt_banner ;; *) Copy ${CustomFiles}/Depends/banner ${BASE_FILES}/etc ;; esac fi [[ -n ${Tempoary_IP} ]] && { ECHO "Using Tempoary IP Address: ${Tempoary_IP} ..." Default_IP="${Tempoary_IP}" } [[ -n ${Default_IP} && ${Default_IP} =~ ^[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}$ ]] && { Old_IP=$(awk -F '[="]+' '/ipaddr:-/{print $3}' ${BASE_FILES}/bin/config_generate | awk 'NR==1') if [[ ! ${Default_IP} == ${Old_IP} ]] then ECHO "Setting default IP Address to ${Default_IP} ..." sed -i "s/${Old_IP}/${Default_IP}/g" ${BASE_FILES}/bin/config_generate fi } [[ ${INCLUDE_DRM_I915} == true && ${TARGET_BOARD} == x86 ]] && { for X in $(ls -1 target/linux/x86 | grep "config-") do cat >> ${Home}/target/linux/x86/${X} <> ${CONFIG_TEMP} < /dev/null 2>&1 AddPackage svn feeds/packages golang coolsnowwolf/packages/trunk/lang ECHO "Starting to convert zh-cn translation files to zh_Hans ..." cd package && bash ${Scripts}/Convert_Translation.sh && cd - ;; *) ECHO "[${OP_BRANCH}]: Current OP_BRANCH is not supported !" ;; esac else ECHO "[${OP_AUTHOR}]: Current OP_AUTHOR is not supported !" fi fi if [[ ${Author_URL} != false ]] then [[ ${Author_URL} == AUTO ]] && Author_URL=${Github} cat >> ${CONFIG_TEMP} < Search_Path Target_Name/Target_Path" return 0 } Result=$(find $2 -name $3 -type $1 -exec echo {} \;) [[ -n ${Result} ]] && echo "${Result}" } CD() { cd $1 [[ ! $? == 0 ]] && ECHO "Unable to enter target directory $1 ..." || ECHO "Entering directory: $(pwd) ..." } MKDIR() { while [[ $1 ]];do if [[ ! -d $1 ]] then mkdir -p $1 || ECHO "Failed to create target directory: [$1] ..." fi shift done } AddPackage() { [[ $# -lt 4 ]] && { ECHO "Syntax error: [$#] [$*]" return 0 } PKG_PROTO=$1 case "${PKG_PROTO}" in git | svn) : ;; *) ECHO "Unknown content: ${PKG_PROTO}" return 0 ;; esac PKG_DIR=$2 [[ ! ${PKG_DIR} =~ ${GITHUB_WORKSPACE} ]] && PKG_DIR=package/${PKG_DIR} PKG_NAME=$3 REPO_URL="https://github.com/$4" REPO_BRANCH=$5 [[ ${REPO_URL} =~ "${OP_AUTHOR}/${OP_REPO}" ]] && return 0 MKDIR ${PKG_DIR} [[ -d ${PKG_DIR}/${PKG_NAME} ]] && { ECHO "Removing old package: [${PKG_NAME}] ..." rm -rf ${PKG_DIR}/${PKG_NAME} } ECHO "Checking out package [${PKG_NAME}] to ${PKG_DIR} ..." case "${PKG_PROTO}" in git) [[ -z ${REPO_BRANCH} ]] && { ECHO "WARNING: Syntax missing ,using default branch: [master]" REPO_BRANCH=master } PKG_URL="$(echo ${REPO_URL}/${PKG_NAME} | sed s/[[:space:]]//g)" git clone -b ${REPO_BRANCH} ${PKG_URL} ${PKG_NAME} > /dev/null 2>&1 ;; svn) svn checkout ${REPO_URL}/${PKG_NAME} ${PKG_NAME} > /dev/null 2>&1 ;; esac [[ -f ${PKG_NAME}/Makefile || -n $(ls -A ${PKG_NAME}) ]] && { mv -f "${PKG_NAME}" "${PKG_DIR}" [[ $? == 0 ]] && ECHO "Done" } || ECHO "Failed to download package ${PKG_NAME} ..." } Copy() { [[ ! $# =~ [23] ]] && { ECHO "Syntax error: [$#] [$*]" return 0 } [[ ! -f $1 ]] && [[ ! -d $1 ]] && { ECHO "$1: No such file or directory ..." return 0 } MKDIR $2 if [[ -z $3 ]] then ECHO "Copying $1 to $2 ..." cp -a $1 $2 else ECHO "Copying and renaming $1 to $2/$3 ..." cp -a $1 $2/$3 fi [[ $? == 0 ]] && ECHO "Done" || ECHO "Failed" }