Instantly share code, notes, and snippets.

Embed
What would you like to do?
#!/bin/sh
###############################################
###############################################
##
## MOVED TO GITHUB REPOSITORY!!
## https://github.com/tavinus/opkg-upgrade
## THIS WILL NOT BE UPDATED!!
##
###############################################
###############################################
###############################################
# Gustavo Arnosti Neves
#
# May / 2017
#
# Upgrade packages listed by:
# opkg list-upgradable
#
# Will list packages and ask for confirmation
# Use ./opkg-upgrade.sh --help for more info
#
# This Script:
# https://github.com/tavinus/opkg-upgrade
#
# Simple oneliner version:
# https://gist.github.com/tavinus/997d896cebd575bfaf1706ce6e701c2d
#
#
# How to install using CURL or WGET:
#
# NOTE: curl/wget may fail because of missing SSL certificates.
# You may choose to ignore the certificates check using
# 'curl -k' or 'wget --no-check-certificate'.
# Or you will need to fix your /etc/ssl/certs/ca-certificates.crt installation.
#
# Local install to current dir on './opkg-upgrade.sh':
# TGT_INST='./opkg-upgrade.sh' && wget 'https://raw.githubusercontent.com/tavinus/opkg-upgrade/master/opkg-upgrade.sh' -O "$TGT_INST" && chmod 755 "$TGT_INST"
# TGT_INST='./opkg-upgrade.sh' && curl -L 'https://raw.githubusercontent.com/tavinus/opkg-upgrade/master/opkg-upgrade.sh' -o "$TGT_INST" && chmod 755 "$TGT_INST"
#
# System install to '/usr/sbin/opkg-upgrade' (no .sh extension) :
# TGT_INST='/usr/sbin/opkg-upgrade' && wget 'https://raw.githubusercontent.com/tavinus/opkg-upgrade/master/opkg-upgrade.sh' -O "$TGT_INST" && chmod 755 "$TGT_INST"
# TGT_INST='/usr/sbin/opkg-upgrade' && curl -L 'https://raw.githubusercontent.com/tavinus/opkg-upgrade/master/opkg-upgrade.sh' -o "$TGT_INST" && chmod 755 "$TGT_INST"
### Initialization
OPKGUPVERSION="0.1.2"
OPKGBIN="$(which opkg 2>/dev/null)"
BANNERSTRING="Simple OPKG Updater v$OPKGUPVERSION"
### Silly SH
TRUE=0
FALSE=1
### Execution FLAGS
CHECK_UPDATES_FLAG=$TRUE
FORCE_FLAG=$FALSE
### This scripts name
OPKGUP_NAME="$(basename $0)"
### Execution vars, populated later
PACKS=""
PACKS_NAMES=""
PACKS_COUNT=""
### Main function
main() {
print_banner
check_for_opkg
if should_run_update; then
opkg_update
else
message_ends "Ignoring package lists update"
fi
opkg_upgradable
if ! opkg_has_update; then
echo $'\nNo packages to install!\n'
exit 0
fi
echo $'\n'"Packages available for upgrade: $PACKS_COUNT"$'\n'
echo -e "$PACKS"
if ! no_confirm; then
if ! confirm_upgrade; then
echo $'Cancelled by user!\n'
exit 3
fi
else
echo ""
fi
do_upgrade
exit $?
}
### Parse CLI options
get_options() {
while :; do
case "$1" in
-V|--version|--Version)
print_banner 'nopadding' ; exit 0 ;;
-h|--help|--Help)
print_help ; exit 0 ;;
-n|--no-pkg-update)
CHECK_UPDATES_FLAG=$FALSE ; shift ;;
-f|--force)
FORCE_FLAG=$TRUE ; shift ;;
*)
check_invalid_opts "$1" ; break ;;
esac
done
}
check_invalid_opts() {
if [[ ! -z "$1" ]]; then
print_banner
echo "Invalid Option: $1"$'\n'
exit 2
fi
return 0
}
### Printing functions
print_banner() {
local str=""
if [[ "$1" = 'nopadding' ]]; then
str="$BANNERSTRING"
else
str=$'\n'"$BANNERSTRING"$'\n'
fi
echo "$str"
}
print_help() {
print_banner
echo "Usage: $OPKGUP_NAME [-n,-f]
Options:
-V, --version Show program name and version and exits
-h, --help Show this help screen and exits
-n, --no-opkg-update Skip opkg update at the beginning,
may not find packages if not up to date
-f, --force Do not ask for confirmation,
will update everything available
Notes:
Parameters should not be grouped.
You must pass each parameter on its own.
The order is irrelevant.
Examples:
$OPKGUP_NAME -nf # INVALID PARAMETER
$OPKGUP_NAME -n -f # VALID PARAMETERS
"
}
message_starts() {
echo -n ".... | $1"$'\r'
}
message_ends() {
[[ -z "$1" ]] && mess="" || mess="$1"
echo "Done | $mess"
}
### Sanity checks
check_for_opkg() {
if [[ ! -x "$OPKGBIN" ]]; then
echo $'ERROR! Could not find or run OPKG binary\n'
exit 1
fi
}
### OPKG Update
opkg_update() {
message_starts "Updating package lists"
"$OPKGBIN" update >/dev/null;
message_ends
}
should_run_update() {
return $CHECK_UPDATES_FLAG
}
### OPKG Upgradable
opkg_upgradable() {
message_starts "Getting upgradable packages list"
PACKS="$($OPKGBIN list-upgradable)"
#PACKS="$(cat pkg-example.txt)" # testing
PACKS_NAMES="$(echo -ne "$PACKS" | awk '{ printf "%s ", $1 }')"
PACKS_COUNT="$(echo "$PACKS" | wc -l)"
message_ends
}
opkg_has_update() {
[[ -z "$PACKS" ]] && return $FALSE
return $TRUE
}
### CLI interaction
no_confirm() {
return $FORCE_FLAG
}
confirm_upgrade() {
read -p $'\nProceed with upgrade? (Y/y to proceed) ' -n 1 -r
echo $'\n'
if [[ "$REPLY" = Y || "$REPLY" = y ]]; then
return $TRUE
fi
return $FALSE
}
### Upgrade packages
do_upgrade() {
message_starts $'Upgrading packages\n\n'
"$OPKGBIN" install $PACKS_NAMES
ret=$?
echo ""
message_ends $'Upgrade finished\n'
echo $'Please check for config file conflicts!\n'
return $ret
}
### Start execution
get_options "$@"
main
exit 20 # should never get here
@tavinus

