| 1 | #include "common.h" |
| 2 | #include "initpass.h" |
| 3 | |
| 4 | void initpass(char *gpgid) { |
| 5 | char *lang = getlang(); |
| 6 | |
| 7 | char *basedir = getbasedir(1); |
| 8 | |
| 9 | if (mkdir_r(basedir, 0755) != 0 && errno != EEXIST) { |
| 10 | if (strncmp(lang, "en", 2) == 0) |
| 11 | fprintf(stderr, "Failed to create directory.\n"); |
| 12 | else fprintf(stderr, "ディレクトリを作成に失敗。\n"); |
| 13 | return; |
| 14 | } |
| 15 | |
| 16 | char gpgidpath[512]; |
| 17 | snprintf(gpgidpath, sizeof(gpgidpath), "%s/.gpg-id", basedir); |
| 18 | |
| 19 | struct stat statbuf; |
| 20 | if (stat(gpgidpath, &statbuf) == 0) { |
| 21 | if (strncmp(lang, "en", 2) == 0) |
| 22 | fprintf(stderr, ".gpg-id file already exists.\n"); |
| 23 | else fprintf(stderr, ".gpg-idファイルは既に存在します。\n"); |
| 24 | return; |
| 25 | } |
| 26 | |
| 27 | FILE *gpgidfile = fopen(gpgidpath, "w"); |
| 28 | if (gpgidfile == NULL) { |
| 29 | if (strncmp(lang, "en", 2) == 0) |
| 30 | fprintf(stderr, "Failed to write .gpg-id file.\n"); |
| 31 | else fprintf(stderr, ".gpg-idファイルを書き込めません。\n"); |
| 32 | return; |
| 33 | } |
| 34 | |
| 35 | if (fprintf(gpgidfile, "%s\n", gpgid) < 0) { |
| 36 | if (strncmp(lang, "en", 2) == 0) |
| 37 | fprintf(stderr, "Failed to write .gpg-id file.\n"); |
| 38 | else fprintf(stderr, ".gpg-idファイルへの書き込みに失敗しました。\n"); |
| 39 | fclose(gpgidfile); |
| 40 | return; |
| 41 | } |
| 42 | |
| 43 | fclose(gpgidfile); |
| 44 | |
| 45 | if (strncmp(lang, "en", 2) == 0) |
| 46 | puts("Initialization completed."); |
| 47 | else puts("初期設定に完了しました。"); |
| 48 | } |