Remove unused opkg_set_current_state bits.
[oweals/opkg-lede.git] / libopkg / opkg_install.c
index aba0d1eb073ac1159f67252d7d438d1a26eec7d5..82749d56b93dc957ebcb383b5f29ad10b775a14c 100644 (file)
@@ -36,7 +36,7 @@ typedef void (*sighandler_t)(int);
 
 #include "opkg_utils.h"
 #include "opkg_message.h"
-#include "opkg_state.h"
+#include "opkg_cmd.h"
 #include "opkg_defines.h"
 
 #include "sprintf_alloc.h"
@@ -105,8 +105,6 @@ int opkg_install_from_file(opkg_conf_t *conf, const char *filename)
      pkg = hash_insert_pkg(&conf->pkg_hash, pkg, 1,conf);
      old = pkg_hash_fetch_installed_by_name(&conf->pkg_hash, pkg->name);
 
-     pkg->local_filename = strdup(filename);
-
      if (old) {
          old_version = pkg_version_str_alloc(old);
          new_version = pkg_version_str_alloc(pkg);
@@ -766,8 +764,10 @@ int opkg_install_pkg(opkg_conf_t *conf, pkg_t *pkg, int from_upgrade)
      abstract_pkg_t *ab_pkg = NULL;
      int old_state_flag;
      char* file_md5;
-     char *pkgid;
-    
+#ifdef HAVE_SHA256
+     char* file_sha256;
+#endif
+
      if ( from_upgrade ) 
         message = 1;            /* Coming from an upgrade, and should change the output message */
 
@@ -834,7 +834,7 @@ int opkg_install_pkg(opkg_conf_t *conf, pkg_t *pkg, int from_upgrade)
      }
 
      /* check that the repository is valid */
-     #if HAVE_GPGME
+     #if defined(HAVE_GPGME) || defined(HAVE_OPENSSL)
      char *list_file_name, *sig_file_name, *lists_dir;
 
      /* check to ensure the package has come from a repository */
@@ -849,8 +849,15 @@ int opkg_install_pkg(opkg_conf_t *conf, pkg_t *pkg, int from_upgrade)
 
        if (file_exists (sig_file_name))
        {
-         if (opkg_verify_file (conf, list_file_name, sig_file_name))
+         if (opkg_verify_file (conf, list_file_name, sig_file_name)){
+           opkg_message(conf, OPKG_ERROR, "Failed to verify the signature of: %s\n",
+                           list_file_name);
            return OPKG_INSTALL_ERR_SIGNATURE;
+         }
+       }else{
+         opkg_message(conf, OPKG_ERROR, "Signature file is missing. "
+                         "Perhaps you need to run 'opkg update'?\n");
+         return OPKG_INSTALL_ERR_SIGNATURE;
        }
 
        free (lists_dir);
@@ -874,6 +881,23 @@ int opkg_install_pkg(opkg_conf_t *conf, pkg_t *pkg, int from_upgrade)
          free(file_md5);
      }
 
+#ifdef HAVE_SHA256
+     /* Check for sha256 value */
+     if(pkg->sha256sum)
+     {
+         file_sha256 = file_sha256sum_alloc(pkg->local_filename);
+         if (strcmp(file_sha256, pkg->sha256sum))
+         {
+              opkg_message(conf, OPKG_ERROR,
+                           "Package %s sha256sum mismatch. Either the opkg or the package index are corrupt. Try 'opkg update'.\n",
+                           pkg->name);
+              free(file_sha256);
+              return OPKG_INSTALL_ERR_SHA256;
+         }
+         free(file_sha256);
+     }
+#endif
+
      if (pkg->tmp_unpack_dir == NULL) {
          unpack_pkg_control_files(conf, pkg);
      }
@@ -892,10 +916,6 @@ int opkg_install_pkg(opkg_conf_t *conf, pkg_t *pkg, int from_upgrade)
      replacees = pkg_vec_alloc();
      pkg_get_installed_replacees(conf, pkg, replacees);
 
-     sprintf_alloc (&pkgid, "%s;%s;%s;", pkg->name, pkg->version, pkg->architecture);
-     opkg_set_current_state (conf, OPKG_STATE_INSTALLING_PKG, pkgid);
-     free (pkgid);
-
      /* this next section we do with SIGINT blocked to prevent inconsistency between opkg database and filesystem */
      {
          sigset_t newset, oldset;
@@ -1039,7 +1059,6 @@ int opkg_install_pkg(opkg_conf_t *conf, pkg_t *pkg, int from_upgrade)
           pkg_vec_free (replacees);
          return OPKG_ERR_UNKNOWN;
      }
-     opkg_set_current_state (conf, OPKG_STATE_NONE, NULL);
 }
 
 static int prerm_upgrade_old_pkg(opkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg)