Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
#!/bin/bash
# Basic bash desktop file crawler
# 2019 - Luis Guzman <ark@switnet.org>
##Check superuser
#if ! [ $(id -u) = 0 ]; then
# echo "You need to be root or have sudo privileges!"
# exit 0
#fi
#Check for necessary packages
sudo apt -yq4 install apt-file dpkg
sudo apt-file update
#Keep apt-file lists for debug porpuses
apt-file search "/usr/share/applications/" | grep .desktop > apt-file_desktop.txt
cat apt-file_desktop.txt | awk -F':' '{print $1}' | awk '!NF || !seen[$0]++' > apt-file_packages.txt
#Create storage for deb files
mkdir packages
cd packages
#Download marked deb packages
#check the true options to only use them instead of all unnecesary path
apt -o Dir::Cache::Archives=~/packages download $(cat ~/apt-file_packages.txt| xargs)
#Extract .desktop file
for f in `ls -1 *.deb | sed 's/\(.*\)\..*/\1/'`
do
dpkg-deb --fsys-tarfile $f.deb | tar -xvf - --wildcards ./usr/share/applications/\*.desktop
done
### Cleaning of .desktop files ###
#GUI specific "OnlyShowIn"
rm -f $(grep -r OnlyShowIn ./usr | awk -F':' '{print $1}' | awk '!NF || !seen[$0]++')
#No icon described on desktop file
rm -r $(grep -Lr Icon ./usr | awk -F':' '{print $1}' | awk '!NF || !seen[$0]++')
#Remove empty folders
find . -type d -empty -delete
#Package .desktop files
tar -czvf desktop_archive.tar.gz usr
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment