|
3 | 3 | from sys import stderr |
4 | 4 | from urllib.request import urlretrieve |
5 | 5 | import subprocess |
| 6 | +import os |
6 | 7 |
|
7 | 8 | script_install_path = '/tmp/homebrew-install.sh' |
| 9 | +script_env_temp_path = '/tmp/homebrew-profile.sh' |
8 | 10 | script_env_path = '/etc/profile.d/homebrew.sh' |
9 | 11 |
|
10 | | -shell = lambda command: subprocess.run(command.split()) |
| 12 | +shell = lambda command: subprocess.run(command.split(), check=True) |
| 13 | + |
| 14 | +if os.path.exists(script_install_path): |
| 15 | + os.remove(script_install_path) |
11 | 16 |
|
12 | 17 | try: |
13 | 18 | urlretrieve( |
14 | 19 | url='https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh', |
15 | 20 | filename=script_install_path |
16 | 21 | ) |
17 | | -except: |
18 | | - print("Failed to download Homebrew installation script", file=stderr) |
| 22 | +except Exception as e: |
| 23 | + print(f"Failed to download Homebrew installation script: {e}", file=stderr) |
19 | 24 | exit(1) |
20 | 25 |
|
21 | | -shell(f'/usr/bin/bash {script_install_path}') |
| 26 | +shell(f'bash {script_install_path}') |
| 27 | + |
| 28 | +with open(script_env_temp_path, 'w') as f: |
| 29 | + f.write('eval "$(/home/linuxbrew/.linuxbrew/bin/brew shellenv)" \n') |
| 30 | + f.write('export PATH=$PATH:/home/linuxbrew/.linuxbrew/bin/ \n') |
| 31 | + f.write('export C_INCLUDE_PATH=$CC_INCLUDE_PATH:/var/home/linuxbrew/.linuxbrew/include/ \n') |
22 | 32 |
|
23 | | -shell(f'sudo touch {script_env_path}') |
24 | | -shell(f'sudo echo \'eval "$(/home/linuxbrew/.linuxbrew/bin/brew shellenv)"\' >> {script_env_path}') |
25 | | -shell(f'sudo echo \'export C_INCLUDE_PATH=$CC_INCLUDE_PATH:/var/home/linuxbrew/.linuxbrew/include/\' >> {script_env_path}') |
| 33 | +shell(f'sudo mv {script_env_temp_path} {script_env_path}') |
26 | 34 |
|
27 | 35 | print("*" * 80) |
28 | 36 | print("Complete!") |
|
0 commit comments