| 1 | import os |
| 2 | |
| 3 | fn setup_symlink(custom_link_dir string) { |
| 4 | link_dir := normalized_link_dir(custom_link_dir) |
| 5 | if !os.exists(link_dir) { |
| 6 | os.mkdir_all(link_dir) or { panic(err) } |
| 7 | } |
| 8 | mut link_path := symlink_path(link_dir) |
| 9 | os.rm(link_path) or {} |
| 10 | os.symlink(vexe, link_path) or { |
| 11 | // Try ~/.local/bin as a fallback when /usr/local/bin is not writable. |
| 12 | home := os.home_dir() |
| 13 | if home == '' { |
| 14 | eprintln('Failed to create symlink "${link_path}": ${err}') |
| 15 | eprintln('Try again with sudo.') |
| 16 | exit(1) |
| 17 | } |
| 18 | local_bin := os.join_path(home, '.local', 'bin') |
| 19 | if !os.exists(local_bin) { |
| 20 | os.mkdir_all(local_bin) or { |
| 21 | eprintln('Failed to create symlink "${link_path}": ${err}') |
| 22 | eprintln('Try again with sudo.') |
| 23 | exit(1) |
| 24 | } |
| 25 | } |
| 26 | link_path = os.join_path(local_bin, 'v') |
| 27 | os.rm(link_path) or {} |
| 28 | os.symlink(vexe, link_path) or { |
| 29 | eprintln('Failed to create symlink "${link_path}": ${err}') |
| 30 | eprintln('Try again with sudo.') |
| 31 | exit(1) |
| 32 | } |
| 33 | eprintln('Note: Symlink created in "${local_bin}" instead of "/usr/local/bin".') |
| 34 | if path := os.getenv_opt('PATH') { |
| 35 | if !path.contains(local_bin) { |
| 36 | eprintln('Make sure "${local_bin}" is in your PATH.') |
| 37 | } |
| 38 | } |
| 39 | } |
| 40 | } |
| 41 | |
| 42 | fn default_link_dir() string { |
| 43 | if os.is_dir('/data/data/com.termux/files') { |
| 44 | return '/data/data/com.termux/files/usr/bin' |
| 45 | } |
| 46 | return '/usr/local/bin' |
| 47 | } |
| 48 | |
| 49 | fn symlink_path(link_dir string) string { |
| 50 | return os.join_path(link_dir, 'v') |
| 51 | } |
| 52 | |