-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathget.io
executable file
·145 lines (125 loc) · 5.41 KB
/
get.io
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
#!/bin/bash
#set -uo pipefail
#==============================================================#
# File : get
# Desc : download & install pigsty src
# Ctime : 2022-10-30
# Mtime : 2025-01-12
# Path : https://repo.pigsty.io/get (global, default)
# Usage : curl -fsSL https://repo.pigsty.io/get | bash
# Deps : curl
# Author : Ruohang Feng ([email protected])
# License : AGPLv3
#==============================================================#
DEFAULT_VERSION=v3.2.1
# To install the latest version of pigsty (v3.2.1):
# curl -fsSL https://repo.pigsty.io/get | bash
# To install a specific version of pigsty (e.g. v3.2.0)
# curl -fsSL https://repo.pigsty.io/get | bash -s v3.2.1
#--------------------------------------------------------------#
# Log Util
#--------------------------------------------------------------#
# if output is a terminal, setup color alias, else use empty str
if [[ -t 1 ]]; then
__CN='\033[0m';__CB='\033[0;30m';__CR='\033[0;31m';__CG='\033[0;32m';
__CY='\033[0;33m';__CB='\033[0;34m';__CM='\033[0;35m';__CC='\033[0;36m';__CW='\033[0;37m';
else
__CN='';__CB='';__CR='';__CG='';__CY='';__CB='';__CM='';__CC='';__CW='';
fi
function log_info() { printf "[${__CG} OK ${__CN}] ${__CG}$*${__CN}\n"; }
function log_warn() { printf "[${__CY}WARN${__CN}] ${__CY}$*${__CN}\n"; }
function log_error() { printf "[${__CR}FAIL${__CN}] ${__CR}$*${__CN}\n"; }
function log_red() { printf "[${__CR}WARN${__CN}] ${__CR}$*${__CN}\n"; }
function log_debug() { printf "[${__CB}HINT${__CN}] ${__CB}$*${__CN}\n"; }
function log_title() { printf "[${__CG}$1${__CN}] ${__CG}$2${__CN}\n"; }
function log_hint() { printf "${__CB}$*${__CN}\n"; }
function log_line() { printf "${__CM}[$*] ===========================================${__CN}\n"; }
#--------------------------------------------------------------#
# Version
#--------------------------------------------------------------#
# arg1 > env > default
if [[ -n "$1" ]]; then
VERSION="$1"
VERSION_FROM="arg"
elif [[ -n "${PIGSTY_VERSION}" ]]; then
VERSION="${PIGSTY_VERSION}"
VERSION_FROM="env"
else
VERSION=${DEFAULT_VERSION}
VERSION_FROM="default"
fi
#--------------------------------------------------------------#
# Reference
#--------------------------------------------------------------#
log_line "${VERSION}"
log_hint "$ curl -fsSL https://repo.pigsty.io/get | bash"
log_title "Site" "https://pigsty.io"
log_title "Demo" "https://demo.pigsty.cc"
log_title "Repo" "https://github.com/Vonng/pigsty"
log_title "Docs" "https://pigsty.io/docs/setup/install"
log_line "Download"
log_info "version = ${VERSION} (from ${VERSION_FROM})"
#--------------------------------------------------------------#
# Download
#--------------------------------------------------------------#
SRC_FILENAME="pigsty-${VERSION}.tgz"
DOWNLOAD_TO="/tmp/${SRC_FILENAME}"
DOWNLOAD_URL="https://repo.pigsty.io/src/${SRC_FILENAME}"
# download file from url, if file already exists with same size, skip download
function download_file(){
local data_url=$1
local data_file=$2
log_hint "curl -fSL ${data_url} -o ${data_file}"
# if file exists and have the exact same size, just use it and skip downloading
if [[ -f ${data_file} ]]; then
if [[ "$(uname)" == "Darwin" ]]; then
size=$(stat -f %z "${data_file}")
else
size=$(stat -c %s "${data_file}")
fi
curl_size=$(curl -fsLI ${data_url} | grep -i 'Content-Length' | awk '{print $2}' | tr -d '\r')
if [[ ${size} -eq ${curl_size} ]]; then
log_warn "tarball = ${data_file} exists, size = ${size}, use it"
#log_hint "rm -rf ${data_file}; # remove it to redownload source tarball"
return 0
fi
fi
curl -# -fSL ${data_url} -o ${data_file}
return $?
}
download_file "${DOWNLOAD_URL}" "${DOWNLOAD_TO}"
if [[ $? -ne 0 ]]; then
log_error "fail to download pigsty source from ${DOWNLOAD_URL}"
log_hint "check: https://pigsty.io/docs/setup/install"
log_hint "alternative url: ${SECONDARY_SRC_URL}"
exit 2
fi
log_info "md5sums = $(md5sum ${DOWNLOAD_TO})"
#--------------------------------------------------------------#
# Install
#--------------------------------------------------------------#
INSTALL_TO="${HOME}/pigsty"
INSTALL_DIR=$(dirname ${INSTALL_TO})
log_line "Install"
if [[ $(whoami) == "root" ]]; then
log_warn "os user = root , it's recommended to install as a sudo-able admin"
fi
# extract to home dir if ~/pigsty not exists
if [[ ! -d ${INSTALL_TO} ]]; then
log_info "install = ${INSTALL_TO}, from ${DOWNLOAD_TO}"
tar -xf "${DOWNLOAD_TO}" -C "${INSTALL_DIR}";
else
log_warn "pigsty already installed on '${INSTALL_TO}', if you wish to overwrite:"
log_hint "sudo rm -rf /tmp/pigsty_bk; cp -r ${INSTALL_TO} /tmp/pigsty_bk; # backup old"
log_hint "sudo rm -rf /tmp/pigsty; tar -xf ${DOWNLOAD_TO} -C /tmp/; # extract new"
log_hint "rsync -av --exclude='/pigsty.yml' --exclude='/files/pki/***' /tmp/pigsty/ ${INSTALL_TO}/; # rsync src"
fi
#--------------------------------------------------------------#
# Next Hint
#--------------------------------------------------------------#
log_line "TodoList"
log_hint "cd ${INSTALL_TO}"
log_hint './bootstrap # [OPTIONAL] install ansible & use offline package'
log_hint './configure # [OPTIONAL] preflight-check and config generation'
log_hint './install.yml # install pigsty modules according to your config.'
log_line "Complete"