-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathatg.sh
109 lines (87 loc) · 2.65 KB
/
atg.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
#!/bin/bash
RED='\033[0;31m'
YELLOW='\033[0;33m'
GRAY='\033[1;30m'
NC='\033[0m'
WARN="[${YELLOW}WARN${NC}]:"
INFO="[${GRAY}INFO${NC}]:"
ERROR="[${RED}ERROR${NC}]:"
homedir=~/
appdir="${homedir}apps/"
installDir="${homedir}.local/share/applications/"
apps=($(tree $appdir -f -i | grep .AppImage))
echo -e "${INFO} Adding all AppImages"
for app in ${apps[@]}; do
tmp="/tmp/ATG-$(uuidgen)/"
currdir=$(pwd)
echo -e "${INFO} Setting executable bit on ${app}"
chmod +x ${app}
mkdir -p ${tmp}
cd ${tmp}
echo -e "${INFO} Extracting ${app}"
${app} --appimage-extract 1>/dev/null
echo -e "${INFO} Extraction completed"
cd ${tmp}/squashfs-root
desktop_file=$(ls *.desktop)
icon_line=$(cat ${desktop_file} | grep "Icon=")
iconArr=(${icon_line//=/ })
iconName=${iconArr[1]}
iconFullName=$(ls | egrep "${iconName}\.(png|jpg|jpeg)")
icon=$(readlink -f ${iconFullName} || echo ${iconFullName})
iconSize=$(identify -format '%wx%h' ${icon})
iconTargetDir=${homedir}.local/share/icons/hicolor/${iconSize}/apps/
iconTargetFile=${iconTargetDir}${iconFullName}
sed -i "/^Exec=/c\Exec=${app}" ${desktop_file}
sed -i "/^Icon=/c\Icon=${iconTargetFile}" ${desktop_file}
mkdir -p ${iconTargetDir}
\cp -r ${desktop_file} ${installDir}
\cp -r ${icon} ${iconTargetFile}
cd ${currdir}
rm -rf ${tmp}
done
echo -e "${INFO} Added all AppImages"
echo -e "${INFO} Removing dead files"
IFS=$'\n'
installedApps=($(ls -d ${installDir}* | grep ".desktop"))
installedAppImages=()
for installedApp in "${installedApps[@]}"; do
cat ${installedApp} | egrep -i "Exec=${appdir}.*\.AppImage" 1>/dev/null
ret=$?
if [ ${ret} -eq 0 ]; then
installedAppImages+=(${installedApp})
fi
done
usedLogos=()
uncheckedFilesToRemove=()
for installedAppImage in "${installedAppImages[@]}"; do
IFS=' '
execLine=$(cat ${installedAppImage} | grep "Exec=")
execArr=(${execLine//=/ })
execPath=${execArr[1]}
logoLine=$(cat ${installedAppImage} | grep "Icon=")
logoArr=(${logoLine//=/ })
logoPath=${logoArr[1]}
if [ -f "${execPath}" ]; then
usedLogos+=(${logoPath})
else
uncheckedFilesToRemove+=(${installedAppImage})
uncheckedFilesToRemove+=(${logoPath})
fi
done
filesToRemove=()
for uncheckedFileToRemove in "${uncheckedFilesToRemove[@]}"; do
IFS='|'
if [[ ! " ${IFS}${usedLogos[*]}${IFS} " =~ " ${uncheckedFileToRemove} " ]]; then
filesToRemove+=(${uncheckedFileToRemove})
else
echo -e "${WARN} File "${uncheckedFileToRemove}" is referenced in existing Desktop file. Won\'t remove."
fi
unset IFS
done
for fileToRemove in "${filesToRemove[@]}"; do
echo -e "${INFO} Removing file: ${fileToRemove}"
rm -f ${fileToRemove}
done
unset IFS
echo -e "${INFO} Removed dead files"
echo -e "${INFO} Finished"