X-OpenWrt/Scripts/AutoBuild_Function.sh

524 lines
16 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
Firmware_Diy_Before() {
ECHO "[Firmware_Diy_Before] Starting ..."
2021-04-16 10:57:19 +00:00
Home="${GITHUB_WORKSPACE}/openwrt"
CONFIG_TEMP="${GITHUB_WORKSPACE}/openwrt/.config"
CD ${Home}
Firmware_Diy_Core
2021-06-17 09:55:08 +00:00
[[ ${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)"
2021-11-03 01:16:26 +00:00
OP_BRANCH="$(GET_Branch)"
if [[ ${OP_BRANCH} =~ (master|main) ]]
then
OP_VERSION_HEAD="R$(date +%y.%m)-"
else
2021-07-09 14:04:24 +00:00
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"
2021-07-02 15:51:31 +00:00
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
2021-06-17 09:55:08 +00:00
while [[ -z ${x86_Test} ]];do
x86_Test="$(egrep -o "CONFIG_TARGET.*DEVICE.*=y" ${CONFIG_TEMP} | 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_TEMP} | 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
} || {
TARGET_PROFILE="$(egrep -o "CONFIG_TARGET.*DEVICE.*=y" ${CONFIG_TEMP} | sed -r 's/.*DEVICE_(.*)=y/\1/')"
2021-04-16 10:57:19 +00:00
}
[[ -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 | ath* | ipq* | bcm47xx | bmips | kirkwood | mediatek)
Firmware_Format=bin
;;
rockchip | x86 | bcm27xx | mxs | sunxi | zynq)
Firmware_Format=$(if_IMG)
;;
mvebu)
case "${TARGET_SUBTARGET}" in
cortexa53 | cortexa72)
Firmware_Format=$(if_IMG)
;;
esac
;;
octeon | oxnas | pistachio)
Firmware_Format=tar
;;
esac
}
[[ ${Author_URL} != false && ${Author_URL} == AUTO ]] && Author_URL=${Github}
[[ ${Author_URL} == false ]] && unset Author_URL
if [[ ${Default_FLAG} == AUTO ]]
then
TARGET_FLAG=${CONFIG_FILE/${TARGET_PROFILE}-/}
[[ ${TARGET_FLAG} =~ ${TARGET_PROFILE} || -z ${TARGET_FLAG} || ${TARGET_FLAG} == ${CONFIG_FILE} ]] && TARGET_FLAG=Full
else
if [[ ! ${Default_FLAG} =~ (\"|=|-|_|\.|\#|\|) && ${Default_FLAG} =~ [a-zA-Z0-9] ]]
then
TARGET_FLAG="${Default_FLAG}"
fi
fi
if [[ ! ${Tempoary_FLAG} =~ (\"|=|-|_|\.|\#|\|) && ${Tempoary_FLAG} =~ [a-zA-Z0-9] ]]
then
TARGET_FLAG="${Tempoary_FLAG}"
fi
2021-07-16 16:11:35 +00:00
case "${TARGET_BOARD}" in
x86)
AutoBuild_Firmware="AutoBuild-${OP_REPO}-${TARGET_PROFILE}-${OP_VERSION}-BOOT-${TARGET_FLAG}-SHA256.FORMAT"
2021-06-06 05:55:56 +00:00
;;
*)
AutoBuild_Firmware="AutoBuild-${OP_REPO}-${TARGET_PROFILE}-${OP_VERSION}-${TARGET_FLAG}-SHA256.FORMAT"
2021-06-06 05:55:56 +00:00
;;
esac
cat >> ${GITHUB_ENV} <<EOF
2021-06-06 05:55:56 +00:00
Home=${Home}
CONFIG_TEMP=${CONFIG_TEMP}
INCLUDE_AutoBuild_Features=${INCLUDE_AutoBuild_Features}
INCLUDE_Original_OpenWrt_Compatible=${INCLUDE_Original_OpenWrt_Compatible}
INCLUDE_DRM_I915=${INCLUDE_DRM_I915}
Checkout_Virtual_Images=${Checkout_Virtual_Images}
2021-07-16 16:11:35 +00:00
AutoBuild_Firmware=${AutoBuild_Firmware}
2021-08-03 10:41:36 +00:00
CustomFiles=${GITHUB_WORKSPACE}/CustomFiles
Scripts=${GITHUB_WORKSPACE}/Scripts
FEEDS_LUCI=${GITHUB_WORKSPACE}/openwrt/package/feeds/luci
FEEDS_PKG=${GITHUB_WORKSPACE}/openwrt/package/feeds/packages
BASE_FILES=${GITHUB_WORKSPACE}/openwrt/package/base-files/files
Banner_Message="${Banner_Message}"
REGEX_Skip_Checkout="${REGEX_Skip_Checkout}"
Version_File=${Version_File}
Firmware_Format=${Firmware_Format}
FEEDS_CONF=${Home}/feeds.conf.default
Author_URL=${Author_URL}
ENV_FILE=${GITHUB_ENV}
2021-06-06 05:55:56 +00:00
EOF
source ${GITHUB_ENV}
echo -e "### VARIABLE LIST ###\n$(cat ${GITHUB_ENV})\n"
ECHO "[Firmware_Diy_Before] Done"
2021-01-11 13:44:45 +00:00
}
Firmware_Diy_Main() {
ECHO "[Firmware_Diy_Main] Starting ..."
CD ${Home}
2021-08-03 10:41:36 +00:00
chmod +x -R ${Scripts}
chmod 777 -R ${CustomFiles}
if [[ ${INCLUDE_AutoBuild_Features} == true ]]
then
MKDIR ${BASE_FILES}/etc/AutoBuild
touch ${BASE_FILES}/etc/AutoBuild/Default_Variable ${BASE_FILES}/etc/AutoBuild/Custom_Variable
cat >> ${BASE_FILES}/etc/AutoBuild/Default_Variable <<EOF
## 请不要修改此文件中的内容, 自定义变量请在 Custom_Variable 中添加或修改
## 该文件将在运行 AutoUpdate.sh 时被读取, 该文件中的变量优先级低于 Custom_Variable
EOF
for i in ${BASE_FILES}/etc/AutoBuild/Default_Variable ${GITHUB_ENV}
do
cat >> ${i} <<EOF
Author=${Author}
Github=${Github}
TARGET_PROFILE=${TARGET_PROFILE}
TARGET_BOARD=${TARGET_BOARD}
TARGET_SUBTARGET=${TARGET_SUBTARGET}
TARGET_FLAG=${TARGET_FLAG}
OP_VERSION=${OP_VERSION}
OP_AUTHOR=${OP_AUTHOR}
OP_REPO=${OP_REPO}
OP_BRANCH=${OP_BRANCH}
EOF
done
unset i
cat >> ${BASE_FILES}/etc/AutoBuild/Custom_Variable <<EOF
## 请在下方输入你的自定义变量,一行只能填写一个变量
## 该文件将在运行 AutoUpdate.sh 时被读取, 该文件中的变量优先级高于 Default_Variable
## 示例:
# Author=Hyy2001
# TARGET_PROFILE=x86_64
# Github=https://github.com/Hyy2001X/AutoBuild-Actions
# Tmp_Path=/tmp/AutoUpdate
# Log_Path=/tmp
EOF
Copy ${Scripts}/AutoBuild_Tools.sh ${BASE_FILES}/bin
Copy ${Scripts}/AutoUpdate.sh ${BASE_FILES}/bin
AutoUpdate_Version=$(awk -F '=' '/Version/{print $2}' ${BASE_FILES}/bin/AutoUpdate.sh | awk 'NR==1')
AddPackage svn lean luci-app-autoupdate Hyy2001X/AutoBuild-Packages/trunk
Copy ${CustomFiles}/Depends/profile ${BASE_FILES}/etc
Copy ${CustomFiles}/Depends/base-files-essential ${BASE_FILES}/lib/upgrade/keep.d
case "${OP_AUTHOR}/${OP_REPO}" in
coolsnowwolf/lede)
Copy ${CustomFiles}/Depends/coremark.sh ${Home}/$(PKG_Finder d "package feeds" coremark)
2021-11-03 01:16:26 +00:00
sed -i '\/etc\/firewall.user/d;/exit 0/d' ${Version_File}
cat >> ${Version_File} <<EOF
2021-11-07 06:24:27 +00:00
sed -i '/check_signature/d' /etc/opkg.conf
2021-11-03 01:16:26 +00:00
sed -i 's/\"services\"/\"nas\"/g' /usr/lib/lua/luci/controller/aliyundrive-webdav.lua
sed -i 's/services/nas/g' /usr/lib/lua/luci/view/aliyundrive-webdav/aliyundrive-webdav_log.htm
sed -i 's/services/nas/g' /usr/lib/lua/luci/view/aliyundrive-webdav/aliyundrive-webdav_status.htm
sed -i 's/\"services\"/\"vpn\"/g' /usr/lib/lua/luci/controller/v2ray_server.lua
sed -i 's/\"services\"/\"vpn\"/g' /usr/lib/lua/luci/model/cbi/v2ray_server/index.lua
sed -i 's/\"services\"/\"vpn\"/g' /usr/lib/lua/luci/model/cbi/v2ray_server/user.lua
sed -i 's/services/vpn/g' /usr/lib/lua/luci/view/v2ray_server/log.htm
sed -i 's/services/vpn/g' /usr/lib/lua/luci/view/v2ray_server/users_list_status.htm
sed -i 's/services/vpn/g' /usr/lib/lua/luci/view/v2ray_server/users_list_status.htm
sed -i 's/services/vpn/g' /usr/lib/lua/luci/view/v2ray_server/v2ray.htm
2021-11-07 02:19:58 +00:00
if [ -z "\$(grep "REDIRECT --to-ports 53" /etc/firewall.user 2> /dev/null)" ]
2021-11-03 01:16:26 +00:00
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
2021-11-03 01:16:26 +00:00
fi
exit 0
EOF
if [[ -n ${TARGET_FLAG} ]]
then
sed -i "s?${zzz_Default_Version}?${TARGET_FLAG} ${zzz_Default_Version} @ ${Author} [${Display_Date}]?g" ${Version_File}
else
sed -i "s?${zzz_Default_Version}?${zzz_Default_Version} @ ${Author} [${Display_Date}]?g" ${Version_File}
fi
2021-11-03 01:16:26 +00:00
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
if [[ -n ${TARGET_FLAG} ]]
then
sed -i "s?ImmortalWrt?ImmortalWrt ${TARGET_FLAG} @ ${Author} [${Display_Date}]?g" ${Version_File}
else
sed -i "s?ImmortalWrt?ImmortalWrt @ ${Author} [${Display_Date}]?g" ${Version_File}
fi
;;
esac
2021-08-05 07:27:21 +00:00
sed -i "s?By?By ${Author}?g" ${CustomFiles}/Depends/banner
sed -i "s?Openwrt?Openwrt ${OP_VERSION} / AutoUpdate ${AutoUpdate_Version}?g" ${CustomFiles}/Depends/banner
if [[ -n ${Banner_Message} ]]
then
if [[ -n ${TARGET_FLAG} ]]
then
sed -i "s?Powered by AutoBuild-Actions?${Banner_Message} @ ${TARGET_FLAG}?g" ${CustomFiles}/Depends/banner
else
sed -i "s?Powered by AutoBuild-Actions?${Banner_Message}?g" ${CustomFiles}/Depends/banner
fi
fi
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
2021-07-16 16:11:35 +00:00
}
[[ ${INCLUDE_DRM_I915} == true && ${TARGET_BOARD} == x86 ]] && {
for X in $(ls -1 target/linux/x86 | grep "config-")
do
cat >> ${Home}/target/linux/x86/${X} <<EOF
CONFIG_64BIT=y
CONFIG_DRM=y
CONFIG_DRM_I915=y
CONFIG_DRM_I915_GVT=y
CONFIG_DUMMY_CONSOLE=y
EOF
done
unset X
2021-06-19 12:59:19 +00:00
}
ECHO "[Firmware_Diy_Main] Done"
}
Firmware_Diy_Other() {
ECHO "[Firmware_Diy_Other] Starting ..."
CD ${Home}
case "${INCLUDE_Original_OpenWrt_Compatible}" in
19.07)
2021-07-09 14:04:24 +00:00
OP_BRANCH=19.07
Force_mode=1
INCLUDE_Original_OpenWrt_Compatible=true
;;
21.02)
2021-07-09 14:04:24 +00:00
OP_BRANCH=21.02
Force_mode=1
INCLUDE_Original_OpenWrt_Compatible=true
;;
esac
if [[ ${INCLUDE_Original_OpenWrt_Compatible} == true ]]
then
if [[ ${OP_AUTHOR} =~ (openwrt|[Ll]ienol) || ${Force_mode} == 1 ]]
then
ECHO "Starting to run [Obsolete_Package_Compatible] Script ..."
2021-07-09 14:04:24 +00:00
case "${OP_BRANCH}" in
2021-07-16 16:11:35 +00:00
19.07 | 21.02 | main)
[[ ${OP_BRANCH} == main ]] && OP_BRANCH=21.02
cat >> ${CONFIG_TEMP} <<EOF
2021-10-06 08:28:13 +00:00
# CONFIG_PACKAGE_dnsmasq is not set
CONFIG_PACKAGE_dnsmasq-full=y
# CONFIG_PACKAGE_wpad-wolfssl is not set
CONFIG_PACKAGE_wpad-openssl=y
EOF
Copy ${CustomFiles}/Patches/0003-upx-ucl-${OP_BRANCH}.patch ${Home}
2021-07-09 14:04:24 +00:00
cat 0003-upx-ucl-${OP_BRANCH}.patch | patch -p1 > /dev/null 2>&1
2021-10-06 08:28:13 +00:00
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 [[ -n ${Author_URL} ]]
then
cat >> ${CONFIG_TEMP} <<EOF
CONFIG_KERNEL_BUILD_USER="${Author}"
CONFIG_KERNEL_BUILD_DOMAIN="${Author_URL}"
EOF
fi
ECHO "[Firmware_Diy_Other] Done"
2021-01-11 13:44:45 +00:00
}
Firmware_Diy_End() {
ECHO "[Firmware_Diy_End] Starting ..."
cd ${Home}
MKDIR ${Home}/bin/Firmware
Firmware_Path="${Home}/bin/targets/${TARGET_BOARD}/${TARGET_SUBTARGET}"
SHA256_File="${Firmware_Path}/sha256sums"
2021-06-06 05:55:56 +00:00
cd ${Firmware_Path}
2021-07-16 16:11:35 +00:00
echo -e "### FIRMWARE OUTPUT ###\n$(ls -1 | egrep -v "packages|buildinfo|sha256sums|manifest")\n"
case "${TARGET_BOARD}" in
x86)
[[ ${Checkout_Virtual_Images} == true ]] && {
Process_Firmware $(List_Format)
2021-07-16 16:11:35 +00:00
} || {
Process_Firmware ${Firmware_Format}
2021-06-17 09:55:08 +00:00
}
2021-02-19 08:17:31 +00:00
;;
*)
if [[ -n ${Firmware_Format} ]]
then
Process_Firmware ${Firmware_Format}
else
Process_Firmware $(List_Format)
fi
2021-02-19 08:17:31 +00:00
;;
esac
[[ $(ls) =~ 'AutoBuild-' ]] && {
cd -
cp -a ${Firmware_Path}/AutoBuild-* bin/Firmware
}
echo "[$(date "+%H:%M:%S")] Actions Avaliable: $(df -h | grep "/dev/root" | awk '{printf $4}')"
ECHO "[Firmware_Diy_End] Done"
2021-01-11 13:44:45 +00:00
}
Process_Firmware() {
2021-07-16 16:11:35 +00:00
while [[ $1 ]];do
Process_Firmware_Core $1 $(List_Firmware $1)
2021-07-16 16:11:35 +00:00
shift
done
}
Process_Firmware_Core() {
Firmware_Format_Defined=$1
2021-07-16 16:11:35 +00:00
shift
while [[ $1 ]];do
Firmware=${AutoBuild_Firmware}
2021-07-16 16:11:35 +00:00
case "${TARGET_BOARD}" in
x86)
[[ $1 =~ efi ]] && {
FW_Boot_Method=UEFI
} || FW_Boot_Method=BIOS
Firmware=${Firmware/BOOT/${FW_Boot_Method}}
2021-07-16 16:11:35 +00:00
;;
esac
Firmware=${Firmware/SHA256/$(Get_SHA256 $1)}
Firmware=${Firmware/FORMAT/${Firmware_Format_Defined}}
2021-07-16 16:11:35 +00:00
[[ -f $1 ]] && {
ECHO "Copying [$1] to [${Firmware}] ..."
cp -a $1 ${Firmware}
} || ECHO "Unable to access [${Firmware}] ..."
2021-07-16 16:11:35 +00:00
shift
done
}
List_Firmware() {
[[ -z $* ]] && {
List_REGEX | while read X;do
echo ${X} | cut -d "*" -f2
2021-07-16 16:11:35 +00:00
done
} || {
while [[ $1 ]];do
for X in $(echo $(List_REGEX));do
[[ ${X} == *$1 ]] && echo "${X}" | cut -d "*" -f2
2021-07-16 16:11:35 +00:00
done
shift
done
}
}
List_Format() {
echo "$(List_REGEX | cut -d "*" -f2 | cut -d "." -f2-3)" | sort | uniq
2021-07-16 16:11:35 +00:00
}
List_REGEX() {
[[ -n ${REGEX_Skip_Checkout} ]] && {
egrep -v "${REGEX_Skip_Checkout}" ${SHA256_File} | tr -s '\n'
} || egrep -v "packages|buildinfo|sha256sums|manifest|kernel|rootfs|factory" ${SHA256_File} | tr -s '\n'
2021-06-06 05:55:56 +00:00
}
Get_SHA256() {
List_REGEX | grep "$1" | cut -c1-5
2021-06-06 05:55:56 +00:00
}
2021-11-03 01:16:26 +00:00
GET_Branch() {
2021-08-03 10:41:36 +00:00
git -C $(pwd) rev-parse --abbrev-ref HEAD | grep -v HEAD || \
git -C $(pwd) describe --exact-match HEAD || \
git -C $(pwd) rev-parse HEAD
2021-05-19 01:03:41 +00:00
}
if_IMG() {
[[ $(cat ${CONFIG_TEMP}) =~ CONFIG_TARGET_IMAGES_GZIP=y ]] && {
echo img.gz
} || echo img
}
ECHO() {
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 ]] && {
ECHO "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
}
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() {
2021-04-16 10:57:19 +00:00
[[ $# -lt 4 ]] && {
ECHO "Syntax error: [$#] [$*]"
2021-04-16 10:57:19 +00:00
return 0
}
2021-07-19 04:17:05 +00:00
PKG_PROTO=$1
case "${PKG_PROTO}" in
git | svn)
:
;;
*)
ECHO "Unknown content: ${PKG_PROTO}"
return 0
2021-07-19 04:17:05 +00:00
;;
esac
PKG_DIR=$2
2021-08-03 10:41:36 +00:00
[[ ! ${PKG_DIR} =~ ${GITHUB_WORKSPACE} ]] && PKG_DIR=package/${PKG_DIR}
2021-07-19 04:17:05 +00:00
PKG_NAME=$3
2021-06-17 09:55:08 +00:00
REPO_URL="https://github.com/$4"
2021-07-19 05:18:50 +00:00
REPO_BRANCH=$5
[[ ${REPO_URL} =~ "${OP_AUTHOR}/${OP_REPO}" ]] && return 0
2021-06-06 05:55:56 +00:00
MKDIR ${PKG_DIR}
2021-08-03 10:41:36 +00:00
[[ -d ${PKG_DIR}/${PKG_NAME} ]] && {
ECHO "Removing old package: [${PKG_NAME}] ..."
2021-08-03 10:41:36 +00:00
rm -rf ${PKG_DIR}/${PKG_NAME}
2021-04-16 10:57:19 +00:00
}
ECHO "Checking out package [${PKG_NAME}] to ${PKG_DIR} ..."
2021-03-04 03:48:24 +00:00
case "${PKG_PROTO}" in
git)
2021-07-19 05:18:50 +00:00
[[ -z ${REPO_BRANCH} ]] && {
ECHO "WARNING: Syntax missing <branch> ,using default branch: [master]"
2021-07-19 05:18:50 +00:00
REPO_BRANCH=master
}
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-08-03 10:41:36 +00:00
mv -f "${PKG_NAME}" "${PKG_DIR}"
[[ $? == 0 ]] && ECHO "Done"
} || ECHO "Failed to download package ${PKG_NAME} ..."
2021-01-05 23:38:00 +00:00
}
2021-06-18 02:08:35 +00:00
Copy() {
2021-08-03 10:41:36 +00:00
[[ ! $# =~ [23] ]] && {
ECHO "Syntax error: [$#] [$*]"
2021-04-16 10:57:19 +00:00
return 0
}
2021-08-03 10:41:36 +00:00
[[ ! -f $1 ]] && [[ ! -d $1 ]] && {
ECHO "$1: No such file or directory ..."
2021-06-18 02:08:35 +00:00
return 0
2021-04-16 10:57:19 +00:00
}
MKDIR $2
if [[ -z $3 ]]
then
ECHO "Copying $1 to $2 ..."
cp -a $1 $2
2021-08-03 10:41:36 +00:00
else
ECHO "Copying and renaming $1 to $2/$3 ..."
cp -a $1 $2/$3
2021-08-03 10:41:36 +00:00
fi
[[ $? == 0 ]] && ECHO "Done" || ECHO "Failed"
2021-11-07 02:19:58 +00:00
}