This comment has been minimized.

Owner

tavinus commented May 10, 2017

MOVED TO GITHUB REPOSITORY!!

https://github.com/tavinus/opkg-upgrade

--

Help example:

# ./opkg-upgrade.sh -h

Simple OPKG Updater v0.1.2

Usage: opkg-upgrade.sh [-n,-f]

Options:
  -V, --version           Show program name and version and exits
  -h, --help              Show this help screen and exits
  -n, --no-opkg-update    Skip opkg update at the beginning,
                          may not find packages if not up to date
  -f, --force             Do not ask for confirmation,
                          will update everything available

Notes:
  Parameters should not be grouped.
  You must pass each parameter on its own.
  The order is irrelevant.

Examples:
  opkg-upgrade.sh -nf     # INVALID PARAMETER
  opkg-upgrade.sh -n -f   # VALID PARAMETERS

Example run:

# ./opkg-upgrade.sh

Simple OPKG Updater v0.1.2

Done | Updating package lists
Done | Getting upgradable packages list

Packages available for upgrade: 23

luci-app-statistics - git-17.126.47277-596f476-1 - git-17.129.29271-6467df3-1
luci-app-adblock - git-17.126.47277-596f476-1 - git-17.129.29271-6467df3-1
luci-lib-ip - git-17.126.47277-596f476-1 - git-17.129.29271-6467df3-1
luci-app-samba - git-17.126.47277-596f476-1 - git-17.129.29271-6467df3-1
luci-theme-bootstrap - git-17.126.47277-596f476-1 - git-17.129.29271-6467df3-1
luci-app-qos - git-17.126.47277-596f476-1 - git-17.129.29271-6467df3-1
luci-app-firewall - git-17.126.47277-596f476-1 - git-17.129.29271-6467df3-1
luci-app-diag-core - git-17.126.47277-596f476-1 - git-17.129.29271-6467df3-1
luci-proto-ppp - git-17.126.47277-596f476-1 - git-17.129.29271-6467df3-1
luci-mod-admin-full - git-17.126.47277-596f476-1 - git-17.129.29271-6467df3-1
luci-base - git-17.126.47277-596f476-1 - git-17.129.29271-6467df3-1
luci-app-commands - git-17.126.47277-596f476-1 - git-17.129.29271-6467df3-1
luci-app-vnstat - git-17.126.47277-596f476-1 - git-17.129.29271-6467df3-1
luci-proto-ipv6 - git-17.126.47277-596f476-1 - git-17.129.29271-6467df3-1
luci-app-wol - git-17.126.47277-596f476-1 - git-17.129.29271-6467df3-1
luci-app-upnp - git-17.126.47277-596f476-1 - git-17.129.29271-6467df3-1
luci-app-minidlna - git-17.126.47277-596f476-1 - git-17.129.29271-6467df3-1
luci-lib-nixio - git-17.126.47277-596f476-1 - git-17.129.29271-6467df3-1
luci-lib-jsonc - git-17.126.47277-596f476-1 - git-17.129.29271-6467df3-1
luci-app-p910nd - git-17.126.47277-596f476-1 - git-17.129.29271-6467df3-1
luci - git-17.126.47277-596f476-1 - git-17.129.29271-6467df3-1
luci-app-transmission - git-17.126.47277-596f476-1 - git-17.129.29271-6467df3-1
luci-app-openvpn - git-17.126.47277-596f476-1 - git-17.129.29271-6467df3-1

