Files
quectel-rgmii-toolkit/ipk-source/sdxpinn-mount-fix/CONTROL/postinst
2024-10-05 18:57:50 -04:00

138 lines
4.8 KiB
Bash

#!/bin/ash
# Define the main package name and list file location
PKG_NAME="sdxpinn-mount-fix"
LIST_FILE="/usr/lib/opkg/info/${PKG_NAME}.list"
DETECTED_PACKAGES_FILE="/tmp/detected_packages.tmp"
# Function to handle bundled packages post-install
handle_bundled_postinst() {
local bundled_package_name="$1"
# Use the target package name for default_postinst instead of $0
if [ "${IPKG_NO_SCRIPT}" = "1" ]; then
return 0
fi
# Source the necessary functions only once
if [ -s "${IPKG_INSTROOT}/lib/functions.sh" ]; then
. "${IPKG_INSTROOT}/lib/functions.sh"
else
echo "Error: ${IPKG_INSTROOT}/lib/functions.sh not found."
return 1
fi
echo "Executing default_postinst for bundled package: $bundled_package_name"
default_postinst "$bundled_package_name" $@
return $?
}
# Replace distfeeds.conf with non-working sources commented out
if [ -f /tmp/distfeeds.conf ]; then
# Backup and replace distfeeds.conf
[ -f /etc/opkg/distfeeds.conf ] && cp /etc/opkg/distfeeds.conf /etc/opkg/distfeeds.conf.bak
mv /tmp/distfeeds.conf /etc/opkg/distfeeds.conf
echo "Replaced /etc/opkg/distfeeds.conf with the custom version."
else
echo "Error: /tmp/distfeeds.conf not found. Cannot replace /etc/opkg/distfeeds.conf."
exit 1
fi
echo "Combo package cleanup in progress..."
# Remove entries in the .list file that refer to opkg control files and specific files
if [ -f "$LIST_FILE" ]; then
# Remove opkg control file entries and specific bundled paths
sed -i '/^\/usr\/lib\/opkg\/info\//d' "$LIST_FILE"
sed -i '/^\/usr\/lib\/libinotifytools.so.0.4.1$/d' "$LIST_FILE"
sed -i '/^\/usr\/bin\/inotifywait$/d' "$LIST_FILE"
sed -i '/^\/usr\/lib\/libinotifytools.so$/d' "$LIST_FILE"
sed -i '/^\/etc\/init.d\/add_opkg_status_bundled$/d' "$LIST_FILE"
sed -i '/^\/tmp\/distfeeds.conf$/d' "$LIST_FILE"
sed -i '/^\/usr\/lib\/libinotifytools.so.0$/d' "$LIST_FILE"
echo "Removed unnecessary file entries from $LIST_FILE."
else
echo "Warning: ${LIST_FILE} not found."
fi
# Make the init scripts and binaries executable
chmod +x /etc/init.d/mount-fix /etc/init.d/init-overlay-watchdog /etc/init.d/add_opkg_status_bundled /usr/sbin/init-overlay-watchdog.sh
# Enable and start the services
echo "Starting services..."
service mount-fix enable
service mount-fix start
sleep 1
service init-overlay-watchdog enable
service init-overlay-watchdog start
echo -e "\e[32m sdxpinn-mount-fix installed! Here is the new file structure! \e[0m"
echo -e "\e[32m ============================================================ \e[0m"
mount && df -h
echo -e "\e[32m ============================================================ \e[0m"
echo -e "\e[32m sdxpinn-mount-fix installed! New file structure above! \e[0m"
# Handle bundled packages based on detection results
BUNDLED_PACKAGES="libinotifytools inotifywait"
# Check if the detected packages file exists and read its content
if [ -f "$DETECTED_PACKAGES_FILE" ]; then
SKIP_PACKAGES=$(cat "$DETECTED_PACKAGES_FILE")
echo "Skipping the following pre-installed bundled packages: $SKIP_PACKAGES"
else
SKIP_PACKAGES=""
fi
# Update the bundled packages in the add_opkg_status_bundled script dynamically
BUNDLED_PACKAGES_INFO=""
for bundled_package_name in $BUNDLED_PACKAGES; do
if echo "$SKIP_PACKAGES" | grep -q "$bundled_package_name"; then
echo "Skipping bundled package: $bundled_package_name"
else
handle_bundled_postinst "$bundled_package_name"
BUNDLED_PACKAGES_INFO="$BUNDLED_PACKAGES_INFO
Package: $bundled_package_name
Version: 3.20.11.0-1
Depends: $( [ "$bundled_package_name" = "inotifywait" ] && echo "libc, libinotifytools" || echo "libc")
Status: install user installed
Architecture: aarch64_cortex-a53
Installed-Time: $(date +%s)"
fi
done
# If BUNDLED_PACKAGES_INFO is empty, remove the add_opkg_status_bundled script and do not start it
if [ -z "$BUNDLED_PACKAGES_INFO" ]; then
echo "All bundled packages are pre-installed. Removing /etc/init.d/add_opkg_status_bundled."
rm -f /etc/init.d/add_opkg_status_bundled
else
echo "Updating /etc/init.d/add_opkg_status_bundled with missing bundled package info."
echo "#!/bin/ash /etc/rc.common
USE_PROCD=1
START=99
STOP=15
STATUS_FILE=\"/usr/lib/opkg/status\"
BUNDLED_PACKAGES_INFO=\"$BUNDLED_PACKAGES_INFO\"
start_service() {
procd_open_instance
procd_set_param command /bin/sh -c \"(
echo 'Waiting for 4 seconds...'
sleep 4
echo 'Adding missing bundled package entries to \$STATUS_FILE...'
echo \"\$BUNDLED_PACKAGES_INFO\" >> \"\$STATUS_FILE\"
sync
rm -f /etc/init.d/add_opkg_status_bundled
) &\"
procd_close_instance
}" > /etc/init.d/add_opkg_status_bundled
chmod +x /etc/init.d/add_opkg_status_bundled
service add_opkg_status_bundled enable
service add_opkg_status_bundled start
fi
exit 0