|
1 | | -import os, subprocess, platform, shutil, tarfile, zipfile, yaml, sys, requests, ctypes |
| 1 | +import os, subprocess, platform, shutil, tarfile, zipfile, sys, requests, ctypes |
2 | 2 |
|
3 | 3 | def create_default_config(): |
4 | 4 | home_dir = os.path.expanduser("~") |
@@ -61,14 +61,19 @@ def main(): |
61 | 61 | home_dir = os.path.expanduser("~") |
62 | 62 | config_dir = os.path.join(home_dir, ".config/greetings") |
63 | 63 |
|
| 64 | + # Install target |
| 65 | + targetDir = os.path.join(home_dir, ".local/bin/") |
| 66 | + asciiTarget = os.path.join(targetDir, "ascii-image-converter") |
| 67 | + greetingsTarget = os.path.join(targetDir, "greetings") |
| 68 | + |
64 | 69 | config_file = os.path.join(config_dir, "greetings.yaml") # Define files. |
65 | 70 | date_dir_file = os.path.join(config_dir, "date.txt") |
66 | 71 | if not os.path.exists(config_dir): |
67 | 72 | print(f"Creating files at: {config_dir}") |
68 | 73 | os.makedirs(config_dir, exist_ok=True) # Create config directories. |
69 | 74 | os.makedirs(os.path.join(config_dir, "images")) |
70 | 75 | open(date_dir_file, 'w').close() # Create date file. |
71 | | - create_default_config() |
| 76 | + create_default_config() |
72 | 77 | elif not os.path.exists(config_file): |
73 | 78 | create_default_config() |
74 | 79 |
|
@@ -171,15 +176,20 @@ def main(): |
171 | 176 | unixOS = 'linux' |
172 | 177 | elif system == 'DARWIN': |
173 | 178 | unixOS = 'macos' |
174 | | - binary_path = os.path.join(extract_dir, 'ascii-image-converter') |
175 | | - subprocess.run(["chmod", "+x", binary_path], check=True) |
| 179 | + binary_path = os.path.join(extract_dir, releaseName.replace('.tar.gz', '').replace('.zip', ''), 'ascii-image-converter') |
| 180 | + subprocess.run(["chmod", "+x", binary_path], check=True) # Set as executable. |
| 181 | + greetingsSrc = os.path.join(script_dir, f"greetings-{unixOS}") |
176 | 182 | try: |
177 | | - print("Moving the binaries to /usr/local/bin (you may be prompted for your password)...") |
178 | | - subprocess.run(["sudo", "mv", binary_path, "/usr/local/bin/ascii-image-converter"], check=True) |
179 | | - subprocess.run(["sudo", "cp", f"greetings-{unixOS}", "/usr/local/bin/greetings"], check=True) |
| 183 | + print("Moving the binaries to ~/.local/bin...") |
| 184 | + os.makedirs(targetDir, exist_ok=True) |
| 185 | + shutil.move(binary_path, asciiTarget) |
| 186 | + shutil.copy2(greetingsSrc, greetingsTarget) |
180 | 187 | except Exception as e: |
181 | | - print(f"Failed to move binaries: {e}") |
182 | | - sys.exit(1) |
| 188 | + print(f"Failed to move binaries: {e}") |
| 189 | + sys.exit(1) |
| 190 | + path_env = os.environ.get('PATH', '') |
| 191 | + if targetDir not in path_env.split(os.pathsep): |
| 192 | + print("Warn: ~/.local/bin not in PATH! Please add it to your PATH for the program to work correctly.") |
183 | 193 | else: # Windows |
184 | 194 | os.makedirs("C:\\Program Files\\widkit\\ascii-image-converter", exist_ok=True) # Make directories for ascii-image-converter and greetings. |
185 | 195 | os.makedirs("C:\\Program Files\\widkit\\greetings", exist_ok=True) |
|
0 commit comments