diff --git a/.github/config b/.github/config index dea74187..8615a2e6 100755 --- a/.github/config +++ b/.github/config @@ -2,14 +2,29 @@ cd lede -git clone https://github.com/tuanqing/install-program package/install-program -git clone https://github.com/tuanqing/openwrt-mentohust package/openwrt-mentohust -git clone https://github.com/tuanqing/luci-app-mentohust package/luci-app-mentohust -git clone https://github.com/jerrykuku/luci-theme-argon -b 18.06 package/luci-theme-argon +( + cd package + git clone https://github.com/tuanqing/install-program + # git clone https://github.com/tuanqing/openwrt-mentohust + # git clone https://github.com/tuanqing/luci-app-mentohust + # git clone https://github.com/jerrykuku/luci-app-jd-dailybonus + # git clone https://github.com/jerrykuku/luci-app-ttnode + git clone https://github.com/jerrykuku/luci-theme-argon -b 18.06 + git clone https://github.com/jerrykuku/luci-app-argon-config +# git clone https://github.com/lisaac/luci-lib-docker +# git clone https://github.com/lisaac/luci-app-dockerman + +# sed -i 's/+docker-ce/+docker +dockerd/' luci-app-dockerman/applications/luci-app-dockerman/Makefile + + rm -rf libs/nettle + rm -rf lean/{samba4,luci-app-samba4,luci-app-ttyd,luci-theme-argon,luci-lib-docker} + # svn co https://github.com/Lienol/openwrt/trunk/package/libs/{libaudit,libsemanage,musl-fts,nettle} libs + git clone https://github.com/Lienol/openwrt -b main lienol-openwrt + cp -r lienol-openwrt/package/libs/{libaudit,libsemanage,musl-fts,nettle} libs/ + rm -rf lienol-openwrt +) cat >feeds.conf.default <<-EOF -# src-git luci https://git.openwrt.org/project/luci.git;openwrt-19.07 -# src-git packages https://git.openwrt.org/feed/packages.git src-git luci https://github.com/Lienol/openwrt-luci.git;18.06 src-git packages https://github.com/Lienol/openwrt-packages.git;main src-git routing https://git.openwrt.org/feed/routing.git @@ -17,12 +32,11 @@ src-git telephony https://git.openwrt.org/feed/telephony.git src-git helloworld https://github.com/fw876/helloworld.git EOF -rm -rf package/lean/{samba4,luci-app-samba4,luci-app-ttyd,luci-theme-argon} -svn co https://github.com/Lienol/openwrt/branches/main/package/libs/{libaudit,musl-fts,libsemanage} package/libs - ./scripts/feeds update -a ./scripts/feeds install -a +# sed -i '/+libmount/d' feeds/packages/utils/btrfs-progs/Makefile + git apply ../.github/patches/{0001*,0002*}.patch --directory=feeds/luci ( cd feeds/luci/modules/luci-mod-admin-full/luasrc/view/admin_status @@ -32,17 +46,16 @@ git apply ../.github/patches/{0001*,0002*}.patch --directory=feeds/luci zzz="package/lean/default-settings/files/zzz-default-settings" sed -i 's/samba/samba4/' $zzz -# sed -i 's#openwrt.proxy.ustclug.org#mirrors.bfsu.edu.cn\\/openwrt#' $zzz sed -i "/openwrt_luci/i sed -i '/Lienol/d' /etc/opkg/distfeeds.conf" $zzz sed -i "/openwrt_luci/i sed -i '/helloworld/d' /etc/opkg/distfeeds.conf" $zzz packages=" \ brcmfmac-firmware-43430-sdio brcmfmac-firmware-43455-sdio kmod-brcmfmac wpad \ -kmod-fs-ext4 kmod-fs-vfat kmod-fs-exfat dosfstools e2fsprogs antfs-mount \ +kmod-fs-ext4 kmod-fs-vfat kmod-fs-exfat dosfstools e2fsprogs ntfs-3g \ kmod-usb2 kmod-usb3 kmod-usb-storage kmod-usb-storage-extras kmod-usb-storage-uas \ kmod-usb-net kmod-usb-net-asix-ax88179 kmod-usb-net-rtl8150 kmod-usb-net-rtl8152 \ blkid lsblk parted fdisk cfdisk losetup resize2fs tune2fs pv unzip \ -lscpu htop iperf3 curl lm-sensors install-program +lscpu htop iperf3 curl lm-sensors python3 install-program " sed -i '/FEATURES+=/ { s/cpiogz //; s/ext4 //; s/ramdisk //; s/squashfs //; }' \ target/linux/armvirt/Makefile @@ -70,8 +83,11 @@ CONFIG_PACKAGE_luci-app-aria2=y CONFIG_PACKAGE_luci-app-cifs-mount=y CONFIG_PACKAGE_luci-app-samba4=y CONFIG_PACKAGE_luci-app-ttyd=y -CONFIG_PACKAGE_luci-app-kodexplorer=y -CONFIG_PACKAGE_luci-app-mentohust=y +# CONFIG_PACKAGE_luci-app-mentohust=y +# CONFIG_PACKAGE_luci-app-jd-dailybonus=y +# CONFIG_PACKAGE_luci-app-ttnode=y +# CONFIG_PACKAGE_luci-app-dockerman=y +CONFIG_PACKAGE_luci-app-argon-config=y ## luci theme CONFIG_PACKAGE_luci-theme-bootstrap-mod=y CONFIG_PACKAGE_luci-theme-argon=y diff --git a/.github/workflows/build-CI.yml b/.github/workflows/build-CI.yml index 2fdb2e5b..3940bb6f 100644 --- a/.github/workflows/build-CI.yml +++ b/.github/workflows/build-CI.yml @@ -1,18 +1,16 @@ name: OpenWrt-CI on: - schedule: - - cron: '0 22 * * 5' - repository_dispatch: - types: 'run' +# schedule: +# - cron: '0 21 * * 5' + workflow_dispatch: env: TZ: 'Asia/Shanghai' jobs: build: - runs-on: ubuntu-18.04 - if: github.event_name == 'schedule' || github.event.action == 'run' + runs-on: ubuntu-20.04 steps: - name: Checkout @@ -23,10 +21,10 @@ jobs: docker rmi `docker images -q` sudo rm -rf /etc/apt/sources.list.d/* /usr/share/dotnet /usr/local/lib/android /usr/lib/jvm /opt/ghc sudo -E apt-get -qq update - sudo -E apt-get -qq install $(curl -fsSL git.io/depends-ubuntu-1804) + sudo -E apt-get -qq install $(curl -fsSL git.io/depends-ubuntu-2004) sudo -E apt-get -qq autoremove --purge sudo -E apt-get -qq clean - sudo timedatectl set-timezone $TZ + sudo timedatectl set-timezone "$TZ" - name: Clone Lean's openwrt run: | @@ -50,7 +48,7 @@ jobs: cp lede/bin/targets/*/*/*.tar.gz ./openwrt sudo ./gen_openwrt -d -k latest - devices=("phicomm-n1" "vplus" "beikeyun" "l1pro" "s905x3") + devices=("phicomm-n1" "rk3328" "s9xxx" "vplus") cd out for x in ${devices[*]}; do cd $x @@ -66,26 +64,20 @@ jobs: name: ${{ env.firmware_phicomm-n1 }} path: out/phicomm-n1 - - name: Upload firmware @ vplus + - name: Upload firmware @ rk3328 [ default beikeyun ] uses: actions/upload-artifact@main with: - name: ${{ env.firmware_vplus }} - path: out/vplus + name: ${{ env.firmware_rk3328 }} + path: out/rk3328 - - name: Upload firmware @ beikeyun + - name: Upload firmware @ s9xxx [ default octopus planet ] uses: actions/upload-artifact@main with: - name: ${{ env.firmware_beikeyun }} - path: out/beikeyun + name: ${{ env.firmware_s9xxx }} + path: out/s9xxx - - name: Upload firmware @ l1pro - uses: actions/upload-artifact@main - with: - name: ${{ env.firmware_l1pro }} - path: out/l1pro - - - name: Upload firmware @ s905x3 + - name: Upload firmware @ vplus uses: actions/upload-artifact@main with: - name: ${{ env.firmware_s905x3 }} - path: out/s905x3 + name: ${{ env.firmware_vplus }} + path: out/vplus diff --git a/LICENSE b/LICENSE index 593af7ab..cb161403 100644 --- a/LICENSE +++ b/LICENSE @@ -1,6 +1,6 @@ MIT License -Copyright (c) 2020 tuanqing +Copyright (c) 2020-2021 tuanqing Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal diff --git a/README.md b/README.md index 9105c9ca..ef578f5b 100644 --- a/README.md +++ b/README.md @@ -1,7 +1,7 @@ -# 自动构建斐讯 N1、微加云、贝壳云、我家云、S905x3( X96 Max Plus, HK1 Box ) OpenWrt 固件脚本 -# Automatically Build OpenWrt Firmware for Phicomm n1, Vplus, Beikeyun, L1-pro, S905x3( X96 Max Plus, HK1 Box ) etc +# 自动构建斐讯 N1、微加云、贝壳云、我家云、S9xxx OpenWrt 固件脚本 +# Automatically Build OpenWrt Firmware for Phicomm n1, Vplus, Beikeyun, L1 Pro, S9xxx etc -**制作脚本已部署到 Github Action,真正实现一栈式全自动构建,每周六早上六点准时为你构建,无须自行制作,下载即可用** +**制作脚本已部署到 Github Action,真正实现一栈式全自动构建,每周六早上五点准时为你构建,无须自行制作,下载即可用** [![OpenWrt-CI](https://github.com/tuanqing/mknop/workflows/OpenWrt-CI/badge.svg?branch=master)](https://github.com/tuanqing/mknop/actions) 👆👆👆    戳上面查看构建状态 @@ -49,23 +49,21 @@ * 目录说明 ``` ├── common 公共目录 - │ ├── firmware-common.tar.gz armbian 固件 - │   └── kernel 内核目录 - │   └── 5.4.68 kernel 5.4.68-flippy-45+o @flippy - ├── device 设备文件夹 - │   ├── phicomm-n1 phicomm n1 设备目录 - │   │   ├── boot-phicomm-n1.tar.gz phicomm n1 启动文件 - │   │   └── root phicomm n1 rootfs 目录 - │   └── vplus vplus 设备目录 - │   ├── boot-vplus.tar.gz vplus 启动文件 - │   └── root vplus rootfs 目录 + │   ├── firmware-common.tar.gz armbian 固件 + │   ├── kernel 内核目录 + │   │   └── 5.4.86 kernel 5.4.86-flippy-51+o @flippy + │   ├── loader bootloader 目录 + │   └── root 公共 rootfs 目录 + ├── device 设备目录 + │   └── phicomm-n1 phicomm n1 设备目录 + │   ├── boot-phicomm-n1.tar.gz phicomm n1 启动文件 + │   └── root phicomm n1 rootfs 目录 ├── gen_openwrt 构建脚本 ├── LICENSE license ├── openwrt 固件目录( 待构建 ) ├── out 固件目录( 构建完成的 ) ├── tmp 临时目录,脚本转储 └── README.md readme - ``` * 使用参数 @@ -81,9 +79,9 @@ `sudo ./gen_openwrt -c` ,清理文件 `sudo ./gen_openwrt -d` ,使用默认配置 `sudo ./gen_openwrt -k latest` ,使用最新内核 - `sudo ./gen_openwrt -m vplus`,构建 vplus 固件 + `sudo ./gen_openwrt -m phicomm-n1`,构建 phicomm n1 固件 `sudo ./gen_openwrt -s 512` ,将 ROOTFS 分区大小设置为 512M - `sudo ./gen_openwrt -d -k 5.4.68 -m vplus` ,使用默认,构建 vplus 固件,并将内核版本设置为 5.4.68 + `sudo ./gen_openwrt -d -k 5.4.86 -m phicomm-n1` ,使用默认,构建 phicomm n1 固件,并将内核版本设置为 5.4.86 `sudo ./gen_openwrt -e` ,从 openwrt 目录中提取内核 `sudo ./gen_openwrt --mount` ,挂载 openwrt 目录中固件 diff --git a/common/firmware-common.tar.gz b/common/firmware-common.tar.gz new file mode 100644 index 00000000..6a7232ed Binary files /dev/null and b/common/firmware-common.tar.gz differ diff --git a/common/kernel/5.4.93/kernel-5.4.93.tar.gz b/common/kernel/5.4.93/kernel-5.4.93.tar.gz new file mode 100644 index 00000000..2ab037cb Binary files /dev/null and b/common/kernel/5.4.93/kernel-5.4.93.tar.gz differ diff --git a/common/kernel/5.4.93/modules-5.4.93.tar.gz b/common/kernel/5.4.93/modules-5.4.93.tar.gz new file mode 100644 index 00000000..f9aa3fa4 Binary files /dev/null and b/common/kernel/5.4.93/modules-5.4.93.tar.gz differ diff --git a/common/root/usr/bin/webd b/common/root/usr/bin/webd new file mode 100755 index 00000000..ea16ee5a Binary files /dev/null and b/common/root/usr/bin/webd differ diff --git a/device/phicomm-n1/boot-phicomm-n1.tar.gz b/device/phicomm-n1/boot-phicomm-n1.tar.gz new file mode 100644 index 00000000..e2040469 Binary files /dev/null and b/device/phicomm-n1/boot-phicomm-n1.tar.gz differ diff --git a/device/rk3328/boot-rk3328.tar.gz b/device/rk3328/boot-rk3328.tar.gz new file mode 100644 index 00000000..42eb17cf Binary files /dev/null and b/device/rk3328/boot-rk3328.tar.gz differ diff --git a/device/beikeyun/root/.keep b/device/rk3328/root/.keep similarity index 100% rename from device/beikeyun/root/.keep rename to device/rk3328/root/.keep diff --git a/device/s905x3/root/.keep b/device/s905x3/root/.keep deleted file mode 100644 index e69de29b..00000000 diff --git a/device/s9xxx/boot-s9xxx.tar.gz b/device/s9xxx/boot-s9xxx.tar.gz new file mode 100644 index 00000000..ea67c89e Binary files /dev/null and b/device/s9xxx/boot-s9xxx.tar.gz differ diff --git a/device/l1pro/root/.keep b/device/s9xxx/root/.keep similarity index 100% rename from device/l1pro/root/.keep rename to device/s9xxx/root/.keep diff --git a/device/vplus/boot-vplus.tar.gz b/device/vplus/boot-vplus.tar.gz new file mode 100644 index 00000000..e9e07074 Binary files /dev/null and b/device/vplus/boot-vplus.tar.gz differ diff --git a/gen_openwrt b/gen_openwrt index 48f22e13..40f65158 100755 --- a/gen_openwrt +++ b/gen_openwrt @@ -1,6 +1,6 @@ #!/usr/bin/env bash # -# Copyright (c) 2020 https://github.com/tuanqing/mknop +# Copyright (c) 2020-2021 https://github.com/tuanqing/mknop # # This is free software, licensed under the MIT. # See /LICENSE for more information. @@ -8,19 +8,25 @@ tmp="./tmp" out="./out" -minsize=512 # min root partition size +# min root partition size +minsize=512 die() { echo -e "${red}e${normal} => $1" + cleanup exit 1 } +no_dir() { + die "no such directory ${yellow}$1${normal}" +} + cleanup() { for x in $(lsblk | grep $(pwd) | grep -oE 'loop[0-9]+' | sort | uniq); do - umount -f /dev/${x}p[1-2] 2>/dev/null - umount -f /dev/$x 2>/dev/null + umount -f /dev/${x}p* 2>/dev/null losetup -d /dev/$x 2>/dev/null done + losetup -D rm -rf $tmp # do not clean up output dir after generated @@ -28,72 +34,65 @@ cleanup() { } get_devices() { - local path=$device_path - [ -d $path ] || return + [ -d $device_path ] || no_dir "$device_path" local len=0 IFS=$'\n' - for x in $(ls $path); do - [ -f $path/$x/boot-*.tar.gz ] && devices[len++]=$x + for x in $(ls $device_path); do + [ -f $device_path/$x/boot-*.tar.gz ] && devices[len++]=$x done } get_kernels() { - local path=$kernel_path - [ -d $path ] || return + [ -d $kernel_path ] || no_dir "$kernel_path" local len=0 IFS=$'\n' - for x in $(ls $path); do - [ -f $path/$x/kernel-*.tar.gz ] && [ -f $path/$x/modules-*.tar.gz ] \ - && kernels[len++]=$x + for x in $(ls $kernel_path); do + [ -f $kernel_path/$x/kernel-*.tar.gz ] && [ -f $kernel_path/$x/modules-*.tar.gz ] && + kernels[len++]=$x done } get_firmwares() { - local path=$firmware_path - [ -d $path ] || return + [ -d $firmware_path ] || no_dir "$firmware_path" local len=0 IFS=$'\n' - for x in $(ls $path); do + for x in $(ls $firmware_path); do firmwares[len++]=$x done } choose_device() { - local i=0 echo "device: " - choose_option "${devices[*]}" ${#devices[*]} - local opt=$? - device=${devices[opt]} + choose_option "${devices[*]}" + device=${devices[$?]} devices=($device) echo -e "${green}${device}${normal}\n" } choose_firmware() { - local i=0 echo "firmware: " - choose_option "${firmwares[*]}" ${#firmwares[*]} - local opt=$? - firmware=${firmwares[opt]} + choose_option "${firmwares[*]}" + firmware=${firmwares[$?]} echo -e "${green}${firmware}${normal}\n" } choose_kernel() { - local i=0 echo "kernel: " - choose_option "${kernels[*]}" ${#kernels[*]} - local opt=$? - kernel=${kernels[opt]} + choose_option "${kernels[*]}" + kernel=${kernels[$?]} kernels=($kernel) echo -e "${green}${kernel}${normal}\n" } choose_option() { local options=$1 - local len=$2 + local len=0 local cnt=0 + local i=0 for x in ${options[*]}; do echo "($((++i))) => $x" + ((len++)) done [ "$len" = 1 ] && return 0 @@ -108,12 +107,12 @@ choose_option() { break else ((cnt++)) - echo "${red}your choice is wrong, please try again${normal}" + echo -e "${red}your choice is wrong, please try again${normal}" sleep 1s fi done - [ $cnt = 3 ] && die "you type the wrong 3 times, the program automatically quit" + [ $cnt = 3 ] && echo && die "you type the wrong 3 times, the program automatically quit" return $opt } @@ -154,43 +153,44 @@ unpack_openwrt() { while true; do case "$suffix" in - xz) - xz -dc $path > $tmp/${firmware%.*} + xz) + xz -dc $path >$tmp/${firmware%.*} + path=$tmp/${firmware%.*} + suffix=${path##*.} + ;; + gz) + # special for .tar.gz + if ls $path | grep -q '.tar.gz$'; then + tar xzf $path -C $common_root + break + else + gzip -dc $path >$tmp/${firmware%.*} path=$tmp/${firmware%.*} suffix=${path##*.} + fi ;; - gz) # special for .tar.gz - if ls $path | grep -q '.tar.gz$'; then - tar xzf $path -C $common_root - break - else - gzip -dc $path > $tmp/${firmware%.*} - path=$tmp/${firmware%.*} - suffix=${path##*.} - fi - ;; - img|ext4) - do_losetup $path - if [ -d $mount/${loop_seq}p2 ]; then - cp -r $mount/${loop_seq}p2/* $common_root - # special for single partition image - elif [ -d $mount/${loop_seq}p1 ]; then - cp -r $mount/${loop_seq}p1/* $common_root - elif [ -d $mount/${loop_seq} ]; then - cp -r $mount/${loop_seq}/* $common_root - # - else - die "error unpack $path" - fi - break + img | ext4) + do_losetup $path + if [ -d $mount/${loop_seq}p2 ]; then + cp -r $mount/${loop_seq}p2/* $common_root + # special for single partition image + elif [ -d $mount/${loop_seq}p1 ]; then + cp -r $mount/${loop_seq}p1/* $common_root + elif [ -d $mount/${loop_seq} ]; then + cp -r $mount/${loop_seq}/* $common_root + else + die "error unpack $path" + fi + break ;; - *) - die "unsupported firmware format!" + *) + die "unsupported firmware format!" ;; esac done - + rm -rf $common_root/lib/modules/*/ + tar xzf ./common/firmware-common.tar.gz -C $common_root } unpack_armbian() { @@ -199,8 +199,8 @@ unpack_armbian() { device_final="$tmp/device/$device" mkdir -p $common_boot - tar xzf $path/kernel-*.tar.gz -C $common_boot 2>/dev/null - tar xzf ./common/firmware-common.tar.gz -C $common_root 2>/dev/null + tar xzf $path/kernel-*.tar.gz -C $common_boot #2>/dev/null + # tar xzf ./common/firmware-common.tar.gz -C $common_root #2>/dev/null mkdir -p ${device_final}/$kernel/{boot,root} cp -r $common_boot/* ${device_final}/$kernel/boot @@ -272,39 +272,47 @@ make_firmware() { fi ) - # do something else + # do something else for rootfs partition do_others "$mount/${loop_seq}p2" } } do_others() { - local path=$1 + local rootfs=$1 + [ -d $rootfs ] || no_dir "$rootfs" - mkdir -p $path/{boot,opt,run} - - local is_amlogic=false - local is_rockchip=false - - echo $amlogic | grep -iq $device && is_amlogic=true - echo $rockchip | grep -iq $device && is_rockchip=true + ( + cd $rootfs && mkdir -p {boot,opt,run} + + local is_amlogic=false + local is_rockchip=false + + echo $amlogic | grep -iq $device && is_amlogic=true + echo $rockchip | grep -iq $device && is_rockchip=true + + if [ $is_amlogic = true ]; then + printf 'pwm_meson' >etc/modules.d/pwm-meson + sed -i 's/ttyAMA0/ttyAML0/' etc/inittab + sed -i 's/ttyS0/tty0/' etc/inittab + elif [ $is_rockchip = true ]; then + sed -i 's/ttyAMA0/tty1/' etc/inittab + sed -i 's/ttyS0/ttyS2/' etc/inittab + [ -f etc/config/fstab ] && sed -i 's/vfat/ext4/' etc/config/fstab + fi - if [ $is_amlogic = true ]; then - printf 'pwm_meson' > $path/etc/modules.d/pwm-meson - sed -i 's/ttyAMA0/ttyAML0/' $path/etc/inittab - sed -i 's/ttyS0/tty0/' $path/etc/inittab - elif [ $is_rockchip = true ]; then - sed -i 's/ttyAMA0/tty1/' $path/etc/inittab - sed -i 's/ttyS0/ttyS2/' $path/etc/inittab - fi + if ! grep -q '/tmp/upgrade' etc/init.d/boot; then + sed -i '/kmodloader/i \\tmkdir -p \/tmp\/upgrade' etc/init.d/boot + fi + if ! grep -q 'ulimit -n' etc/init.d/boot; then + sed -i '/kmodloader/i \\tulimit -n 131072\n' etc/init.d/boot + fi - if ! grep -q '/tmp/upgrade' $path/etc/init.d/boot; then - sed -i '/kmodloader/i\\tmkdir -p \/tmp\/upgrade' $path/etc/init.d/boot - fi - if ! grep -q 'ulimit -n' $path/etc/init.d/boot; then - sed -i '/kmodloader/i\\tulimit -n 131072\n' $path/etc/init.d/boot - fi + [ -f etc/modules.d/usb-net-asix-ax88179 ] || printf 'ax88179_178a' >etc/modules.d/usb-net-asix-ax88179 + [ -f etc/modules.d/usb-net-rtl8150 ] || printf 'rtl8150' >etc/modules.d/usb-net-rtl8150 + [ -f etc/modules.d/usb-net-rtl8152 ] || printf 'r8152' >etc/modules.d/usb-net-rtl8152 + ) - chown -R 0:0 $path + chown -R 0:0 $rootfs } set_rootsize() { @@ -330,29 +338,7 @@ set_rootsize() { } extract_kernel() { - choose_firmware - - local path="$firmware_path/$firmware" - local suffix="${firmware##*.}" - - while true; do - case "$suffix" in - xz) - [ -d $tmp ] || mkdir -p $tmp - echo -e "${green}unpack${normal}" - xz -dc $path > $tmp/${firmware%.*} - path=$tmp/${firmware%.*} - suffix=${path##*.} - ;; - img) - do_losetup $path - break - ;; - *) - die "unsupported firmware format!" - ;; - esac - done + mount_image local kversion=$(ls $mount/${loop_seq}p2/lib/modules) local version=$(echo $kversion | grep -oE '^[4-5].[0-9]+.[0-9]+') @@ -360,11 +346,29 @@ extract_kernel() { echo -e "${green}kernel version${normal} => $kversion" mkdir -p $tmp/$version/{boot,root/lib} - cp -r $mount/${loop_seq}p1/{config-*,initrd.img-*,System.map-*,uInitrd-*,vmlinuz-*} $tmp/$version/boot + + cp -r $mount/${loop_seq}p1/{config-*,initrd.img-*,System.map-*} $tmp/$version/boot + if [ -f $mount/${loop_seq}p1/uInitrd-* ]; then + cp $mount/${loop_seq}p1/uInitrd-* $tmp/$version/boot + else + [ -f $mount/${loop_seq}p1/uInitrd ] && + cp $mount/${loop_seq}p1/uInitrd $tmp/$version/boot || + die "no uInitrd found in $firmware!" + mv $tmp/$version/boot/uInitrd $tmp/$version/boot/uInitrd-$kversion + fi + if [ -f $mount/${loop_seq}p1/vmlinuz-* ]; then + cp $mount/${loop_seq}p1/vmlinuz-* $tmp/$version/boot + else + [ -f $mount/${loop_seq}p1/zImage ] && + cp $mount/${loop_seq}p1/zImage $tmp/$version/boot || + die "no vmlinuz found in $firmware!" + mv $tmp/$version/boot/zImage $tmp/$version/boot/vmlinuz-$kversion + fi + cp -r $mount/${loop_seq}p2/lib/modules $tmp/$version/root/lib ( - cd tmp/$version/root/lib/modules/*/ + cd $tmp/$version/root/lib/modules/*/ rm -rf *.ko find ./ -type f -name '*.ko' -exec ln -s {} ./ \; ) @@ -387,13 +391,14 @@ extract_kernel() { [ -f $tmp/$version/kernel-$version.tar.gz ] && [ -f $tmp/$version/modules-$version.tar.gz ] && { [ -d $kernel_path/$version ] && { - echo && read -p "this version $(echo -e "${yellow}${version}${normal}") already exists, do you want to replace it? [Y/n] " yn && echo + echo && read -p "this version $(echo -e "${yellow}${version}${normal}") already exists, do you want to replace it? [Y/n] " yn && echo case "$yn" in - n|N) yn=n ;; - *) yn=y ;; + n | N) yn=n ;; + *) yn=y ;; esac } [[ ! "$yn" || "$yn" = "y" ]] && { + [ -d $kernel_path ] || mkdir -p $kernel_path cp -r $tmp/$version $kernel_path chown -R 1000:1000 $kernel_path/$version echo -e "${green}done${normal}" @@ -409,21 +414,28 @@ mount_image() { local path="$firmware_path/$firmware" local suffix="${firmware##*.}" + [ -d $tmp ] || mkdir -p $tmp + while true; do case "$suffix" in - xz) - [ -d $tmp ] || mkdir -p $tmp - echo -e "${green}unpack${normal}" - xz -dc $path > $tmp/${firmware%.*} - path=$tmp/${firmware%.*} - suffix=${path##*.} + xz) + echo -e "${green}unpack${normal}" + xz -dc $path >$tmp/${firmware%.*} + path=$tmp/${firmware%.*} + suffix=${path##*.} ;; - img) - do_losetup $path - break + gz) + echo -e "${green}unpack${normal}" + gzip -dc $path >$tmp/${firmware%.*} + path=$tmp/${firmware%.*} + suffix=${path##*.} ;; - *) - die "unsupported firmware format!" + img) + do_losetup $path + break + ;; + *) + die "unsupported firmware format!" ;; esac done @@ -455,8 +467,8 @@ yellow="\033[33m" normal="\033[0m" allwinner="vplus" -amlogic="phicomm-n1 s905x3" -rockchip="beikeyun l1pro" +amlogic="phicomm-n1 s9xxx" +rockchip="rk3328" device_path="./device" kernel_path="./common/kernel" @@ -473,73 +485,75 @@ get_kernels while [ "$1" ]; do case "$1" in - -h|--help) - usage - exit + -h | --help) + usage + exit ;; - -c|--clean) - cleanup - echo -e "${green}done${normal}" - exit + -c | --clean) + cleanup + echo -e "${green}clean up done${normal}" + exit ;; - -d|--default) - : ${device:="all"} - : ${firmware:=${firmwares[0]}} - : ${kernel:="all"} - : ${rootsize:=$minsize} + -d | --default) + : ${device:="all"} + : ${firmware:=${firmwares[0]}} + : ${kernel:="all"} + : ${rootsize:=$minsize} ;; - -e) - extract_kernel - exit + -e) + extract_kernel + exit ;; - -k) - kernel=$2 - if [ -f $kernel_path/$kernel/kernel-*.tar.gz ] && \ - [ -f $kernel_path/$kernel/modules-*.tar.gz ]; then - kernels=($kernel) - shift - elif [ "$kernel" = "all" ]; then - [ ${#kernels[*]} = 0 ] && unset kernel - shift - elif [ "$kernel" = "latest" ]; then - [ ${#kernels[*]} = 0 ] && unset kernel || kernel=${kernels[-1]} - shift - else - die "invalid kernel ${red}$kernel${normal}" - fi + -k) + kernel=$2 + if [ -f $kernel_path/$kernel/kernel-*.tar.gz ] && + [ -f $kernel_path/$kernel/modules-*.tar.gz ]; then + kernels=($kernel) + shift + elif [ "$kernel" = "all" ]; then + shift + elif [ "$kernel" = "latest" ]; then + [ ${#kernels[*]} = 0 ] || kernel=${kernels[-1]} + shift + else + die "invalid kernel ${red}$kernel${normal}" + fi ;; - -m) - device=$2 - if [ -f $device_path/$device/boot-*.tar.gz ]; then - devices=($device) - shift - elif [ "$device" = "all" ]; then - [ ${#devices[*]} = 0 ] && unset device - shift - else - die "invalid device ${red}$device${normal}" - fi + -m) + device=$2 + if [ -f $device_path/$device/boot-*.tar.gz ]; then + devices=($device) + shift + elif [ "$device" = "all" ]; then + shift + else + die "invalid device ${red}$device${normal}" + fi ;; - --mount) - mount_image - exit + --mount) + mount_image + exit ;; - -s|--size) - rootsize=$2 - if [[ "$rootsize" -ge "$minsize" ]] 2>/dev/null; then - shift - else - die "invalid rootsize ${red}$rootsize${normal}" - fi + -s | --size) + rootsize=$2 + if [[ "$rootsize" -ge "$minsize" ]] 2>/dev/null; then + shift + else + die "invalid rootsize ${red}$rootsize${normal}" + fi ;; - *) - usage - die "invalid option ${red}$1${normal}" + *) + usage + die "invalid option ${red}$1${normal}" ;; esac shift done +[ ${#devices[*]} = 0 ] && die "there is no device in ${yellow}${device_path:2}${normal} directory!" +[ ${#firmwares[*]} = 0 ] && die "there is no firmware in ${yellow}${firmware_path:2}${normal} directory!" +[ ${#kernels[*]} = 0 ] && die "there is no kernel in ${yellow}${kernel_path:2}${normal} directory!" + [ "$device" ] && { echo -en "device\t\t=> " echo -e "${devices[@]}" | sed 's/ /, /g' @@ -550,11 +564,7 @@ done echo -e "${kernels[@]}" | sed 's/ /, /g' } [ "$rootsize" ] && echo -e "rootsize\t=> $rootsize" -[ "$device" ] || [ "$firmware" ] || [ "$kernel" ] || [ "$rootsize" ] && echo - -[ ${#devices[*]} = 0 ] && die "there is no device in ${yellow}${device_path:2}${normal} directory!" -[ ${#firmwares[*]} = 0 ] && die "there is no firmware in ${yellow}${firmware_path:2}${normal} directory!" -[ ${#kernels[*]} = 0 ] && die "there is no kernel in ${yellow}${kernel_path:2}${normal} directory!" +[ "$device" ] || [ "$firmware" ] || [ "$kernel" ] || [ "$rootsize" ] && echo [ "$device" ] || choose_device [ "$firmware" ] || choose_firmware @@ -566,13 +576,13 @@ unpack_openwrt for kernel in ${kernels[*]}; do for device in ${devices[*]}; do - { - echo -e "${green}unpack armbian${normal} => $device @ $kernel" - unpack_armbian - echo -e "${green}make firmware${normal}\t=> $device @ $kernel" - make_firmware - echo -e "${green}done${normal}\t\t=> $device @ $kernel" - } & + { + echo -e "${green}unpack armbian${normal} ( $device @ $kernel )" + unpack_armbian + echo -e "${green}make firmware${normal} ( $device @ $kernel )" + make_firmware + echo -e "${green}done${normal} ( $device @ $kernel )" + } & done done