]> git.saurik.com Git - apt.git/blobdiff - cmdline/apt-key
merged from debian-sid
[apt.git] / cmdline / apt-key
index b39ab12e48fd0daf57ec369fdf54b2ee4b6bf386..113f9ab1baa5f230cc42af455d1fbfc5939a6e39 100755 (executable)
@@ -5,16 +5,28 @@ unset GREP_OPTIONS
 
 # We don't use a secret keyring, of course, but gpg panics and
 # implodes if there isn't one available
-GPG_CMD="gpg --ignore-time-conflict --no-options --no-default-keyring --secret-keyring /etc/apt/secring.gpg --trustdb-name /etc/apt/trustdb.gpg"
+GPG_CMD='gpg --ignore-time-conflict --no-options --no-default-keyring --secret-keyring /etc/apt/secring.gpg'
+
+if [ "$(id -u)" -eq 0 ]; then
+       GPG_CMD="$GPG_CMD --trustdb-name /etc/apt/trustdb.gpg"
+fi
+
 GPG="$GPG_CMD"
 
-MASTER_KEYRING=""
-ARCHIVE_KEYRING_URI=""
-#MASTER_KEYRING=/usr/share/keyrings/debian-master-keyring.gpg
-#ARCHIVE_KEYRING_URI=http://ftp.debian.org/debian/debian-archive-keyring.gpg
 
-ARCHIVE_KEYRING=/usr/share/keyrings/debian-archive-keyring.gpg
-REMOVED_KEYS=/usr/share/keyrings/debian-archive-removed-keys.gpg
+# ubuntu keyrings
+MASTER_KEYRING=/usr/share/keyrings/ubuntu-master-keyring.gpg
+ARCHIVE_KEYRING=/usr/share/keyrings/ubuntu-archive-keyring.gpg
+REMOVED_KEYS=/usr/share/keyrings/ubuntu-archive-removed-keys.gpg
+ARCHIVE_KEYRING_URI=http://archive.ubuntu.com/ubuntu/project/ubuntu-archive-keyring.gpg
+
+
+requires_root() {
+       if [ "$(id -u)" -ne 0 ]; then
+               echo >&1 "ERROR: This command can only be used by root."
+               exit 1
+       fi
+}
 
 add_keys_with_verify_against_master_keyring() {
     ADD_KEYRING=$1
@@ -54,13 +66,14 @@ add_keys_with_verify_against_master_keyring() {
 # (otherwise it does not make sense from a security POV)
 net_update() {
     if [ -z "$ARCHIVE_KEYRING_URI" ]; then
-       echo "ERROR: no location for the archive-keyring given"
+       echo >&2 "ERROR: Your distribution is not supported in net-update as no uri for the archive-keyring is set"
        exit 1
     fi
+    requires_root
     # in theory we would need to depend on wget for this, but this feature
     # isn't useable in debian anyway as we have no keyring uri nor a master key
     if ! which wget >/dev/null 2>&1; then
-       echo "ERROR: an installed wget is required for a network-based update"
+       echo >&2 "ERROR: an installed wget is required for a network-based update"
        exit 1
     fi
     if [ ! -d /var/lib/apt/keyrings ]; then
@@ -71,7 +84,7 @@ net_update() {
     if [ -e $keyring ]; then
        old_mtime=$(stat -c %Y $keyring)
     fi
-    (cd  /var/lib/apt/keyrings; wget -q -N $ARCHIVE_KEYRING_URI)
+    (cd  /var/lib/apt/keyrings; wget --timeout=90 -q -N $ARCHIVE_KEYRING_URI)
     if [ ! -e $keyring ]; then
        return
     fi
@@ -85,9 +98,10 @@ net_update() {
 update() {
     if [ ! -f $ARCHIVE_KEYRING ]; then
        echo >&2 "ERROR: Can't find the archive-keyring"
-       echo >&2 "Is the debian-archive-keyring package installed?"
+       echo >&2 "Is the ubuntu-keyring package installed?"
        exit 1
     fi
+    requires_root
 
     # add new keys from the package;
 
@@ -179,10 +193,12 @@ fi
 
 case "$command" in
     add)
+        requires_root
         $GPG --quiet --batch --import "$1"
         echo "OK"
         ;;
     del|rm|remove)
+        requires_root
         $GPG --quiet --batch --delete-key --yes "$1"
         echo "OK"
         ;;