Last active
September 29, 2022 03:14
-
-
Save Ansen/e5a7478b6a75362ae7249a289612a995 to your computer and use it in GitHub Desktop.
[aliyundrive-webdav](https://github.com/messense/aliyundrive-webdav) upgrade script for openwrt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
# Author: An Shen | |
# Date: 2022-02-16 | |
# Version: 1.0 | |
# Description: aliyundrive-webdav upgrade script | |
# Usage: ./aliyundrive-webdav-upgrade.sh | |
# Reference: https://www.github.com/ansen | |
. /etc/profile >/dev/null 2>&1 | |
function log(){ | |
echo "[$(date +'%Y-%m-%d %H:%M:%S')] - $1" | |
} | |
function get_latest_info(){ | |
local latest_info_file='/tmp/aliyundrive-webdav-latest-info.json' | |
wget -q -O ${latest_info_file} https://api.github.com/repos/messense/aliyundrive-webdav/releases/latest | |
[[ $? -ne 0 ]] && log "Failed to get latest info" && exit 1 | |
latest_version=$(grep tag_name ${latest_info_file} | cut -d '"' -f 4| sed 's/^v//g') | |
latest_comments=$(grep body ${latest_info_file} | cut -d '"' -f 4) | |
rm -f ${latest_info_file} | |
} | |
function upgrade() { | |
local hardware=$(uname -m) | |
local base_download_url="https://github.com/messense/aliyundrive-webdav/releases/download" | |
local aliyundrive_webdav_download_url="${base_download_url}/v${latest_version}/aliyundrive-webdav_${latest_version}-1_${hardware}.ipk" | |
local luci_app_download_url="${base_download_url}/v${latest_version}/luci-app-aliyundrive-webdav_${latest_version}_all.ipk" | |
rm -f /tmp/aliyundrive-webdav.ipk /tmp/luci-app-aliyundrive-webdav.ipk | |
log "Downloading aliyundrive-webdav_${latest_version}-1_${hardware}.ipk ..." | |
wget -q -O /tmp/aliyundrive-webdav.ipk $aliyundrive_webdav_download_url | |
[[ $? -ne 0 ]] && log "Download aliyundrive-webdav.ipk failed" && exit 1 | |
log "Downloading luci-app-aliyundrive-webdav_${latest_version}_all.ipk ..." | |
wget -q -O /tmp/luci-app-aliyundrive-webdav.ipk $luci_app_download_url | |
[[ $? -ne 0 ]] && log "Download luci-app-aliyundrive-webdav.ipk failed" && exit 1 | |
log "Installing aliyundrive-webdav ..." | |
opkg install /tmp/aliyundrive-webdav.ipk | |
[[ $? -ne 0 ]] && log "Install aliyundrive-webdav.ipk failed" && exit 1 | |
log "Installing luci-app-aliyundrive-webdav ..." | |
opkg install /tmp/luci-app-aliyundrive-webdav.ipk | |
[[ $? -ne 0 ]] && log "Install luci-app-aliyundrive-webdav.ipk failed" && exit 1 | |
log "Upgrade aliyundrive-webdav success" | |
rm -f /tmp/aliyundrive-webdav.ipk /tmp/luci-app-aliyundrive-webdav.ipk | |
rm -f /etc/config/aliyundrive-webdav-opkg | |
} | |
function main(){ | |
confirm="$1" | |
current=$(aliyundrive-webdav -V| awk '{print $NF}') | |
get_latest_info | |
if [ "$latest_version" == "$current" ];then | |
log "No update available" | |
exit 0 | |
fi | |
log "New version available: $latest_version" | |
log "upgrade comments: $latest_comments" | |
if [ "x$confirm" == "x-y" ];then | |
choice="y" | |
else | |
log "Do you want to upgrade? [y/n]" | |
read -p "Please input your choice: " choice | |
fi | |
case $choice in | |
y|Y) | |
upgrade | |
;; | |
n|N) | |
log "Exit" | |
exit 0 | |
;; | |
*) | |
log "Invalid input" | |
exit 1 | |
;; | |
esac | |
} | |
main "$@" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment