sa-kt

openwrt opkg 一覧表示 プリインのパッケージと、あとからインストールしたのを分類

Dec 6th, 2024 (edited)
166
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 1.99 KB | Source Code | 0 0
  1. #!/bin/sh
  2. # Create temporary files to store package information with timestamps
  3. temp_file_user=$(mktemp)
  4. temp_file_ok=$(mktemp)
  5. count_user=0
  6. count_ok=0
  7.  
  8. # Get total number of packages
  9. total_packages=$(opkg list-installed | wc -l)
  10. echo "Total packages to process: $total_packages"
  11.  
  12. # Create files to store package names
  13. user_packages=""
  14. ok_packages=""
  15.  
  16. # Loop through installed packages and get their installation time and status
  17. for pkg in $(opkg list-installed | awk '{print $1}'); do
  18.     status=$(opkg status $pkg | grep -E 'Status' | awk '{print $3}')
  19.     installed_time=$(opkg status $pkg | grep 'Installed-Time' | awk '{print $2}')
  20.     # Convert timestamp to YYYY-MM-DD HH:MM:SS format
  21.     installed_datetime=$(date -d @$installed_time +'%Y-%m-%d %H:%M:%S')
  22.  
  23.     if [ "$status" = "user" ]; then
  24.         echo "$installed_datetime $pkg" >> $temp_file_user
  25.         count_user=$((count_user + 1))
  26.         user_packages="$user_packages $pkg"
  27.     else
  28.         echo "$installed_datetime $pkg" >> $temp_file_ok
  29.         count_ok=$((count_ok + 1))
  30.         ok_packages="$ok_packages $pkg"
  31.     fi
  32.  
  33.     echo "($((count_user + count_ok))/$total_packages) U: $count_user, P: $count_ok package: $pkg"
  34. done
  35.  
  36. # Sort the temporary files by date and write to the output file
  37. {
  38.     echo "## User Installed Packages"
  39.     sort $temp_file_user
  40.     echo ""
  41.     echo "## PREINSTALL OK Installed Packages"
  42.     sort $temp_file_ok
  43.     echo ""
  44.     echo "Total user installed packages: $count_user"
  45.     echo "Total preinstall ok installed packages: $count_ok"
  46. } > /tmp/installed_packages_with_time.txt
  47.  
  48. # Write the package names to separate files
  49. echo $user_packages > /tmp/packagename-user.txt
  50. echo $ok_packages > /tmp/packagename-ok.txt
  51.  
  52. # Clean up the temporary files
  53. rm $temp_file_user $temp_file_ok
  54.  
  55. # Check if nano is installed, if not use cat and more
  56. if command -v nano > /dev/null; then
  57.     nano /tmp/installed_packages_with_time.txt
  58. else
  59.     cat /tmp/installed_packages_with_time.txt | more
  60. fi
  61.  
  62.  
Tags: OpenWRT
Advertisement
Add Comment
Please, Sign In to add comment