-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathspam
More file actions
executable file
·266 lines (244 loc) · 9.45 KB
/
spam
File metadata and controls
executable file
·266 lines (244 loc) · 9.45 KB
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
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
#!/bin/bash
# Shitty PAckage Manager
# Check for sudo
if [ "$EUID" -eq 0 ]
then
# First-time setup things, for sudo users
# Link spam to bin
if test ! -f "/usr/bin/spam"; then
ln -sr ./spam /usr/bin/spam
chmod +x /usr/bin/spam
fi
# Add alias to run as sudo
if test ! -f "/etc/profile.d/spam.sh"; then
echo 'alias spam="sudo /usr/bin/spam"' >> /etc/profile.d/spam.sh
fi
# Mod perm for user local
if [ "$(stat -c '%a' /usr/local/src)" != "1777" ]
then
chmod -R 1777 /usr/local/src
fi
# Edit sudoers file
if ! grep -q "spam" /etc/sudoers
then
# We copy the sudoers file and change it, to not fuck it up
cp /etc/sudoers /tmp/sudoers_spam
echo "ALL ALL=NOPASSWD: /usr/bin/spam" >> /tmp/sudoers_spam
# We check, using visudo, if the tmp sudoers file is valid
if visudo -qcf /tmp/sudoers_spam
then
echo "File OK, changing sudoers file!"
mv -f /tmp/sudoers_spam /etc/sudoers
else
echo "Failed to change sudoers file! File not valid, aborting!"
fi
fi
# Go to /usr/local/src
INSTALL_PATH=/usr/local/src
cd $INSTALL_PATH || exit
# Give package name
read -r -p "Enter package name: " package_name
# Type URL of package
if [[ $1 == "install" ]] && [[ -n "$2" ]]
then
package_url=$2
else
read -r -p "Type URL of package (source code / .deb / .rpm / .tar): " package_url
fi
# Parse type of package
if [[ "$package_url" == *.tar.* ]]
then
# Download tarball
echo "Installing $package_name from tarball..."
mkdir "$package_name"
cd "$package_name" || exit
package_file=$(basename "$package_url")
curl "$package_url" --output "$package_file"
# Unpack tarball
tar -xf "$package_file"
# We assume it's a C-compiled program
# Configure
./configure
# Install
make
make install
elif [[ "$package_url" == *.git ]]
then
# Clone git
#package_name=$(basename $package_url .git)
echo "Installing $package_name from source code..."
git clone "$package_url" $INSTALL_PATH/"$package_name"
# We assume it's a C-compiled program
# Configure
./configure
# Install
make
make install
elif [[ "$package_url" == *.deb ]]
then
# Download and install .deb file
#package_name=$(basename $package_url .deb)
echo "Installing $package_name from .deb file"
mkdir "$package_name"
cd "$package_name" || exit
package_file=$(basename "$package_url")
curl "$package_url" --output "$package_file"
# dpkg --dry-run -i package.deb
# dpkg -I package
# apt-cache rdepends package.deb
# apt-cache showpkg package-name
# apt-cache depends package-name
# dpkg -I $package_file | grep -E "Depends|Recommends|Suggests|Pre\-Depends"
# Check package dependencies
dependencies=$(apt-cache depends "./$package_file")
dep_count=$(echo "$dependencies" | wc -l)
echo "Showing dependencies for $package_name:"
if [[ ! "$dependencies" == E:* ]]
then
if [[ "$dep_count" -gt 10 ]]
then
echo "$dependencies" | head -n 10
echo "Show all $dep_count dependencies?"
select yn in "Yes" "No"; do
case $yn in
Yes )
echo "$dependencies"
break;;
No )
break;;
esac
done
else
echo "$dependencies"
fi
echo "Do you want to install $package_name with the listed dependencies?"
select yn in "Yes" "No"; do
case $yn in
Yes )
# Install the package
if ! dpkg -i "./$package_file"
then
# Install dependencies and package from apt-cache
if apt -f install
then
echo "Installated successfully."
else
echo "Failed installation!"
fi
else
echo "Installed successfully."
fi
break;;
No )
echo "Installation cancelled."
exit;;
esac
done
else
echo "$dependencies"
fi
elif [[ "$package_url" == *.rpm ]]
then
# Download and install .rpm file
#IFS=. read -r package_name <<< $(basename $package_url .rpm)
#package_name=$(basename $package_url .rpm)
echo "Installing $package_name from .rpm file"
mkdir "$package_name"
cd "$package_name" || exit
package_file=$(basename "$package_url")
curl "$package_url" --output "$package_file"
# If installing rpm file directly
echo "Do you want to install the .rpm-file with dpkg? (alternative is rpm)"
select yn in "Yes" "No"; do
case $yn in
Yes )
# convert the rpm-file to a deb-file
deb_package_file=$(alien --to-deb "$package_file" | cut -d " " -f 1)
# Check package dependencies
dependencies=$(apt-cache depends "./$deb_package_file")
dep_count=$(echo "$dependencies" | wc -l)
echo "Showing dependencies for $package_name:"
if [[ ! "$dependencies" == E:* ]]
then
if [[ "$dep_count" -gt 10 ]]
then
echo "$dependencies" | head -n 10
echo "Show all $dep_count dependencies?"
select yn in "Yes" "No"; do
case $yn in
Yes )
echo "$dependencies"
break;;
No )
break;;
esac
done
else
echo "$dependencies"
fi
echo "Do you want to install $package_name with the listed dependencies?"
select yn in "Yes" "No"; do
case $yn in
Yes )
# Install the package
if ! dpkg -i "./$deb_package_file"
then
# Install dependencies and package from apt-cache
if apt -f install
then
echo "Installated successfully."
else
echo "Failed installation!"
fi
else
echo "Installed successfully."
fi
break;;
No )
echo "Installation cancelled."
exit;;
esac
done
else
echo "$dependencies"
fi
break;;
No )
# Check package dependencies
echo "Do you want to install $package_name with the following dependencies?"
rpm -qpR "$package_file"
select yn2 in "Yes" "No"; do
case $yn2 in
Yes )
# Install the package
if ! rpm -i "$package_file"
then
# Install package with yum
if yum --nogpgcheck localinstall "$package_file"
then
echo "Installated successfully."
else
echo "Failed installation!"
fi
else
echo "Installed successfully."
fi
break;;
No )
echo "Installation cancelled."
exit;;
esac
done
exit;;
esac
done
else
echo "Package URL did not match a .git repo, .deb, .rpm"
fi
else
# Only works for adding user aliases
if ! grep -q "/usr/bin/spam" ~/.bashrc; then
echo 'alias spam="sudo /usr/bin/spam"' >> ~/.bashrc
fi
sudo sh ./spam
fi