diff --git a/binr/r2pm/d/www-t b/binr/r2pm/d/www-t index 059c236407..fd7448ffdc 100644 --- a/binr/r2pm/d/www-t +++ b/binr/r2pm/d/www-t @@ -6,12 +6,15 @@ R2PM_DESC "[r2-www] The tiled WebUI of /t" R2PM_INSTALL() { cd www/t || exit 1 make || exit 1 - WWWROOT=`r2 -qce' http.root' - 2> /dev/null` + WWWROOT="${R2PM_WWWROOT}" + echo "WWWROOT IS ${WWWROOT}" + mkdir -p ${WWWROOT} || exit 1 + echo mkdir -p ${WWWROOT} || exit 1 if [ -n "${WWWROOT}" ]; then rm -rf "${WWWROOT}/t"/* - mkdir -p "${WWWROOT}/t" + mkdir -p "${WWWROOT}/t" || exit 1 echo "Installing /t..." - tar xzvf dist.tar.gz -C "${WWWROOT}/t" + tar xzvf dist.tar.gz -C "${WWWROOT}/t" || exit 1 else echo "Cannot find WWWROOT" exit 1 @@ -19,7 +22,7 @@ R2PM_INSTALL() { } R2PM_UNINSTALL() { - WWWROOT=`r2 -qce' http.root' - 2>/dev/null` + WWWROOT="${R2PM_WWWROOT}" if [ -n "${WWWROOT}" ]; then rm -rf "{WWWROOT}/t" else diff --git a/binr/r2pm/r2pm b/binr/r2pm/r2pm index ee2b338a15..97e9f5e256 100755 --- a/binr/r2pm/r2pm +++ b/binr/r2pm/r2pm @@ -14,8 +14,18 @@ export GLOBAL=0 export R2VERSION="`r2 -qv`" export PREFIX="`r2 -hh | grep PREFIX | awk '{print $2}' 2> /dev/null`" export LIBEXT="`r2 -hh | grep LIBEXT | awk '{print $2}' 2> /dev/null`" -export R2HOMEDIR="`r2 -hh | grep RHOMEDIR | awk '{print $2}' 2> /dev/null`" +export R2HOMEDIR="`r2 -hh | grep '^ RHOMEDIR' | awk '{print $2}' 2> /dev/null`" +# prefix export R2PM_SYSPREFIX="${PREFIX}" +export R2PM_HOMEPREFIX="${R2HOMEDIR}/prefix" +export R2PM_PREFIX="${R2PM_HOMEPREFIX}" +# www +export R2PM_SYSWWWROOT="`r2 -cq -qe http.root --`" +export R2PM_HOMEWWWROOT="${R2HOMEDIR}/www" +export R2PM_WWWROOT="${R2PM_HOMEWWWROOT}" +echo $R2PM_WWWROOT +# pkgconfig +export PKG_CONFIG_PATH="${R2PM_HOMEPREFIX}/lib/pkgconfig:${PKG_CONFIG_PATH}" # Global Vars TRAVIS_TYPE=XX @@ -23,9 +33,6 @@ TRAVIS_JOB=86948888 [ -z "${R2PM_PLUGDIR}" ] && R2PM_PLUGDIR="${R2HOMEDIR}" IS_SYSPKG=0 R2PM_USRDIR="${HOME}/.config/radare2/r2pm" -export R2PM_HOMEPREFIX="${R2PM_USRDIR}/prefix" -R2PM_PREFIX="${R2PM_HOMEPREFIX}" -export PKG_CONFIG_PATH="${R2PM_HOMEPREFIX}/lib/pkgconfig:${PKG_CONFIG_PATH}" # TODO. support system plugin installs R2PM_PLUGDIR="${R2PM_PREFIX}/lib/radare2/last" diff --git a/binr/radare2/radare2.c b/binr/radare2/radare2.c index 5b271419e3..2c27ed8ec3 100644 --- a/binr/radare2/radare2.c +++ b/binr/radare2/radare2.c @@ -156,7 +156,8 @@ static int main_help(int line) { " -v, -V show radare2 version (-V show lib versions)\n" " -w open file in write mode\n" " -z, -zz do not load strings or load them even in raw\n"); - if (line == 2) + if (line == 2) { + char *homedir = r_str_home (R2_HOMEDIR); printf ( "Scripts:\n" " system "R2_PREFIX"/share/radare2/radare2rc\n" @@ -167,7 +168,7 @@ static int main_help(int line) { " user ~/.config/radare2/plugins\n" " LIBR_PLUGINS "R2_PREFIX"/lib/radare2/"R2_VERSION"\n" "Environment:\n" - " RHOMEDIR ~/.config/radare2\n" // TODO: rename to RHOME R2HOME? + " RHOMEDIR %s\n" // TODO: rename to RHOME R2HOME? " RCFILE ~/.radare2rc (user preferences, batch script)\n" // TOO GENERIC " MAGICPATH "R_MAGIC_PATH"\n" " R_DEBUG if defined, show error messages and crash signal\n" @@ -178,7 +179,9 @@ static int main_help(int line) { " INCDIR "R2_INCDIR"\n" " LIBDIR "R2_LIBDIR"\n" " LIBEXT "R_LIB_EXT"\n" - ); + , homedir); + free (homedir); + } return 0; } diff --git a/libr/core/config.c b/libr/core/config.c index 977f353607..e9898ec972 100644 --- a/libr/core/config.c +++ b/libr/core/config.c @@ -1712,6 +1712,7 @@ R_API int r_core_config_init(RCore *core) { #endif SETI("http.maxsize", 0, "Maximum file size for upload"); SETPREF("http.bind", "localhost", "Server address"); + SETPREF("http.homeroot", "~/.config/radare2/www", "http home root directory"); #if __ANDROID__ SETPREF("http.root", "/data/data/org.radare2.installer/www", "http root directory"); #elif __WINDOWS__ diff --git a/libr/core/rtr.c b/libr/core/rtr.c index 1b4230da7b..d3ffdf6a85 100644 --- a/libr/core/rtr.c +++ b/libr/core/rtr.c @@ -363,12 +363,16 @@ static int r_core_rtr_http_run (RCore *core, int launch, const char *path) { int iport, timeout = r_config_get_i (core->config, "http.timeout"); const char *host = r_config_get (core->config, "http.bind"); const char *root = r_config_get (core->config, "http.root"); + const char *homeroot = r_config_get (core->config, "http.homeroot"); const char *port = r_config_get (core->config, "http.port"); const char *allow = r_config_get (core->config, "http.allow"); const char *httpui = r_config_get (core->config, "http.ui"); if (!r_file_is_directory (root)) { - eprintf ("Cannot find http.root '%s'\n", root); + if (!r_file_is_directory (homeroot)) { + eprintf ("Cannot find http.root (%s) or http.homeroot (%s)\n", root, homeroot); + return false; + } return false; } @@ -651,7 +655,19 @@ static int r_core_rtr_http_run (RCore *core, int launch, const char *path) { free (refstr); } else { const char *root = r_config_get (core->config, "http.root"); - char *path = r_file_root (root, rs->path); + const char *homeroot = r_config_get (core->config, "http.homeroot"); + char *path; + if (homeroot && *homeroot) { + char *homepath = r_file_abspath (homeroot); + path = r_file_root (homepath, rs->path); + free (homepath); + if (!r_file_exists (path)) { + free (path); + path = r_file_root (root, rs->path); + } + } else { + path = r_file_root (root, rs->path); + } // FD IS OK HERE if (rs->path [strlen (rs->path)-1] == '/') { path = r_str_concat (path, "index.html"); diff --git a/libr/util/file.c b/libr/util/file.c index cf0164ca69..579137f913 100644 --- a/libr/util/file.c +++ b/libr/util/file.c @@ -124,7 +124,7 @@ R_API char *r_file_abspath(const char *file) { } cwd = r_sys_getdir (); if (!strncmp (file, "~/", 2) || !strncmp (file, "~\\", 2)) { - ret = r_str_home (file+2); + ret = r_str_home (file + 2); } else { #if __UNIX__ || __CYGWIN__ if (cwd && *file != '/')