summaryrefslogtreecommitdiffstats
path: root/scripts/misc.bash
blob: e3bd51ac96aab2ffd2f615e49373682a7c742bf3 (plain)
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
#!/usr/bin/env bash

function golang_lint_check() {
	pushd "$PROJECT_ROOT"/interfacer || _panic
	diff -u <(echo -n) <(gofmt -d ./)
	popd || _panic
}

function golang_lint_fix() {
	gofmt -w ./interfacer
}

function prettier_fix() {
	pushd "$PROJECT_ROOT"/webext || _panic
	prettier --write '{src,test}/**/*.js'
	popd || _panic
}

function parse_firefox_version_from_ci_config() {
	local line && line=$(grep 'firefox-version:' <"$PROJECT_ROOT"/.github/workflows/main.yml)
	local version && version=$(echo "$line" | tr -s ' ' | cut -d ' ' -f 3)
	[ "$version" = "" ] && _panic "Couldn't parse Firefox version"
	echo -n "$version"
}

function install_firefox() {
	local version && version=$(parse_firefox_version_from_ci_config)
	local destination=/tmp
	echo "Installing Firefox v$version to $destination..."
	mkdir -p "$destination"
	pushd "$destination" || _panic
	curl -L -o firefox.tar.bz2 \
		"https://ftp.mozilla.org/pub/firefox/releases/$version/linux-x86_64/en-US/firefox-$version.tar.bz2"
	bzip2 -d firefox.tar.bz2
	tar xf firefox.tar
	popd || _panic
}

function parse_golang_version_from_go_mod() {
	local path=$1
	[ "$path" = "" ] && _panic "Path to Golang interfacer code not passed"
	local line && line=$(grep '^go ' <"$path"/go.mod)
	local version && version=$(echo "$line" | tr -s ' ' | cut -d ' ' -f 2)
	[ "$(echo "$version" | tr -s ' ')" == "" ] && _panic "Couldn't parse Golang version"
	echo -n "$version"
}

function install_golang() {
	local path=$1
	[ "$path" = "" ] && _panic "Path to Golang interfacer code not passed"
	local version && version=$(parse_golang_version_from_go_mod "$path")
	[ "$GOPATH" = "" ] && _panic "GOPATH not set"
	[ "$GOROOT" = "" ] && _panic "GOROOT not set"
	echo "Installing Golang v$version... to $GOROOT"
	curl -L \
		-o go.tar.gz \
		https://dl.google.com/go/go"$version".linux-amd64.tar.gz
	mkdir -p "$GOPATH"/bin
	mkdir -p "$GOROOT"
	tar -C "$GOROOT/.." -xzf go.tar.gz
	go version
}