-
Notifications
You must be signed in to change notification settings - Fork 148
/
go
executable file
·128 lines (103 loc) · 3.56 KB
/
go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
#!/usr/bin/env python
# -*- coding: utf-8; -*-
# Copyright (C) 2012, 2013, 2014 Johan Andersson
# Copyright (C) 2013, 2014 Sebastian Wiesner
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 3, or (at your option)
# any later version.
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
# You should have received a copy of the GNU General Public License
# along with GNU Emacs; see the file COPYING. If not, write to the
# Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
# Boston, MA 02110-1301, USA.
"""
Install Cask
"""
from __future__ import unicode_literals, print_function
import os
import sys
import errno
from subprocess import CalledProcessError, check_call
HOME = os.path.expanduser("~")
TARGET_DIRECTORY = os.path.join(HOME, ".cask")
REPOSITORY = "https://github.com/cask/cask.git"
ISSUE_TRACKER = "https://github.com/cask/cask/issues"
class CaskGoError(Exception):
pass
OKGREEN = "\033[32m"
FAIL = "\033[31m"
ENDC = "\033[0m"
def success(s):
print(OKGREEN + s + ENDC)
sys.exit(0)
def fail(s):
print(FAIL + s + ENDC, file=sys.stderr)
sys.exit(1)
def bootstrap_cask(target_directory):
cask = os.path.join(target_directory, "bin", "cask")
try:
check_call(["bash", cask, "upgrade-cask"])
except CalledProcessError:
raise CaskGoError(
"Cask could not be bootstrapped. Try again later, "
"or report an issue at {0}".format(ISSUE_TRACKER)
)
def install_cask(target_directory):
if os.path.isdir(target_directory):
raise CaskGoError(
"Directory {0} exists. Is Cask already installed?".format(target_directory)
)
else:
try:
check_call(["git", "clone", REPOSITORY, target_directory])
except CalledProcessError:
raise CaskGoError(
"Cask could not be installed. Try again "
"later, or report an issue at {0}".format(ISSUE_TRACKER)
)
except OSError as error:
if error.errno == errno.ENOENT:
raise CaskGoError("git executable not found. Please install Git")
else:
raise
def main():
notice = """
!!!
!!! DEPRECATION NOTICE
!!!
!!!
!!! The cask `go` script will be removed on 2021/06/01.
!!!
!!! This is due to security concerns about the way python is
!!! invoked from curl, and to remove the python dependency from cask.
!!!
!!! The way to install cask without depending on the `go` script
!!! is very simple. Just clone Cask and pass the PATH.
!!!
!!! git clone https://github.com/cask/cask ~/.cask
!!! PATH=$HOME/.cask/bin:$PATH
!!!
!!! # If you want to make it permanent
!!! echo 'PATH=$HOME/.cask/bin:$PATH' >> .bashrc
!!!
"""
try:
install_cask(TARGET_DIRECTORY)
bootstrap_cask(TARGET_DIRECTORY)
print(FAIL + notice + ENDC, file=sys.stderr)
success(
"""\
Successfully installed Cask! Now, add the cask binary to your $PATH:
export PATH="{0}/bin:$PATH\"""".format(
TARGET_DIRECTORY
)
)
except CaskGoError as error:
print(FAIL + notice + ENDC, file=sys.stderr)
fail("{0!s}".format(error))
if __name__ == "__main__":
sys.exit(main())