Ejemplo n.º 1
0
bool install_in_shell(bool global) {
  // keep track of the number of files
  // that we've written to (should end up being 2)
  int wrote_files = 0;

  char* script = bash_script();
  if (script) {
    print_verbose("Writing \"%s\"\n", script);

    char *profile_filename = NULL;

    if (global) {
      //global mode - install in /etc/profile and /etc/bash.bashrc
      if (directory_exists("/etc/profile.d")) {
        profile_filename = "/etc/profile.d/path.sh";
      } else if (file_exists("/etc/profile")) {
        profile_filename = "/etc/profile";
      }
      if (profile_filename) {
        if (write_script(profile_filename, script)) wrote_files++;
      }
      if (file_exists("/etc/bash.bashrc")) {
        if (write_script("/etc/bash.bashrc", script)) wrote_files++;
      }
    } else {
      //user mode - install in profile, rc file
      char* home_dir = get_home_directory();
      int i;
      char* profile_search_list[] = {".bash_profile", ".bash_login", ".profile"};
      for (i = 0; i < 3; i++) {
        char* filename = file_join(home_dir, profile_search_list[i]);
        if (file_exists(filename)) {
          profile_filename = filename;
          break;
        }
        free(filename);
      }
      if (!profile_filename) {
        profile_filename = file_join(home_dir, profile_search_list[0]);
      }
      if (write_script(profile_filename, script)) wrote_files++;
      free(profile_filename);

      char* rc_filename = file_join(home_dir, ".bashrc");
      if (write_script(rc_filename, script)) wrote_files++;
      free(rc_filename);

      free(home_dir);
    }

    free(script);
  }
  return wrote_files == 2;
}
Ejemplo n.º 2
0
char *
file_join2(const char *part1, const char *part2)
{
    return file_join(part1, part2, (const char *)0);
}
Ejemplo n.º 3
0
int main(int argc, char *argv[])
{
    assert(argc > 3);

    return file_join(argv[1], argv + 2, argc - 2);
}