28 |
|
|
29 |
let bin_dir = Filename.dirname Sys.argv.(0) |
let bin_dir = Filename.dirname Sys.argv.(0) |
30 |
|
|
|
let home_dir = (try Sys.getenv "HOME" with _ -> ".") |
|
|
|
|
31 |
let hidden_dir_prefix = |
let hidden_dir_prefix = |
32 |
if Autoconf.system = "windows" then "" else "." |
if Autoconf.system = "windows" then "" else "." |
33 |
|
|
34 |
let config_dir_basename = hidden_dir_prefix ^ "mldonkey" |
let config_dir_basename = hidden_dir_prefix ^ "mldonkey" |
35 |
|
|
36 |
let config_dir = Filename.concat home_dir config_dir_basename |
let home_dir = |
37 |
|
match Autoconf.system with |
38 |
|
| "windows" -> Filename.concat "." config_dir_basename |
39 |
|
| _ -> Filename.concat (try Sys.getenv "HOME" with _ -> ".") config_dir_basename |
40 |
|
|
41 |
let installer_ini = create_options_file (Filename.concat config_dir |
let installer_ini = create_options_file (Filename.concat home_dir |
42 |
"installer.ini") |
"installer.ini") |
43 |
|
|
44 |
let installer_section = file_section installer_ini [] "" |
let installer_section = file_section installer_ini [] "" |
45 |
|
|
46 |
let mldonkey_directory = |
let mldonkey_directory = |
47 |
define_option installer_section ["mldonkey_directory"] |
define_option installer_section ["mldonkey_directory"] |
48 |
"The directory where mldonkey's option files are" string_option "." |
"The directory where mldonkey's option files are" string_option home_dir |
49 |
|
|
50 |
let _ = |
let _ = |
51 |
(try Options.load installer_ini with _ -> ()) |
(try Options.load installer_ini with _ -> ()) |
52 |
|
|
53 |
let (file_basedir, home_basedir) = |
let file_basedir_pre = |
54 |
try |
try |
55 |
if (String2.starts_with |
if (String2.starts_with |
56 |
(Filename.basename Sys.argv.(0)) "mlgui") |
(Filename.basename Sys.argv.(0)) "mlgui") |
59 |
try |
try |
60 |
Unix.chdir chroot_dir; |
Unix.chdir chroot_dir; |
61 |
let new_passwd = Filename.concat chroot_dir "/etc/passwd" in |
let new_passwd = Filename.concat chroot_dir "/etc/passwd" in |
62 |
if not (Sys.file_exists new_passwd) then begin |
if not (Sys.file_exists new_passwd) then |
63 |
lprintf_nl "No /etc/passwd in your chroot directory\n create one if you want to use 'run_as_user' option" |
lprintf_nl "No /etc/passwd in your chroot directory\n create one if you want to use 'run_as_user' option"; |
|
end; |
|
64 |
MlUnix.chroot chroot_dir; |
MlUnix.chroot chroot_dir; |
65 |
lprintf_nl "mldonkey is now running in %s" chroot_dir; |
lprintf_nl "mldonkey is now running in %s" chroot_dir; |
66 |
".", "." |
"." |
67 |
|
|
68 |
with e -> |
with e -> |
69 |
lprintf_nl "Exception %s trying to chroot %s" |
lprintf_nl "Exception %s trying to chroot %s" |
70 |
(Printexc2.to_string e) chroot_dir; |
(Printexc2.to_string e) chroot_dir; |
71 |
exit 2 |
exit 2 |
72 |
with _ -> |
with _ -> |
|
( |
|
73 |
try |
try |
74 |
let s = Sys.getenv "MLDONKEY_DIR" in |
let s = Sys.getenv "MLDONKEY_DIR" in |
75 |
if s = "" then "." else s |
if s = "" then home_dir else Filename2.normalize s |
76 |
with _ -> |
with _ -> |
77 |
!!mldonkey_directory |
home_dir |
78 |
), home_dir |
|
79 |
|
let file_basedir = |
80 |
|
(* Creating dirs does work differently on Windows than Unix. |
81 |
|
Dirs like c:\b are split down by unix2.safe_mkdir to "c". |
82 |
|
This function splits the directory name into the drive name |
83 |
|
and chdir to it before creating directories. |
84 |
|
Non-absolute paths in $MLDONKEY_DIR do not work as well *) |
85 |
|
if Sys.file_exists (Filename.concat (Sys.getcwd ()) "downloads.ini") then |
86 |
|
(Sys.getcwd ()) |
87 |
|
else |
88 |
|
if Autoconf.system = "windows" then |
89 |
|
match String2.split file_basedir_pre ':' with |
90 |
|
| drive :: directory :: _ -> |
91 |
|
Unix.chdir (drive ^ ":\\"); |
92 |
|
directory |
93 |
|
| _ -> lprintf "Please provide an absolute path in MLDONKEY_DIR like d:\\mldonkey, exiting...\n"; exit 2 |
94 |
|
else file_basedir_pre |
95 |
|
|
96 |
let _ = |
let _ = |
97 |
lprintf_nl "Starting MLDonkey %s ... " Autoconf.current_version; |
lprintf_nl "Starting MLDonkey %s ... " Autoconf.current_version; |
98 |
lprintf_nl "Language %s, locale %s" |
lprintf_nl "Language %s, locale %s" |
99 |
Charset.default_language Charset.locstr; |
Charset.default_language Charset.locstr; |
100 |
|
lprintf_nl "MLDonkey is working in %s" file_basedir; |
101 |
|
|
102 |
(try |
(try |
103 |
Unix2.safe_mkdir file_basedir |
Unix2.safe_mkdir file_basedir |
104 |
with e -> |
with e -> |
105 |
lprintf_nl "Exception %s to create dir %s" |
lprintf_nl "Exception (%s) trying to create dir %s" |
106 |
(Printexc2.to_string e) file_basedir; |
(Printexc2.to_string e) file_basedir; |
107 |
exit 2); |
exit 2); |
108 |
Unix2.can_write_to_directory file_basedir; |
Unix2.can_write_to_directory file_basedir; |
109 |
Unix.chdir file_basedir; |
Unix.chdir file_basedir; |
110 |
|
|
111 |
if (String2.starts_with (Filename.basename Sys.argv.(0)) "mlnet") |
if (String2.starts_with (Filename.basename Sys.argv.(0)) "mlnet") |
112 |
then if Sys.file_exists "mlnet.pid" |
then if Sys.file_exists "mlnet.pid" |
113 |
then begin |
then begin |
120 |
exit 2 |
exit 2 |
121 |
end; |
end; |
122 |
|
|
|
lprintf_nl "The .ini-files are saved in %s" file_basedir; |
|
|
|
|
123 |
let filename = |
let filename = |
124 |
try |
try |
125 |
Sys.getenv "MLDONKEY_STRINGS" |
Sys.getenv "MLDONKEY_STRINGS" |
126 |
with _ -> |
with _ -> |
127 |
Filename.concat config_dir "mlnet_strings" |
"mlnet_strings" |
128 |
in |
in |
|
Unix2.safe_mkdir (Filename.dirname filename); |
|
|
Unix2.can_write_to_directory (Filename.dirname filename); |
|
129 |
set_strings_file filename |
set_strings_file filename |
130 |
|
|
131 |
|
|