Skip to content

Commit

Permalink
update-packages: improvements (to be tested)
Browse files Browse the repository at this point in the history
  • Loading branch information
gsanchietti committed Jul 24, 2024
1 parent 07bdb41 commit b0daf4f
Showing 1 changed file with 22 additions and 29 deletions.
51 changes: 22 additions & 29 deletions packages/ns-plug/files/update-packages
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,15 @@
# --force-stable: force update from stable channel even if the system has a subscription
#

# Function to perform cleanup
error_exit() {
echo "$1" | logger -s -t update-packages
exit 1
}

cleanup() {
if [ -f /etc/opkg/distfeeds.conf.orig ]; then
echo "Restoring original distfeeds.conf" | logger -s -t update-packages
mv /etc/opkg/distfeeds.conf.orig /etc/opkg/distfeeds.conf
mv /etc/opkg/distfeeds.conf.orig /etc/opkg/distfeeds.conf || error_exit "Failed to restore distfeeds.conf"
fi
}

Expand All @@ -26,52 +30,41 @@ if [ "$1" = "--force-stable" ]; then
echo "Flag force-stable is set" | logger -s -t update-packages
fi

channel='dev'
# channel is subscription if "$(uci -q get ns-plug.config.system_id)" is not empty
if [ -n "$(uci -q get ns-plug.config.system_id)" ]; then
channel='subscription'
fi
channel=$([ -n "$(uci -q get ns-plug.config.system_id)" ] && echo 'subscription' || echo 'dev')

# Set up trap to call cleanup function on script exit
trap cleanup EXIT

# Create temporary opkg configuration
if [ "$force" -gt 0 ]; then
if [ "$force" -eq 1 ]; then
channel='stable'
# Preserve original distfeed.conf
cp /etc/opkg/distfeeds.conf /etc/opkg/distfeeds.conf.orig

if [ $? -ne 0 ]; then
echo "Failed to backup distfeeds.conf" | logger -s -t update-packages
exit 1
fi
cp /etc/opkg/distfeeds.conf /etc/opkg/distfeeds.conf.orig || error_exit "Failed to backup distfeeds.conf"

echo "Creating temporary distfeed configuration" | logger -s -t update-packages
# make sure to replace dev with stable in case we are using a dev image
cat /rom/etc/opkg/distfeeds.conf | sed 's/dev/stable/g' > /etc/opkg/distfeeds.conf

if [ $? -ne 0 ]; then
echo "Failed to create temporary opkg configuration" | logger -s -t update-packages
exit 1
fi
sed 's/dev/stable/g' /rom/etc/opkg/distfeeds.conf > /etc/opkg/distfeeds.conf || error_exit "Failed to create temporary opkg configuration"
fi

echo "Updating packages from $channel channel" | logger -s -t update-packages

# Update metadata
opkg update 2>&1 | logger -s -t update-packages

if [ $? -ne 0 ]; then
echo "Failed to update metadata" | logger -s -t update-packages
exit 1
if ! opkg update 2>&1 | logger -s -t update-packages; then
error_exit "Failed to update metadata"
fi

# List upgradable packages
opkg list-upgradable | cut -f 1 -d ' ' | xargs -r opkg upgrade 2>&1 | logger -s -t update-packages
upgradable_packages=$(opkg list-upgradable | cut -f 1 -d ' ')

if [ $? -ne 0 ]; then
echo "Failed to upgrade packages" | logger -s -t update-packages
exit 1
fi
if [ -n "$upgradable_packages" ]; then
echo "Upgrading packages: $upgradable_packages" | logger -s -t update-packages
if ! opkg upgrade $upgradable_packages 2>&1; then
error_exit "Failed to upgrade packages"
fi
else
echo "No packages to upgrade" | logger -s -t update-packages
fi

echo "Update successful" | logger -s -t update-packages
exit 0

0 comments on commit b0daf4f

Please sign in to comment.