Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revision Previous revision
Next revision
Previous revision
docs:guide-user:advanced:opkg_extras [2021/09/22 02:27] – [Instructions] vgaeteradocs:guide-user:advanced:opkg_extras [2023/11/30 19:06] (current) – [Instructions] vgaetera
Line 1: Line 1:
 ====== Opkg extras ====== ====== Opkg extras ======
-{{section>meta:infobox:howto_links#cli_skills&noheader&nofooter&noeditbutton}}+{{section>meta:infobox:howto_links#basic_skills&noheader&nofooter&noeditbutton}}
  
 ===== Introduction ===== ===== Introduction =====
-  * This instruction extends [[docs:guide-user:additional-software:opkg|Opkg]] functionality. +  * This instruction extends the functionality of [[docs:guide-user:additional-software:opkg|Opkg]].
-  * Follow [[docs:guide-user:advanced:hotplug_extras|Hotplug extras]] to extend Hotplug functionality. +
-  * Follow [[docs:guide-user:advanced:uci_extras|UCI extras]] to extend UCI functionality.+
   * Follow the [[docs:guide-user:advanced:opkg_extras#automated|automated]] section for quick setup.   * Follow the [[docs:guide-user:advanced:opkg_extras#automated|automated]] section for quick setup.
  
Line 11: Line 9:
   * Save, restore and roll back Opkg profiles.   * Save, restore and roll back Opkg profiles.
   * Support automatic and custom profiles.   * Support automatic and custom profiles.
 +  * Support RWM, overlay and extroot setup.
   * Identify user-removed/installed packages.   * Identify user-removed/installed packages.
   * Restore automatically after firmware upgrade.   * Restore automatically after firmware upgrade.
   * Upgrade all upgradable packages.   * Upgrade all upgradable packages.
-  * Find new configurations.+  * Fix symbolic links for installed alternatives. 
 +  * Find new configurations for upgraded packages.
  
 ===== Implementation ===== ===== Implementation =====
   * Wrap Opkg calls to provide a seamless invocation method.   * Wrap Opkg calls to provide a seamless invocation method.
   * Rely on [[docs:guide-user:base-system:uci|UCI]] and [[https://github.com/openwrt/openwrt/blob/master/package/base-files/Makefile#L47|backup defaults]] to store and manage profiles.   * Rely on [[docs:guide-user:base-system:uci|UCI]] and [[https://github.com/openwrt/openwrt/blob/master/package/base-files/Makefile#L47|backup defaults]] to store and manage profiles.
-  * Identify package types with [[man>grep(1)|grep]] and [[man>find(1)|find]], and overlay with [[man>mount(8)|mount]]. +  * Identify package types with [[man>grep(1)|grep]] and [[man>find(1)|find]], and RWM with [[man>mount(8)|mount]]. 
-  * Support importing [[https://github.com/openwrt/openwrt/blob/master/package/base-files/files/sbin/sysupgrade#L245-L251|user-installed]] packages from [[docs:techref:sysupgrade|Sysupgrade]]. +  * Support importing [[https://github.com/openwrt/openwrt/blob/master/package/base-files/files/sbin/sysupgrade#L249-L255|user-installed]] packages from [[docs:techref:sysupgrade|Sysupgrade]]. 
-  * Use [[docs:guide-user:base-system:hotplug|Hotplug]] to detect WAN connectivity and trigger profile restore.+  * Use [[docs:guide-user:advanced:hotplug_extras|Hotplug extras]] to detect WAN connectivity and trigger profile restore.
   * Utilize lockfiles with [[https://github.com/openwrt/openwrt/blob/master/package/utils/busybox/patches/220-add_lock_util.patch|lock]] to avoid race conditions and loops.   * Utilize lockfiles with [[https://github.com/openwrt/openwrt/blob/master/package/utils/busybox/patches/220-add_lock_util.patch|lock]] to avoid race conditions and loops.
   * Perform [[man>reboot(8)|reboot]] to apply changes after automatic profile restore.   * Perform [[man>reboot(8)|reboot]] to apply changes after automatic profile restore.
-  * Write and read non-interactive logs with [[docs:guide-user:base-system:log.essentials|Syslog]] for troubleshooting. 
   * Fetch the default profile to restore and roll back from UCI, unless specified manually.   * Fetch the default profile to restore and roll back from UCI, unless specified manually.
   * Take precedence for remove over install to avoid package conflicts while restoring profile.   * Take precedence for remove over install to avoid package conflicts while restoring profile.
Line 31: Line 30:
  
 ===== Commands ===== ===== Commands =====
-Opkg sub-command ^ Description ^ +Sub-command ^ Description ^ 
-| ''**help**''Show Opkg extras. |+| ''**init**'' | Initialize Opkg configuration. | 
 +| ''**uci** [<prof>] < <uciprof>''Import Opkg profile from stdin or file to UCI. |
 | ''**import** [<bakprof>]'' | Import Opkg profile from Sysupgrade backup to UCI. | | ''**import** [<bakprof>]'' | Import Opkg profile from Sysupgrade backup to UCI. |
-| ''**save** [<prof>]'' | Save the current Opkg profile to UCI. | +| ''**save**'' | Save the current Opkg profile to UCI. | 
-| ''**restore** [<prof>]'' | Restore Opkg profile:\\ ''custom''custom profile configured manually,\\ ''auto'' or none automatic profile. |+| ''**restore** [<prof>]'' | Restore Opkg profile:\\ ''main'' or none default profile,\\ ''init''RWM/minimal profile,\\ ''custom'' - custom profile. |
 | ''**rollback** [<prof>]'' | Roll back Opkg profile:\\ remove user-installed packages,\\ install user-removed packages,\\ skip upgraded packages. | | ''**rollback** [<prof>]'' | Roll back Opkg profile:\\ remove user-installed packages,\\ install user-removed packages,\\ skip upgraded packages. |
-| ''**upgr** [<pkgtype>]'' | Upgrade packages by type:\\ ''au'' or none - all upgradable,\\ ''oi'' - overlay-installed. |+| ''**upgr** [<pkgtype>]'' | Upgrade packages by type:\\ ''ai'' or none - all installed,\\ ''oi'' - overlay-installed. |
 | ''**export** [<pkgtype>]'' | Export packages by type:\\ ''ai'' or none - all installed,\\ ''au'' - all upgradable,\\ ''ri'' - ROM-installed,\\ ''wr'' - RWM-removed,\\ ''wi'' - RWM-installed,\\ ''or'' - overlay-removed,\\ ''oi'' - overlay-installed,\\ ''ur'' - user-removed,\\ ''ui'' - user-installed,\\ ''pr'' - profile-removed,\\ ''pi'' - profile-installed. | | ''**export** [<pkgtype>]'' | Export packages by type:\\ ''ai'' or none - all installed,\\ ''au'' - all upgradable,\\ ''ri'' - ROM-installed,\\ ''wr'' - RWM-removed,\\ ''wi'' - RWM-installed,\\ ''or'' - overlay-removed,\\ ''oi'' - overlay-installed,\\ ''ur'' - user-removed,\\ ''ui'' - user-installed,\\ ''pr'' - profile-removed,\\ ''pi'' - profile-installed. |
-| ''**proc** <cmd> <pkgs>'' | Process packages one by one with the given sub-command. |+| ''**proc** <cmd> <pkgs>'' | Process packages from stdin with the given sub-command. |
 | ''**reinstall** <pkgs>'' | Reinstall specific packages. | | ''**reinstall** <pkgs>'' | Reinstall specific packages. |
-| ''**newconf** [<path>]''Find new configurations. | +| ''**altlink**''Fix symbolic links for installed alternatives. | 
-| ''**uci** [<prof>] < <uciprof>''Initialize Opkg profile from stdin or file. | +| ''**newconf** [<path>]''Find new configurations for upgraded packages. |
-| ''**uciget** <cmd> [<defaults>]'' | Get Opkg defaults for the given sub-command. |+
  
 ===== Instructions ===== ===== Instructions =====
Line 52: Line 51:
 opkg() { opkg() {
 local OPKG_CMD="${1}" local OPKG_CMD="${1}"
-if ! type opkg_"${OPKG_CMD}" &> /dev/null +local OPKG_UCI="$(uci -q get opkg.defaults."${OPKG_CMD}")" 
-then command opkg "${@}" +case "${OPKG_CMD}" in 
-else shift +(init|uci|import|save|restore|rollback|upgr\ 
-opkg_"${OPKG_CMD}" "${@}" +|export|proc|reinstall|altlink|newconf) opkg_"${@}" ;; 
-fi+(*) command opkg "${@}" ;; 
 +esac
 } }
  
-opkg_help() { +opkg_init() { 
-cat << EOI +uci import opkg < /dev/null 
-opkg [help|import|save|restore|rollback|upgr\ +uci -q batch << EOI 
-|export|proc|reinstall|newconf|uci|uciget] +set opkg.defaults='opkg' 
-opkg upgr [au|oi] +set opkg.defaults.import='/etc/backup/installed_packages.txt' 
-opkg export [ai|au|ri|wr|wi|or|oi|ur|ui|pr|pi]+set opkg.defaults.restore='init main' 
 +set opkg.defaults.rollback='main' 
 +set opkg.defaults.upgr='ai' 
 +set opkg.defaults.export='ai' 
 +set opkg.defaults.proc='--force-depends' 
 +set opkg.defaults.reinstall='--force-reinstall' 
 +set opkg.defaults.newconf='/etc' 
 +EOI 
 +
 + 
 +opkg_uci() { 
 +local OPKG_OPT="${1:-${OPKG_UCI}}" 
 +local OPKG_OPT="${OPKG_OPT:-main}" 
 +if ! uci -q get opkg > /dev/null 
 +then opkg init 
 +fi 
 +uci -q batch << EOI 
 +delete opkg.'${OPKG_OPT}' 
 +set opkg.'${OPKG_OPT}'='opkg' 
 +$(sed -r -e "s/^(.*)\s(.*)$/
 +del_list opkg.'${OPKG_OPT}'.'\2'='\1'\n\ 
 +add_list opkg.'${OPKG_OPT}'.'\2'='\1'/"
 +commit opkg
 EOI EOI
 } }
  
 opkg_import() { opkg_import() {
-local OPKG_BAK="${1:-/etc/backup/installed_packages.txt}" +local OPKG_OPT="${1:-${OPKG_UCI}}" 
-if grep -q -e "^overlayfs:" /etc/mtab +if [ -e "${OPKG_OPT}" ] 
-then local OPKG_DEST="overlay" +then sed -n -r -e "s/\s(overlay|unknown)$/
-else local OPKG_DEST="unknown" +\tipkg/p" "${OPKG_OPT}" \ 
-fi +| opkg uci main
-if [ -e "${OPKG_BAK}" ] +
-then sed -n -e "s/\s${OPKG_DEST}$/\tipkg/p" "${OPKG_BAK}" \ +
-| opkg uci+
 fi fi
 } }
  
 opkg_save() { opkg_save() {
-local OPKG_PROF="$(opkg uciget "${OPKG_CMD}" auto "${1}")"+local OPKG_WR="$(opkg export wr)" 
 +local OPKG_WI="$(opkg export wi)"
 local OPKG_UR="$(opkg export ur)" local OPKG_UR="$(opkg export ur)"
 local OPKG_UI="$(opkg export ui)" local OPKG_UI="$(opkg export ui)"
 +if uci -q get fstab.rwm > /dev/null \
 +&& grep -q -e "\s/rwm\s" /etc/mtab
 +then {
 +sed -e "s/$/\trpkg/" "${OPKG_WR}"
 +sed -e "s/$/\tipkg/" "${OPKG_WI}"
 +} | opkg uci init
 +fi
 { {
 sed -e "s/$/\trpkg/" "${OPKG_UR}" sed -e "s/$/\trpkg/" "${OPKG_UR}"
 sed -e "s/$/\tipkg/" "${OPKG_UI}" sed -e "s/$/\tipkg/" "${OPKG_UI}"
-} | opkg uci "${OPKG_PROF}" +} | opkg uci main 
-rm -f "${OPKG_UR}" "${OPKG_UI}" +rm -f "${OPKG_WR}" "${OPKG_WI}" "${OPKG_UR}" "${OPKG_UI}"
-local OPKG_PROF="rwm" +
-local OPKG_WR="$(opkg export wr)" +
-local OPKG_WI="$(opkg export wi)" +
-+
-sed -e "s/$/\trpkg/" "${OPKG_WR}+
-sed -e "s/$/\tipkg/" "${OPKG_WI}" +
-} | opkg uci "${OPKG_PROF}" +
-rm -f "${OPKG_WR}" "${OPKG_WI}"+
 } }
  
 opkg_restore() { opkg_restore() {
-local OPKG_PROF="$(opkg uciget "${OPKG_CMD}" auto "${1}")"+local OPKG_OPT="${1:-${OPKG_UCI}}" 
 +local OPKG_CONF="${OPKG_OPT}" 
 +for OPKG_CONF in ${OPKG_CONF} 
 +do
 local OPKG_AI="$(opkg export ai)" local OPKG_AI="$(opkg export ai)"
 local OPKG_PR="$(opkg export pr)" local OPKG_PR="$(opkg export pr)"
 local OPKG_PI="$(opkg export pi)" local OPKG_PI="$(opkg export pi)"
-opkg proc remove $(grep -x -f "${OPKG_AI}" "${OPKG_PR}") +grep -x -f "${OPKG_AI}" "${OPKG_PR}" \ 
-opkg proc install $(grep -v -x -f "${OPKG_AI}" "${OPKG_PI}")+opkg proc remove 
 +grep -v -x -f "${OPKG_AI}" "${OPKG_PI}" 
 +| opkg proc install
 rm -f "${OPKG_AI}" "${OPKG_PR}" "${OPKG_PI}" rm -f "${OPKG_AI}" "${OPKG_PR}" "${OPKG_PI}"
 +done
 } }
  
 opkg_rollback() { opkg_rollback() {
-local OPKG_PROF="$(opkg uciget "${OPKG_CMD}" auto "${1}")"+local OPKG_OPT="${1:-${OPKG_UCI}}" 
 +local OPKG_CONF="${OPKG_OPT}"
 local OPKG_UR="$(opkg export ur)" local OPKG_UR="$(opkg export ur)"
 local OPKG_UI="$(opkg export ui)" local OPKG_UI="$(opkg export ui)"
 local OPKG_PR="$(opkg export pr)" local OPKG_PR="$(opkg export pr)"
 local OPKG_PI="$(opkg export pi)" local OPKG_PI="$(opkg export pi)"
-opkg restore "${OPKG_PROF}" +if uci -q get opkg."${OPKG_CONF}" > /dev/null 
-opkg proc remove $(grep -v -x -f "${OPKG_PI}" "${OPKG_UI}") +then opkg restore "${OPKG_CONF}" 
-opkg proc install $(grep -v -x -f "${OPKG_PR}" "${OPKG_UR}")+grep -v -x -f "${OPKG_PI}" "${OPKG_UI}" \ 
 +opkg proc remove 
 +grep -v -x -f "${OPKG_PR}" "${OPKG_UR}" 
 +| opkg proc install 
 +fi
 rm -f "${OPKG_UR}" "${OPKG_UI}" "${OPKG_PR}" "${OPKG_PI}" rm -f "${OPKG_UR}" "${OPKG_UI}" "${OPKG_PR}" "${OPKG_PI}"
 } }
  
 opkg_upgr() { opkg_upgr() {
-local OPKG_ARG="${1:-au}" +local OPKG_OPT="${1:-${OPKG_UCI}}" 
-if ! type opkg_"${OPKG_CMD}_${OPKG_ARG}" &> /dev/null +case "${OPKG_OPT}" in 
-then opkg help +(ai|oi) opkg_"${OPKG_CMD}"_type ;; 
-else shift +esac | opkg proc upgrade
-opkg_"${OPKG_CMD}_${OPKG_ARG}" "${@}" +
-fi+
 } }
  
-opkg_upgr_au() {+opkg_upgr_type() {
 local OPKG_AI="$(opkg export ai)" local OPKG_AI="$(opkg export ai)"
-local OPKG_AU="$(opkg export au)" 
-opkg proc upgrade $(grep -x -f "${OPKG_AI}" "${OPKG_AU}") 
-rm -f "${OPKG_AI}" "${OPKG_AU}" 
-} 
- 
-opkg_upgr_oi() { 
 local OPKG_OI="$(opkg export oi)" local OPKG_OI="$(opkg export oi)"
 local OPKG_AU="$(opkg export au)" local OPKG_AU="$(opkg export au)"
-opkg proc upgrade $(grep -x -f "${OPKG_OI}" "${OPKG_AU}"+case "${OPKG_OPT::1}" in 
-rm -f "${OPKG_OI}" "${OPKG_AU}"+(a) grep -x -f "${OPKG_AI}" "${OPKG_AU}" ;; 
 +(ogrep -x -f "${OPKG_OI}" "${OPKG_AU}" ;; 
 +esac 
 +rm -f "${OPKG_AI}" "${OPKG_OI}" "${OPKG_AU}"
 } }
  
 opkg_export() { opkg_export() {
-local OPKG_ARG="${1:-ai}" +local OPKG_OPT="${1:-${OPKG_UCI}}" 
-local OPKG_EXP="$(mktemp -t opkg.XXXXXX)" +local OPKG_TEMP="$(mktemp -t opkg.XXXXXX)" 
-if ! type opkg_"${OPKG_CMD}_${OPKG_ARG}" &> /dev/null +case "${OPKG_OPT}" in 
-then opkg help +(ai|au) opkg_"${OPKG_CMD}"_cmd ;; 
-else shift +(ri|wr|wi|or|oi) opkg_"${OPKG_CMD}"_type ;; 
-opkg_"${OPKG_CMD}_${OPKG_ARG}" "${@}" > "${OPKG_EXP}" +(ur|ui) opkg_"${OPKG_CMD}"_run ;; 
-cat << EOI +(pr|pi) opkg_"${OPKG_CMD}"_uci ;; 
-${OPKG_EXP} +esac > "${OPKG_TEMP}" 
-EOI +echo "${OPKG_TEMP}"
-fi+
 } }
  
-opkg_export_ai() { +opkg_export_cmd() { 
-opkg list-installed "${@}" | sed -e "s/\s.*$//"+local OPKG_TYPE 
 +case "${OPKG_OPT:1}" in 
 +(i) OPKG_TYPE="installed" ;; 
 +(u) OPKG_TYPE="upgradable" ;; 
 +esac 
 +opkg list-"${OPKG_TYPE}" 
 +| sed -e "s/\s.*$//"
 } }
  
-opkg_export_au() { +opkg_export_type() { 
-opkg list-upgradable "${@}" | sed -e "s/\s.*$//"+local OPKG_INFO="/usr/lib/opkg/info" 
 +local OPKG_TYPE 
 +case "${OPKG_OPT::1}" in 
 +(r) OPKG_INFO="/rom${OPKG_INFO}" ;; 
 +(w) OPKG_INFO="/rwm/upper${OPKG_INFO}" ;; 
 +(o) OPKG_INFO="/overlay/upper${OPKG_INFO}" ;; 
 +esac 
 +case "${OPKG_OPT:1}" in 
 +(r) OPKG_TYPE="c" ;; 
 +(i) OPKG_TYPE="f" ;; 
 +esac 
 +find "${OPKG_INFO}" -name "*.control"
 +-type "${OPKG_TYPE}" 2> /dev/null \ 
 +| sed -e "s/^.*\///;s/\.control$//"
 } }
  
-opkg_export_ri() { +opkg_export_run() {
-local OPKG_INFO="/rom/usr/lib/opkg/info" +
-find "${OPKG_INFO}" -name "*.control" -type "f" 2> /dev/null \ +
-| sed -e "s/^.*\//;s/\.control$//" +
-+
- +
-opkg_export_wr() { +
-local OPKG_INFO="/rwm/upper/usr/lib/opkg/info" +
-find "${OPKG_INFO}" -name "*.control" -type "c" 2> /dev/null \ +
-| sed -e "s/^.*\//;s/\.control$//" +
-+
- +
-opkg_export_wi() { +
-local OPKG_INFO="/rwm/upper/usr/lib/opkg/info" +
-find "${OPKG_INFO}" -name "*.control" -type "f" 2> /dev/null \ +
-| sed -e "s/^.*\//;s/\.control$//" +
-+
- +
-opkg_export_or() { +
-local OPKG_INFO="/overlay/upper/usr/lib/opkg/info" +
-find "${OPKG_INFO}" -name "*.control" -type "c" 2> /dev/null \ +
-| sed -e "s/^.*\//;s/\.control$//" +
-+
- +
-opkg_export_oi() { +
-local OPKG_INFO="/overlay/upper/usr/lib/opkg/info" +
-find "${OPKG_INFO}" -name "*.control" -type "f" 2> /dev/null \ +
-| sed -e "s/^.*\//;s/\.control$//" +
-+
- +
-opkg_export_ur() {+
 local OPKG_AI="$(opkg export ai)" local OPKG_AI="$(opkg export ai)"
 local OPKG_RI="$(opkg export ri)" local OPKG_RI="$(opkg export ri)"
-grep -v -x -f "${OPKG_AI}" "${OPKG_RI}"+case "${OPKG_OPT:1}" in 
 +(r) grep -v -x -f "${OPKG_AI}" "${OPKG_RI}" ;; 
 +(i) grep -v -x -f "${OPKG_RI}" "${OPKG_AI}" ;; 
 +esac
 rm -f "${OPKG_AI}" "${OPKG_RI}" rm -f "${OPKG_AI}" "${OPKG_RI}"
 } }
  
-opkg_export_ui() { +opkg_export_uci() { 
-local OPKG_AI="$(opkg export ai)+local OPKG_TYPE 
-local OPKG_RI="$(opkg export ri)" +case "${OPKG_OPT:1}in 
-grep -v -x -f "${OPKG_RI}" "${OPKG_AI}+(rOPKG_TYPE="rpkg;; 
-rm -f "${OPKG_AI}" "${OPKG_RI}+(i) OPKG_TYPE="ipkg;; 
-+esac 
- +uci -q get opkg."${OPKG_CONF}"."${OPKG_TYPE}" 
-opkg_export_pr() { +| sed -e "s/\s/\n/g"
-uci -q get opkg."${OPKG_PROF}".rpkg | sed -e "s/\s/\n/g" +
-+
- +
-opkg_export_pi() { +
-uci -q get opkg."${OPKG_PROF}".ipkg | sed -e "s/\s/\n/g"+
 } }
  
 opkg_proc() { opkg_proc() {
-local OPKG_OPT="$(opkg uciget "${OPKG_CMD}" --force-depends)"+local OPKG_OPT="${OPKG_UCI}"
 local OPKG_CMD="${1:?}" local OPKG_CMD="${1:?}"
 local OPKG_PKG local OPKG_PKG
-shift +while read -r OPKG_PKG 
-for OPKG_PKG in "${@}" +do opkg "${OPKG_CMD}" "${OPKG_PKG}" ${OPKG_OPT}
-do +
-if [ "${OPKG_PKG%%-*}" = "dnsmasq" -a "${OPKG_CMD}" = "remove"+
-then /etc/init.d/dnsmasq stop +
-fi +
-opkg "${OPKG_CMD}" "${OPKG_PKG}" ${OPKG_OPT} +
-if [ "${OPKG_PKG%%-*}" = "grep"+
-then hash -r +
-fi+
 done done
 } }
  
 opkg_reinstall() { opkg_reinstall() {
-local OPKG_OPT="$(opkg uciget "${OPKG_CMD}" --force-reinstall)"+local OPKG_OPT="${OPKG_UCI}"
 opkg install "${@}" ${OPKG_OPT} opkg install "${@}" ${OPKG_OPT}
 } }
  
-opkg_newconf() { +opkg_altlink() { 
-local OPKG_PATH="${1:-/etc}" +sed -n -e "/^Alternatives:/
-find "${OPKG_PATH}" -name "*-opkg"+{s/^\S*\s*//;s/,\s/\n/gp}" /usr/lib/opkg/status \ 
 +| sort -n -t ":"
 +| while IFS=":" read -r OPKG_PRIO OPKG_LINK OPKG_ALT 
 +do ln -f -s "${OPKG_ALT}" "${OPKG_LINK}" 
 +done
 } }
  
-opkg_uci() { +opkg_newconf() { 
-local OPKG_PROF="$(opkg uciget "${OPKG_CMD}" auto "${1}")" +local OPKG_OPT="${1:-${OPKG_UCI}}" 
-if ! uci -q show opkg > /dev/null +find "${OPKG_OPT}" -name "*-opkg"
-then uci import opkg < /dev/null +
-fi +
-uci -q batch << EOI +
-delete opkg.${OPKG_PROF} +
-set opkg.defaults=opkg +
-set opkg.custom=opkg +
-set opkg.${OPKG_PROF}=opkg +
-$(sed -r -e "s/^(.*)\s(.*)$/\ +
-add_list opkg.${OPKG_PROF}.\2=\1/"+
-commit opkg +
-EOI +
-+
- +
-opkg_uciget() { +
-local OPKG_UCI="$(uci -q get opkg.defaults."${1}")" +
-local OPKG_UCI="${3:-${OPKG_UCI}}" +
-local OPKG_UCI="${OPKG_UCI:-${2}}" +
-cat << EOI +
-${OPKG_UCI} +
-EOI+
 } }
 EOF EOF
 . /etc/profile.d/opkg.sh . /etc/profile.d/opkg.sh
  
-Restore packages automatically+Configure hotplug
 mkdir -p /etc/hotplug.d/online mkdir -p /etc/hotplug.d/online
 cat << "EOF" > /etc/hotplug.d/online/50-opkg-restore cat << "EOF" > /etc/hotplug.d/online/50-opkg-restore
-if [ ! -e /etc/opkg-restore ] \+OPKG_CONF="$(uci -q get opkg.defaults.restore)" 
 +for OPKG_CONF in ${OPKG_CONF} 
 +do if [ ! -e /etc/opkg-restore-"${OPKG_CONF}" ] \
 && lock -n /var/lock/opkg-restore \ && lock -n /var/lock/opkg-restore \
 +&& sleep 10 \
 && opkg update && opkg update
-then +then . /etc/profile.d/opkg.sh 
-. /etc/profile.d/opkg.sh +opkg restore "${OPKG_CONF}" &> 
-if uci -q get opkg.rwm &> /dev/null +/var/log/opkg-restore-"${OPKG_CONF}" 
-then opkg restore rwm +touch /etc/opkg-restore-"${OPKG_CONF}"
-else opkg restore +
-fi +
-touch /etc/opkg-restore+
 lock -u /var/lock/opkg-restore lock -u /var/lock/opkg-restore
-reboot+case "${OPKG_CONF}" in 
 +(init) ;; 
 +(*) reboot ;; 
 +esac 
 +break
 fi fi
 +done
 EOF EOF
 cat << "EOF" >> /etc/sysupgrade.conf cat << "EOF" >> /etc/sysupgrade.conf
Line 305: Line 297:
 opkg rollback opkg rollback
  
-# Set up a custom Opkg profile +# Set up Opkg profiles 
-uci set opkg.defaults.restore="custom" +uci set opkg.defaults.restore="init custom" 
-uci -q delete opkg.custom.rpkg+uci set opkg.init="opkg" 
 +uci add_list opkg.init.ipkg="losetup" 
 +uci add_list opkg.init.ipkg="parted" 
 +uci add_list opkg.init.ipkg="resize2fs" 
 +uci set opkg.custom="opkg"
 uci add_list opkg.custom.rpkg="dnsmasq" uci add_list opkg.custom.rpkg="dnsmasq"
 uci add_list opkg.custom.rpkg="ppp" uci add_list opkg.custom.rpkg="ppp"
-uci -q delete opkg.custom.ipkg 
 uci add_list opkg.custom.ipkg="curl" uci add_list opkg.custom.ipkg="curl"
 uci add_list opkg.custom.ipkg="diffutils" uci add_list opkg.custom.ipkg="diffutils"
Line 316: Line 311:
 uci commit opkg uci commit opkg
  
-# Check hotplug log +# Check Opkg log 
-logread -e hotplug+tail -f /var/log/opkg-*
  
 # Upgrade packages # Upgrade packages
 opkg update opkg update
 opkg upgr opkg upgr
 +
 +# Maintenance
 +opkg altlink
 +opkg newconf
 </code> </code>
  
 ===== Automated ===== ===== Automated =====
 <code bash> <code bash>
-uclient-fetch -O opkg-extras.sh "https://openwrt.org/_export/code/docs/guide-user/advanced/opkg_extras?codeblock=0"+wget -U "" -O opkg-extras.sh "https://openwrt.org/_export/code/docs/guide-user/advanced/opkg_extras?codeblock=0"
 . ./opkg-extras.sh . ./opkg-extras.sh
 </code> </code>
  
  • Last modified: 2023/11/30 19:06
  • by vgaetera