-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathaptRepository-remove
More file actions
executable file
·132 lines (121 loc) · 7.24 KB
/
aptRepository-remove
File metadata and controls
executable file
·132 lines (121 loc) · 7.24 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
#! /bin/bash
# Shell program to remove ppa launchpad repository added with add-apt-repository ufficial script#
# sudo add-apt-repository ppa:<repository_name> #
# sudo add-apt-repository ppa:<repository_name>/<subdirectory> #
# ———————————————–——–——–—————————————————–——–——–—————————————————–—————————————————–————————————#
# Copyright (c) 2009 Ingalex project <http://www.sourceslist.eu> #
# This script is licensed under GNU GPL version 3.0 or above #
# #
# Redistribution and use in source and binary forms, with or without #
# modification, are permitted provided that the following conditions #
# are met: #
# 1. Redistributions of source code must retain the above copyright #
# notice, this list of conditions and the following disclaimer. #
# 2. Redistributions in binary form must reproduce the above copyright #
# notice, this list of conditions and the following disclaimer in the #
# documentation and/or other materials provided with the distribution. #
# #
# THIS SOFTWARE IS PROVIDED BY AUTHOR AND CONTRIBUTORS ``AS IS'' AND #
# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE #
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE #
# ARE DISCLAIMED. IN NO EVENT SHALL AUTHOR OR CONTRIBUTORS BE LIABLE #
# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL #
# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS #
# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) #
# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT #
# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY #
# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF #
# SUCH DAMAGE. #
# ———————————————————————————————————————–——–——–—————————————————–—————————————————–————————————#
# This script is part of Ingalex shell script collection #
# Visit http://www.sourceslist.eu for more information. #
# ———————————————————————————————————————–——–——–—————————————————–—————————————————–————————————#
# Syntax: sudo remove-apt-repository <repository_name> #
# sudo remove-apt-repository <repository_name>/<subdirectory> #
# ———————————————————————————————————————–——–——–—————————————————–—————————————————–————————————#
## functions defining
remove_repo () {
echo -ne 'Please Wait (0%)\r'
sleep 1
echo -ne 'Please Wait ##### (33%)\r'
apt-get update > /dev/null
echo -ne 'Please Wait ############# (66%)\r'
s1="$(echo $1 | sed "s:\/:\-:")-$(lsb_release -c | awk '{print $2}').list"
s2="$(echo $1 | sed "s:\/:\-:")-ppa-$(lsb_release -c | awk '{print $2}').list"
r1="ppa.launchpad.net_$(echo $1 | sed "s:\/:\_:")_ubuntu_dists_$(lsb_release -c | awk '{print $2}')_Release"
r2="ppa.launchpad.net_$(echo $1 | sed "s:\/:\_:")_ppa_ubuntu_dists_$(lsb_release -c | awk '{print $2}')_Release"
cd /etc/apt/sources.list.d/
if [ -f "$s1" ] ; then
keyid="$(gpg --verify --no-permission-warning /var/lib/apt/lists/$r1.gpg /var/lib/apt/lists/$r1 2>&1 1>/dev/null | head -n 1 | awk '{print $15}' )"
rm -rf /etc/apt/sources.list.d/$s1 && apt-key del $keyid > /dev/null && echo -ne 'Compleated ####################### (100%)\r' && echo -e '\E[32;40mppa launchpad repository successfully removed:' $1 && tput sgr0
elif [ -f "$s2" ] ; then
keyid="$(gpg --verify --no-permission-warning /var/lib/apt/lists/$r2.gpg /var/lib/apt/lists/$r2 2>&1 1>/dev/null | head -n 1 | awk '{print $15}')"
rm -rf /etc/apt/sources.list.d/$s2 && apt-key del $keyid > /dev/null && echo -ne 'Completed ####################### (100%)\r' && echo -e '\E[32;40mppa launchpad repository successfully removed:' $1 && tput sgr0
else
echo -ne 'Completed ####################### (100%)\r'
echo -e '\E[31;40munsuccessful removing - ppa launchpad repository not present or wrong syntax' && tput sgr0
fi
}
help_option() {
echo " "
echo "Usage: add-apt-repository [options]"
echo " "
echo "Syntax: "
echo "sudo remove-apt-repository <repository_name>"
echo "sudo remove-apt-repository <repository_name>/<subdirectory>"
echo " "
echo "Options: "
echo "-h, --help show this help message and exit"
}
list_option() {
cd /etc/apt/sources.list.d/
sources=$(dir *.list)
if [ "$sources" = "" ]; then
echo "No repository PPA Launchpad installed"
else
echo
echo -e '\E[33;40mPPA Launchpad repositories added to your list of software sources:' && tput sgr0
echo
for mysources in $sources
do
if [ -f "$mysources" ]
then
repo=$(sed 's:deb\ http\:\/\/ppa.launchpad.net/:'':g' $mysources | sed 's:\/ubuntu\ karmic\ main:'':g'| sed 's:\/ppa:'':g')
# repot=${mysources%%-karmic.list}
# repo=${repot%%-ppa} 2>&1 1>/dev/null
echo $repo
fi
echo
done
fi
}
## script
WHOAMI=$(/usr/bin/whoami)
if [ "$WHOAMI" != "root" ] ; then
/bin/echo
/bin/echo -e 'ERROR: you have to execute this command with root privileges: put "sudo" before this command!'
/bin/echo
exit 1
else
if [ "$1" = "--help" -o "$1" = "-h" ]; then
help_option
elif [ "$1" = "--list" -o "$1" = "-l" ]; then
list_option
else
controll=$(grep -e http://ppa.launchpad.net /etc/apt/sources.list)
if [ "$controll" != "" ]; then
echo ""
echo "Pay attention! You have some repository PPA Launchpad in your /etc/apt/sources.list but with this command you can remove only PPA Launchpad present in /etc/apt/sources.list.d/"
echo "Do you wish to continue? [Y/N]"
read answer
if [ "$answer" = "Si" -o "$answer" = "S" -o "$answer" = "Y" -o "$answer" = "Yes" ]; then
remove_repo "$1"
else
exit
fi
else
remove_repo "$1"
fi
fi
fi
exit 0