Proceed with upgrade? (Y/y to proceed) y

.... | Upgrading packages

Upgrading luci-app-statistics on root from git-17.126.47277-596f476-1 to git-17.129.29271-6467df3-1...
Downloading http://downloads.lede-project.org/releases/17.01.1/packages/mipsel_74kc/luci/luci-app-statistics_git-17.129.29271-6467df3-1_all.ipk
Upgrading luci-app-adblock on root from git-17.126.47277-596f476-1 to git-17.129.29271-6467df3-1...
Downloading http://downloads.lede-project.org/releases/17.01.1/packages/mipsel_74kc/luci/luci-app-adblock_git-17.129.29271-6467df3-1_all.ipk
Upgrading luci-lib-ip on root from git-17.126.47277-596f476-1 to git-17.129.29271-6467df3-1...
Downloading http://downloads.lede-project.org/releases/17.01.1/packages/mipsel_74kc/luci/luci-lib-ip_git-17.129.29271-6467df3-1_mipsel_74kc.ipk
Upgrading luci-app-samba on root from git-17.126.47277-596f476-1 to git-17.129.29271-6467df3-1...
Downloading http://downloads.lede-project.org/releases/17.01.1/packages/mipsel_74kc/luci/luci-app-samba_git-17.129.29271-6467df3-1_all.ipk
Upgrading luci-theme-bootstrap on root from git-17.126.47277-596f476-1 to git-17.129.29271-6467df3-1...
Downloading http://downloads.lede-project.org/releases/17.01.1/packages/mipsel_74kc/luci/luci-theme-bootstrap_git-17.129.29271-6467df3-1_all.ipk
Upgrading luci-app-qos on root from git-17.126.47277-596f476-1 to git-17.129.29271-6467df3-1...
Downloading http://downloads.lede-project.org/releases/17.01.1/packages/mipsel_74kc/luci/luci-app-qos_git-17.129.29271-6467df3-1_all.ipk
Upgrading luci-app-firewall on root from git-17.126.47277-596f476-1 to git-17.129.29271-6467df3-1...
Downloading http://downloads.lede-project.org/releases/17.01.1/packages/mipsel_74kc/luci/luci-app-firewall_git-17.129.29271-6467df3-1_all.ipk
Upgrading luci-app-diag-core on root from git-17.126.47277-596f476-1 to git-17.129.29271-6467df3-1...
Downloading http://downloads.lede-project.org/releases/17.01.1/packages/mipsel_74kc/luci/luci-app-diag-core_git-17.129.29271-6467df3-1_all.ipk
Upgrading luci-proto-ppp on root from git-17.126.47277-596f476-1 to git-17.129.29271-6467df3-1...
Downloading http://downloads.lede-project.org/releases/17.01.1/packages/mipsel_74kc/luci/luci-proto-ppp_git-17.129.29271-6467df3-1_all.ipk
Upgrading luci-mod-admin-full on root from git-17.126.47277-596f476-1 to git-17.129.29271-6467df3-1...
Downloading http://downloads.lede-project.org/releases/17.01.1/packages/mipsel_74kc/luci/luci-mod-admin-full_git-17.129.29271-6467df3-1_mipsel_74kc.ipk
Upgrading luci-base on root from git-17.126.47277-596f476-1 to git-17.129.29271-6467df3-1...
Downloading http://downloads.lede-project.org/releases/17.01.1/packages/mipsel_74kc/luci/luci-base_git-17.129.29271-6467df3-1_mipsel_74kc.ipk
Upgrading luci-app-commands on root from git-17.126.47277-596f476-1 to git-17.129.29271-6467df3-1...
Downloading http://downloads.lede-project.org/releases/17.01.1/packages/mipsel_74kc/luci/luci-app-commands_git-17.129.29271-6467df3-1_all.ipk
Upgrading luci-app-vnstat on root from git-17.126.47277-596f476-1 to git-17.129.29271-6467df3-1...
Downloading http://downloads.lede-project.org/releases/17.01.1/packages/mipsel_74kc/luci/luci-app-vnstat_git-17.129.29271-6467df3-1_all.ipk
Upgrading luci-proto-ipv6 on root from git-17.126.47277-596f476-1 to git-17.129.29271-6467df3-1...
Downloading http://downloads.lede-project.org/releases/17.01.1/packages/mipsel_74kc/luci/luci-proto-ipv6_git-17.129.29271-6467df3-1_all.ipk
Upgrading luci-app-wol on root from git-17.126.47277-596f476-1 to git-17.129.29271-6467df3-1...
Downloading http://downloads.lede-project.org/releases/17.01.1/packages/mipsel_74kc/luci/luci-app-wol_git-17.129.29271-6467df3-1_all.ipk
Upgrading luci-app-upnp on root from git-17.126.47277-596f476-1 to git-17.129.29271-6467df3-1...
Downloading http://downloads.lede-project.org/releases/17.01.1/packages/mipsel_74kc/luci/luci-app-upnp_git-17.129.29271-6467df3-1_all.ipk
Upgrading luci-app-minidlna on root from git-17.126.47277-596f476-1 to git-17.129.29271-6467df3-1...
Downloading http://downloads.lede-project.org/releases/17.01.1/packages/mipsel_74kc/luci/luci-app-minidlna_git-17.129.29271-6467df3-1_all.ipk
Upgrading luci-lib-nixio on root from git-17.126.47277-596f476-1 to git-17.129.29271-6467df3-1...
Downloading http://downloads.lede-project.org/releases/17.01.1/packages/mipsel_74kc/luci/luci-lib-nixio_git-17.129.29271-6467df3-1_mipsel_74kc.ipk
Upgrading luci-lib-jsonc on root from git-17.126.47277-596f476-1 to git-17.129.29271-6467df3-1...
Downloading http://downloads.lede-project.org/releases/17.01.1/packages/mipsel_74kc/luci/luci-lib-jsonc_git-17.129.29271-6467df3-1_mipsel_74kc.ipk
Upgrading luci-app-p910nd on root from git-17.126.47277-596f476-1 to git-17.129.29271-6467df3-1...
Downloading http://downloads.lede-project.org/releases/17.01.1/packages/mipsel_74kc/luci/luci-app-p910nd_git-17.129.29271-6467df3-1_all.ipk
Upgrading luci on root from git-17.126.47277-596f476-1 to git-17.129.29271-6467df3-1...
Downloading http://downloads.lede-project.org/releases/17.01.1/packages/mipsel_74kc/luci/luci_git-17.129.29271-6467df3-1_all.ipk
Upgrading luci-app-transmission on root from git-17.126.47277-596f476-1 to git-17.129.29271-6467df3-1...
Downloading http://downloads.lede-project.org/releases/17.01.1/packages/mipsel_74kc/luci/luci-app-transmission_git-17.129.29271-6467df3-1_all.ipk
Upgrading luci-app-openvpn on root from git-17.126.47277-596f476-1 to git-17.129.29271-6467df3-1...
Downloading http://downloads.lede-project.org/releases/17.01.1/packages/mipsel_74kc/luci/luci-app-openvpn_git-17.129.29271-6467df3-1_all.ipk
Configuring luci-app-statistics.
Configuring luci-lib-jsonc.
Configuring luci-app-adblock.
Configuring luci-lib-nixio.
Configuring luci-lib-ip.
Configuring luci-base.
Configuring luci-mod-admin-full.
Configuring luci-app-firewall.
Configuring luci-app-samba.
Configuring luci-theme-bootstrap.
Configuring luci-app-qos.
Configuring luci-app-diag-core.
Configuring luci-proto-ppp.
Configuring luci-app-commands.
Configuring luci-app-vnstat.
Configuring luci-proto-ipv6.
Configuring luci-app-wol.
Configuring luci-app-upnp.
Configuring luci-app-minidlna.
Configuring luci-app-p910nd.
Configuring luci.
Configuring luci-app-transmission.
Configuring luci-app-openvpn.
Collected errors:
 * resolve_conffiles: Existing conffile /etc/config/luci_statistics is different from the conffile in the new package. The new conffile will be placed at /etc/config/luci_statistics-opkg.
 * resolve_conffiles: Existing conffile /etc/config/luci is different from the conffile in the new package. The new conffile will be placed at /etc/config/luci-opkg.

Done | Upgrade finished

Please check for config file conflicts!
  

And then:

# ./opkg-upgrade.sh -f -n

Simple OPKG Updater v0.1.2

Done | Ignoring package lists update
Done | Getting upgradable packages list

No packages to install!
@tavinus

This comment has been minimized.

Owner

tavinus commented May 11, 2017

I wonder if there is a real difference on using opkg upgrade instead of opkg install in this case.
I mean, we are running a list of pre-installed packages anyways and opkg install gives me better output messages (I think).
If anyone know the answer, let me know.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment