Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/bin/sh
- # Create temporary files to store package information with timestamps
- temp_file_user=$(mktemp)
- temp_file_ok=$(mktemp)
- count_user=0
- count_ok=0
- # Get total number of packages
- total_packages=$(opkg list-installed | wc -l)
- echo "Total packages to process: $total_packages"
- # Create files to store package names
- user_packages=""
- ok_packages=""
- # Loop through installed packages and get their installation time and status
- for pkg in $(opkg list-installed | awk '{print $1}'); do
- status=$(opkg status $pkg | grep -E 'Status' | awk '{print $3}')
- installed_time=$(opkg status $pkg | grep 'Installed-Time' | awk '{print $2}')
- # Convert timestamp to YYYY-MM-DD HH:MM:SS format
- installed_datetime=$(date -d @$installed_time +'%Y-%m-%d %H:%M:%S')
- if [ "$status" = "user" ]; then
- echo "$installed_datetime $pkg" >> $temp_file_user
- count_user=$((count_user + 1))
- user_packages="$user_packages $pkg"
- else
- echo "$installed_datetime $pkg" >> $temp_file_ok
- count_ok=$((count_ok + 1))
- ok_packages="$ok_packages $pkg"
- fi
- echo "($((count_user + count_ok))/$total_packages) U: $count_user, P: $count_ok package: $pkg"
- done
- # Sort the temporary files by date and write to the output file
- {
- echo "## User Installed Packages"
- sort $temp_file_user
- echo ""
- echo "## PREINSTALL OK Installed Packages"
- sort $temp_file_ok
- echo ""
- echo "Total user installed packages: $count_user"
- echo "Total preinstall ok installed packages: $count_ok"
- } > /tmp/installed_packages_with_time.txt
- # Write the package names to separate files
- echo $user_packages > /tmp/packagename-user.txt
- echo $ok_packages > /tmp/packagename-ok.txt
- # Clean up the temporary files
- rm $temp_file_user $temp_file_ok
- # Check if nano is installed, if not use cat and more
- if command -v nano > /dev/null; then
- nano /tmp/installed_packages_with_time.txt
- else
- cat /tmp/installed_packages_with_time.txt | more
- fi
Advertisement
Add Comment
Please, Sign In to add comment