-
Notifications
You must be signed in to change notification settings - Fork 90
/
install.ab
146 lines (125 loc) Β· 5.17 KB
/
install.ab
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
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
import { has_failed, input_prompt } from "std/env"
import { split_chars } from "std/text"
import { array_contains } from "std/array"
import { file_exists } from "std/fs"
import { get_os, get_arch, get_place, get_bins_folder } from "./shared.ab"
let name = "amber"
let target = "amber"
let archive = "amber.tar.xz"
let agent = has_failed("uname -a")
then "unknown"
else trust $ uname -a $
echo ""
fun get_latest_release_tag() {
let tag_url = "https://api.github.com/repos/amber-lang/{name}/releases/latest"
let tag_json = $ curl -sL "{tag_url}" $?
// Get the tag name from the JSON
let tag = $ echo "\${nameof tag_json}" \
| grep -Eo "tag_name\\"[^\\"]*\\"([^\\"]+)\\"" \
| grep -Eo "\\"[^\\"]+\\"\$" \
| grep -Eo "[^\\"\\s]+" $?
return tag
}
main(args) {
let os = get_os()
let arch = get_arch()
let user_only_install = array_contains(args, "--user")
let place = get_place(user_only_install)
let bins_folder = get_bins_folder(user_only_install)
// Check if such directory exists
trust $ test -d "{place}" $
if status == 0 {
echo "Amber already installed"
echo "It seems that Amber is already installed on your system. ({place})"
echo "If you want to reinstall Amber, uninstall it first."
echo "(Find out more at https://docs.amber-lang.com/getting_started/installation#uninstallation)"
exit 2
}
// Check if curl is installed
if has_failed("curl -V") {
echo "Curl is not installed on your system."
echo "Please install `curl` and try again."
exit 1
}
echo "Installing Amber... π"
// Make the directories we need first to ensure we have permissions before downloading any files
// this decreases the chance that our script results in partial installation leaving assets behind
let sudo = user_only_install then "" else "sudo"
// Create directory for amber
silent $ {sudo} mkdir -p "{place}" $ failed {
echo "Failed to create directory for amber."
if user_only_install {
echo "Please make sure that root user can access {place} directory."
} else {
echo "Please make sure that your user can access {place} directory."
}
exit 1
}
if user_only_install {
silent $ mkdir -p "{bins_folder}" $ failed {
echo "Failed to create directory for amber bin at {bins_folder}."
exit 1
}
}
let tag = get_latest_release_tag() failed {
echo "Failed to get the latest release tag."
echo "Please try again or use another download method."
exit 1
}
// Set the download link
let url = "https://github.com/amber-lang/{name}/releases/download/{tag}/amber-{arch}-{os}.tar.xz"
// Download amber
silent $ curl -L -o "{archive}" "{url}" $ failed {
echo "Curl failed to download amber."
echo "Something went wrong. Please try again later."
exit 1
}
// Move archived version of amber
$ {sudo} mv "{archive}" "{place}/{archive}" $ failed {
echo "Failed to move amber to the installation directory."
echo "Please make sure that root user can access {place} directory."
exit 1
}
// Unarchive amber
silent $ {sudo} tar --strip-components=1 -xvf {place}/{archive} -C {place} $ failed {
echo "Failed to unarchive amber at {place}/{archive}"
echo "Please make sure that you have `tar` command installed."
exit 1
}
// Delete the archive
$ {sudo} rm {place}/{archive} $ failed {
echo "Failed to remove downloaded archive at {place}/{archive}"
exit 1
}
// Give permissions to execute amber
$ {sudo} chmod +x "{place}/{target}" $ failed {
echo "Failed to give permissions to execute amber."
echo "Please make sure that root user can access {place} directory."
exit 1
}
// Delete the previous symbolic link
if file_exists("{bins_folder}/{target}") {
$ {sudo} rm "{bins_folder}/{target}" $ failed {
echo "Failed to remove the previous amber symbol link."
echo "Please make sure that root user can access {bins_folder} directory."
exit 1
}
}
// Create amber symbol link
$ {sudo} ln -s "{place}/{target}" "{bins_folder}/{target}" $ failed {
echo "Failed to create amber symbol link."
echo "Please make sure that root user can access {bins_folder} directory."
exit 1
}
let nickname = input_prompt("Would you like to help improve Amber by sharing your OS info with our developer database? Enter your GitHub nickname (or any nickname) or type `no`:")
if (nickname != "no") {
// Send feedback to the server
trust silent $ curl -G --data-urlencode "agent={agent}" --data-urlencode "nickname={nickname}" --data-urlencode "name=download" "https://amber-lang.com/api/visit" $
}
// Send success message
echo "Amber has been installed successfully. π"
echo "> Now you can use amber by typing `amber` in your terminal."
if user_only_install {
echo "> Since you requested a user only install with `--user` ensure that ~/.local/bin is in your \\$PATH."
}
}