#include <errno.h>
#include <fcntl.h>
#include <glib.h>
+#include <getopt.h>
#include <tzplatform_config.h>
#define WGT_RW_DIR tzplatform_mkpath(TZ_SYS_RO_APP, ".preload-rw-wgt")
#define ALL_PRELOAD_RW_PKG_LIST "/opt/usr/share/.all_preload_rw_list"
+#define PKG_TYPE_STRING_LEN_MAX 128
+
+#define OPTVAL_SKIP_CHECK_REFERENCE 1000
+#define OPTVAL_PATH 1001
+#define OPTVAL_PRELOAD 1002
+#define OPTVAL_PRELOAD_RW 1003
+#define OPTVAL_PKG_TYPE 1004
+
+typedef enum install_type_e {
+ INSTALL_TYPE_UNDEFINED = 0,
+ INSTALL_TYPE_PRELOAD = 1,
+ INSTALL_TYPE_PRELOAD_RW = 2
+} install_type;
+
struct pkginfo {
char *pkgid;
char *version;
int main(int argc, char *argv[])
{
+ int opt_idx = 0;
+ int c = -1;
+ char pkg_path[PATH_MAX];
+ char pkg_type[PKG_TYPE_STRING_LEN_MAX];
char err_msg[BUFSZE];
+ char *backend_cmd;
int handle = -1;
int ret;
bool skip_check_reference = false;
+ bool is_default = true;
+ bool default_operation = false;
+ install_type op_type = INSTALL_TYPE_UNDEFINED;
+ const char *short_options = "";
+ const struct option long_options[] = {
+ {"skip-check-reference", 0, NULL, OPTVAL_SKIP_CHECK_REFERENCE},
+ {"path", 1, NULL, OPTVAL_PATH},
+ {"preload", 0, NULL, OPTVAL_PRELOAD},
+ {"preload-rw", 0, NULL, OPTVAL_PRELOAD_RW},
+ {"type", 1, NULL, OPTVAL_PKG_TYPE},
+ {0, 0, 0, 0} /* sentinel */
+ };
+
if (!_is_authorized(getuid())) {
_E("You are not an authorized user!");
return -1;
}
- if (argc > 1 && !strcmp(argv[1], "--skip-check-reference"))
- skip_check_reference = true;
+ while (1) {
+ c = getopt_long(argc, argv, short_options, long_options,
+ &opt_idx);
+ if (c == -1)
+ break; /* Parse end */
+ switch (c) {
+ case OPTVAL_PATH:
+ is_default = false;
+ if (optarg)
+ snprintf(pkg_path, sizeof(pkg_path),
+ "%s", optarg);
+ break;
+ case OPTVAL_SKIP_CHECK_REFERENCE:
+ skip_check_reference = true;
+ break;
+ case OPTVAL_PKG_TYPE:
+ is_default = false;
+ if (optarg)
+ snprintf(pkg_type, sizeof(pkg_type),
+ "%s", optarg);
+ if (strcmp(pkg_type, "tpk") != 0 &&
+ strcmp(pkg_type, "wgt") != 0) {
+ _E("Wrong pkg type: [%s]", pkg_type);
+ return -1;
+ }
+ break;
+ case OPTVAL_PRELOAD:
+ is_default = false;
+ op_type = INSTALL_TYPE_PRELOAD;
+ break;
+ case OPTVAL_PRELOAD_RW:
+ is_default = false;
+ op_type = INSTALL_TYPE_PRELOAD_RW;
+ break;
+ default:
+ _E("Unidentified input: (%d)", c);
+ break;
+ }
+ }
- if (_install_preload_pkg(TPK_BACKEND_CMD, TPK_DIR, true,
- skip_check_reference) < 0)
- goto error;
+ if (is_default) {
+ if (_install_preload_pkg(TPK_BACKEND_CMD, TPK_DIR, true,
+ skip_check_reference) < 0)
+ goto error;
- if (_install_preload_pkg(WGT_BACKEND_CMD, WGT_DIR, true,
- skip_check_reference) < 0)
- goto error;
+ if (_install_preload_pkg(WGT_BACKEND_CMD, WGT_DIR, true,
+ skip_check_reference) < 0)
+ goto error;
- if (_install_preload_pkg(TPK_BACKEND_CMD, TPK_RW_DIR, false,
- skip_check_reference) < 0)
- goto error;
+ if (_install_preload_pkg(TPK_BACKEND_CMD, TPK_RW_DIR, false,
+ skip_check_reference) < 0)
+ goto error;
- if (_install_preload_pkg(WGT_BACKEND_CMD, WGT_RW_DIR, false,
- skip_check_reference) < 0)
- goto error;
+ if (_install_preload_pkg(WGT_BACKEND_CMD, WGT_RW_DIR, false,
+ skip_check_reference) < 0)
+ goto error;
- return 0;
+ return 0;
+ }
+
+ if (op_type == INSTALL_TYPE_UNDEFINED ||
+ strlen(pkg_path) == 0 ||
+ strlen(pkg_type) == 0) {
+ _E("Invalid argument");
+ return -1;
+ }
+
+ if (strcmp(pkg_type, "tpk") == 0)
+ backend_cmd = TPK_BACKEND_CMD;
+ else
+ backend_cmd = WGT_BACKEND_CMD;
+
+ if (_install_preload_pkg(backend_cmd, pkg_path,
+ (op_type == INSTALL_TYPE_PRELOAD) ? true : false,
+ skip_check_reference) < 0)
+ goto error;
error:
handle = open("/tmp/.preload_install_error",