-
Notifications
You must be signed in to change notification settings - Fork 0
/
AppToGrid.sh
executable file
·139 lines (126 loc) · 3.46 KB
/
AppToGrid.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
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
#!/bin/bash
DESKTOP_DIR="/usr/share/applications/"
BIN_DIR="/usr/bin/"
PS3="Select action [1-2]: "
select action in Add Remove
do
case $action in
"Add")
break;;
"Remove")
break;;
*)
echo "Invalid input.";;
esac
done
if [ "$action" == "Add" ]
then
while read -rp "Enter application name (name will be shown in app grid): " appName
do
if [ "$appName" == "" ]
then
echo "Application name cannot be empty."
else
break
fi
done
while read -rp "Enter path to executable (full path with extension): " pathToExe
do
if [ ! -f "$pathToExe" ]
then
echo "Executable not found."
else
break
fi
done
exeNameWithExtension=$(basename "$pathToExe")
exeName="${exeNameWithExtension%.*}"
while read -rp "Copy executable $exeNameWithExtension to $BIN_DIR [y/n]? " res
do
if [ "$res" == "y" ]
then
echo "Copying executable $exeNameWithExtension to $BIN_DIR..."
cp -i "$pathToExe" "$BIN_DIR"
pathToExe="$BIN_DIR$exeNameWithExtension"
break
elif [ "$res" == "n" ]
then
break
else
echo "Invalid answer."
fi
done
echo "Adding permissions..."
chmod +x "$pathToExe"
echo "Adding desktop entry $exeName.desktop to grid at $DESKTOP_DIR..."
echo "[Desktop Entry]
Type=Application
Terminal=false
Exec='$pathToExe'
Name=$appName
Comment=$appName
Keywords=$appName;" > "$exeName.desktop"
mv -i "$exeName.desktop" "$DESKTOP_DIR$exeName.desktop"
elif [ "$action" == "Remove" ]
then
while read -rp "Enter application name (name in grid): " appName
do
if [ "$appName" == "" ]
then
echo "Application name cannot be empty."
else
break
fi
done
echo "Searching directories..."
shopt -s nullglob
desktopEntries=("$DESKTOP_DIR"*)
for desktopEntry in "${desktopEntries[@]}"
do
if grep -q "Name=$appName" "$desktopEntry"
then
exeName="$(basename "$desktopEntry" ".desktop")"
# Get full name of executable
execProp=$(grep 'Exec=' "$desktopEntry" | grep "$BIN_DIR" )
if [ "$execProp" ]
then
exeNameWithExtension=$(basename "$execProp" | sed "s/'//g" | sed 's/"//g')
fi
break
fi
done
filesFound=()
if [ "$exeNameWithExtension" ] && [ -f "$BIN_DIR$exeNameWithExtension" ]
then
echo "Executable $exeNameWithExtension found in $BIN_DIR."
filesFound+=("$BIN_DIR$exeNameWithExtension")
fi
if [ -f "$DESKTOP_DIR$exeName.desktop" ]
then
echo "Desktop entry $exeName.dektop found in $DESKTOP_DIR."
filesFound+=("$DESKTOP_DIR$exeName.desktop")
fi
if [ "${#filesFound[@]}" -gt 0 ]
then
while read -rp "Remove ${#filesFound[@]} files [y/n]? " res
do
if [ "$res" == "y" ]
then
for file in "${filesFound[@]}"
do
echo "Removing $file..."
rm "$file"
done
break
elif [ "$res" == "n" ]
then
break
else
echo "Invalid answer."
fi
done
else
echo "Application not found."
fi
fi
echo "Done."