├── .github └── ISSUE_TEMPLATE │ └── bug_report.md ├── README.md ├── LICENSE └── codius-install.sh /.github/ISSUE_TEMPLATE/bug_report.md: -------------------------------------------------------------------------------- 1 | --- 2 | name: Bug report 3 | about: Create a report to help us improve 4 | 5 | --- 6 | 7 | **Describe the issues** 8 | A clear and concise description of what the issues is. 9 | 10 | **To Reproduce** 11 | Steps to reproduce the behavior: 12 | 1. run the script 13 | 2. enter num `2` and hit ENTER 14 | 3. past or attach the log out of the debug 15 | 16 | **Expected behavior** 17 | A clear and concise description of what you expected to happen. 18 | 19 | **Screenshots** 20 | If applicable, add screenshots to help explain your problem. 21 | 22 | **Additional context** 23 | Add any other context about the problem here. 24 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | ## codius-install 2 | Codius (https://codius.org/) installer for CentOS, Ubuntu, Debian ... 3 | 4 | This script will let you setup your own codius peer in no more than a minute, even if you haven't used codius before. It has been designed to be as unobtrusive and universal as possible. 5 | 6 | ### Installation 7 | Run the script and follow the assistant: 8 | 9 | `wget https://raw.githubusercontent.com/N3TC4T/codius-install/master/codius-install.sh -O codius-install.sh && bash codius-install.sh` 10 | ### ScreenShot 11 | ![screen](https://user-images.githubusercontent.com/6250203/41824308-780a9170-7823-11e8-8611-642b84895ccb.png) 12 | 13 | ### Contact 14 | 15 | [ 16 | ](https://twitter.com/baltazar223) 17 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2018 XRP Community 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /codius-install.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | # File : codius-install.sh 3 | # Author : N3TC4T 4 | # Date : 16.06.2018 5 | # Last Modified Date: 08.08.2018 6 | # Last Modified By : N3TC4T 7 | # Copyright (c) 2018 N3TC4T 8 | # 9 | # Permission is hereby granted, free of charge, to any person obtaining a copy 10 | # of this software and associated documentation files (the "Software"), to deal 11 | # in the Software without restriction, including without limitation the rights 12 | # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 13 | # copies of the Software, and to permit persons to whom the Software is 14 | # furnished to do so, subject to the following conditions: 15 | # 16 | # The above copyright notice and this permission notice shall be included in 17 | # all copies or substantial portions of the Software. 18 | # 19 | # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 20 | # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 21 | # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 22 | # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 23 | # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 24 | # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 25 | # SOFTWARE. 26 | 27 | set -e 28 | 29 | ########## Variable ########## 30 | SUDO="" 31 | BASH_C="bash -c" 32 | SLEEP_SEC=10 33 | LOG_OUTPUT="/tmp/${0##*/}$(date +%Y-%m-%d.%H-%M)" 34 | CURRENT_USER="$(id -un 2>/dev/null || true)" 35 | BASE_DIR=$(cd "$(dirname "$0")"; pwd); cd ${BASE_DIR} 36 | INSTALLER_URL="https://raw.githubusercontent.com/N3TC4T/codius-install/master/codius-install.sh" 37 | ########## Hyperd ########## 38 | HYPERD_URL="https://codius-hyper-install.s3.amazonaws.com/hyper-bootstrap.sh" 39 | ########## Nodejs ########## 40 | NODEJS_RPM_URL="https://rpm.nodesource.com/setup_10.x" 41 | NODEJS_DEB_URL="https://deb.nodesource.com/setup_10.x" 42 | ########## Certbot ########## 43 | CERTBOT_AUTO_URL="https://dl.eff.org/certbot-auto" 44 | ########## Constant ########## 45 | SUPPORT_DISTRO=(debian ubuntu fedora centos) 46 | UBUNTU_CODE=(trusty utopic vivid wily xenial) 47 | DEBIAN_CODE=(jessie wheezy) 48 | CENTOS_VER=(6 7) 49 | FEDORA_VER=(20 21 22 23 24 25) 50 | #Color Constant 51 | RED=`tput setaf 1` 52 | GREEN=`tput setaf 2` 53 | YELLOW=`tput setaf 3` 54 | BLUE=`tput setaf 4` 55 | WHITE=`tput setaf 7` 56 | LIGHT=`tput bold ` 57 | RESET=`tput sgr0` 58 | #Error Message#Error Message 59 | ERR_ROOT_PRIVILEGE_REQUIRED=(10 "This install script need root privilege, please retry use 'sudo' or root user!") 60 | ERR_NOT_SUPPORT_PLATFORM=(20 "Sorry, Hyperd only support x86_64 platform!") 61 | ERR_NOT_SUPPORT_DISTRO=(21 "Sorry, The installer only support centos/ubuntu/debian/fedora now.") 62 | ERR_NOT_PUBLIC_IP=(11 "You need an public IP to run Codius!") 63 | ERR_MONEYD_CONFIGURE=(12 "There is an error on configuring moneyd , please check you entered correct secret and your account have at least 36 XRP. If you meet these requirements, please restart the script and try again.") 64 | ERR_NOT_SUPPORT_DISTRO_VERSION=(22) 65 | ERR_SCRIPT_NO_NEW_VERSION=(80 "You are using the newest codius installer\n") 66 | ERR_NO_CERTBOT_INSTALLED=(81 "Certbot is not installed!\n") 67 | ERR_UNKNOWN_MSG_TYPE=98 68 | ERR_UNKNOWN=99 69 | # Helpers ============================================== 70 | 71 | display_header() 72 | { 73 | cat <<"EOF" 74 | 75 | ____ _ _ ___ _ _ _ 76 | / ___|___ __| (_)_ _ ___ |_ _|_ __ ___| |_ __ _| | | ___ _ __ 77 | | | / _ \ / _` | | | | / __| | || '_ \/ __| __/ _` | | |/ _ \ '__| 78 | | |__| (_) | (_| | | |_| \__ \ | || | | \__ \ || (_| | | | __/ | 79 | \____\___/ \__,_|_|\__,_|___/ |___|_| |_|___/\__\__,_|_|_|\___|_| 80 | 81 | 82 | This script will let you setup your own Codius host in no more than two minutes, 83 | even if you haven't used codius before. 84 | It has been designed to be as unobtrusive and universal as possible. 85 | 86 | EOF 87 | } 88 | 89 | _box () { 90 | str="$@" 91 | len=$((${#str}+4)) 92 | for i in $(seq $len); do echo -n '.'; done; 93 | echo; echo ". "$str" ."; 94 | for i in $(seq $len); do echo -n '.'; done; 95 | echo 96 | } 97 | 98 | function spin_wait() { 99 | local -r SPIN_DELAY="0.1" 100 | local spinstr="⠏⠛⠹⠼⠶⠧" 101 | printf " " 102 | while kill -0 $1 2>/dev/random; do 103 | local tmp=${spinstr#?} 104 | 105 | if [ -z "$2" ]; then 106 | printf " \b\b\b${tmp:0:1} " 107 | else 108 | printf "${cl} ${tmp:0:1} ${2}" 109 | fi 110 | 111 | local spinstr=$tmp${spinstr%"$tmp"} 112 | sleep ${SPIN_DELAY} 113 | done 114 | printf "\033[3D\033[K ${LIGHT}${GREEN}Done${RESET}" 115 | # printf "\r\033[K" 116 | } 117 | 118 | function _exec() { 119 | local -i PID= 120 | local COMMAND=$1 121 | shift ## Clip the first value of the $@, the rest are the options. 122 | local COMMAND_OPTIONS="$@" 123 | local COMMAND_OUTPUT="" 124 | echo -e "\n==================================" >> "${LOG_OUTPUT}" 125 | echo "${COMMAND} $COMMAND_OPTIONS" >> "${LOG_OUTPUT}" 126 | echo -e "==================================\n" >> "${LOG_OUTPUT}" 127 | exec 3>$(tty) 128 | eval "time ${SUDO} bash -c '${COMMAND} ${COMMAND_OPTIONS}'" >>"${LOG_OUTPUT}" 2>&1 & 129 | PID=$! # Set global PGID to process id of the command we just ran. 130 | spin_wait "${PID}" 131 | exec 3>&- 132 | } 133 | 134 | function program_is_installed { 135 | # set to 1 initially 136 | local return_=1 137 | # set to 0 if not found 138 | type $1 >/dev/null 2>&1 || { local return_=0; } 139 | # return value 140 | echo "$return_" 141 | } 142 | 143 | function service_is_running { 144 | # set to 1 initially 145 | local return_=0 146 | # set to 0 if not found 147 | if (( $(ps -ef | grep -v grep | grep $1 | wc -l) > 0 )) ;then 148 | local return_=1 149 | fi 150 | # return value 151 | echo "$return_" 152 | } 153 | 154 | function echo_if { 155 | if [ $1 == 1 ]; then 156 | echo -e "${LIGHT}${GREEN}✔ ${RESET}" 157 | else 158 | echo -e "${RED}✘${RESET}" 159 | fi 160 | } 161 | 162 | new_line() { printf "\n"; } 163 | 164 | show_message() { 165 | case "$1" in 166 | debug) echo -e "\n[${BLUE}DEBUG${RESET}] : $2";; 167 | info) echo -e -n "\n${WHITE}$2${RESET}" ;; 168 | warn) echo -e "\n[${YELLOW}WARN${RESET}] : $2" ;; 169 | done|success) echo -e "${LIGHT}${GREEN}$2${RESET}" ;; 170 | error|failed) echo -e "\n[${RED}ERROR${RESET}] : $2" ;; 171 | esac 172 | } 173 | 174 | command_exist() { 175 | type "$@" > /dev/null 2>&1 176 | } 177 | 178 | 179 | get_curl() { 180 | CURL_C=""; USE_WGET="false" 181 | if (command_exist curl);then 182 | CURL_C='curl -SL -o ' 183 | elif (command_exist wget);then 184 | USE_WGET="true" 185 | CURL_C='wget -O ' 186 | fi 187 | 188 | echo "${USE_WGET}|${CURL_C}" 189 | } 190 | 191 | check_os_platform() { 192 | ARCH="$(uname -m)" 193 | if [[ "${ARCH}" != "x86_64" ]];then 194 | show_message error "${ERR_NOT_SUPPORT_PLATFORM[1]}" && exit ${ERR_NOT_SUPPORT_PLATFORM[0]} 195 | fi 196 | } 197 | check_deps_initsystem() { 198 | if [[ "${LSB_DISTRO}" == "ubuntu" ]] && [[ "${LSB_CODE}" == "utopic" ]];then 199 | INIT_SYSTEM="sysvinit" 200 | elif (command_exist systemctl);then 201 | INIT_SYSTEM="systemd" 202 | else 203 | INIT_SYSTEM="sysvinit" 204 | fi 205 | } 206 | 207 | check_os_distro() { 208 | LSB_DISTRO=""; LSB_VER=""; LSB_CODE="" 209 | if (command_exist lsb_release);then 210 | LSB_DISTRO="$(lsb_release -si)" 211 | LSB_VER="$(lsb_release -sr)" 212 | LSB_CODE="$(lsb_release -sc)" 213 | fi 214 | if [[ -z "${LSB_DISTRO}" ]];then 215 | if [[ -r /etc/lsb-release ]];then 216 | LSB_DISTRO="$(. /etc/lsb-release && echo "${DISTRIB_ID}")" 217 | LSB_VER="$(. /etc/lsb-release && echo "${DISTRIB_RELEASE}")" 218 | LSB_CODE="$(. /etc/lsb-release && echo "${DISTRIB_CODENAME}")" 219 | elif [[ -r /etc/os-release ]];then 220 | LSB_DISTRO="$(. /etc/os-release && echo "$ID")" 221 | LSB_VER="$(. /etc/os-release && echo "$VERSION_ID")" 222 | elif [[ -r /etc/fedora-release ]];then 223 | LSB_DISTRO="fedora" 224 | elif [[ -r /etc/debian_version ]];then 225 | LSB_DISTRO="Debian" 226 | LSB_VER="$(cat /etc/debian_version)" 227 | elif [[ -r /etc/centos-release ]];then 228 | LSB_DISTRO="CentOS" 229 | LSB_VER="$(cat /etc/centos-release | cut -d' ' -f3)" 230 | fi 231 | fi 232 | LSB_DISTRO=$(echo "${LSB_DISTRO}" | tr '[:upper:]' '[:lower:]') 233 | if [[ "${LSB_DISTRO}" == "debian" ]];then 234 | case ${LSB_VER} in 235 | 8) LSB_CODE="jessie";; 236 | 7) LSB_CODE="wheezy";; 237 | esac 238 | fi 239 | 240 | case "${LSB_DISTRO}" in 241 | ubuntu|debian) 242 | if [[ "${LSB_DISTRO}" == "ubuntu" ]] 243 | then SUPPORT_CODE_LIST="${UBUNTU_CODE[@]}"; 244 | else SUPPORT_CODE_LIST="${DEBIAN_CODE[@]}"; 245 | fi 246 | if (echo "${SUPPORT_CODE_LIST}" | grep -vqw "${LSB_CODE}");then 247 | show_message error "Hyper support ${LSB_DISTRO}( ${SUPPORT_CODE_LIST} ), but current is ${LSB_CODE}(${LSB_VER})" 248 | exit ${ERR_NOT_SUPPORT_DISTRO_VERSION[0]} 249 | fi 250 | ;; 251 | centos|fedora) 252 | CMAJOR=$( echo ${LSB_VER} | cut -d"." -f1 ) 253 | if [[ "${LSB_DISTRO}" == "centos" ]] 254 | then SUPPORT_VER_LIST="${CENTOS_VER[@]}"; 255 | else SUPPORT_VER_LIST="${FEDORA_VER[@]}"; 256 | fi 257 | if (echo "${SUPPORT_VER_LIST}" | grep -qvw "${CMAJOR}");then 258 | show_message error "Hyper support ${LSB_DISTRO}( ${SUPPORT_VER_LIST} ), but current is ${LSB_VER}" 259 | exit ${ERR_NOT_SUPPORT_DISTRO_VERSION[0]} 260 | fi 261 | ;; 262 | *) if [[ ! -z ${LSB_DISTRO} ]];then echo -e -n "\nCurrent OS is '${LSB_DISTRO} ${LSB_VER}(${LSB_CODE})'"; 263 | else echo -e -n "\nCan not detect OS type"; fi 264 | show_message error "${ERR_NOT_SUPPORT_DISTRO[1]}" 265 | exit ${ERR_NOT_SUPPORT_DISTRO[0]} 266 | ;; 267 | esac 268 | } 269 | 270 | check_user() { 271 | if [[ "${CURRENT_USER}" != "root" ]];then 272 | if (command_exist sudo);then 273 | SUDO='sudo' 274 | else 275 | show_message error "${ERR_ROOT_PRIVILEGE_REQUIRED[1]}" && exit ${ERR_ROOT_PRIVILEGE_REQUIRED[0]} 276 | fi 277 | show_message info "${WHITE}Hint: This installer needs root privilege\n" 278 | ${SUDO} echo -e "\n" 279 | fi 280 | } 281 | 282 | 283 | # ============================================== Helpers 284 | 285 | 286 | ################### INSTALL ########################### 287 | 288 | install() 289 | { 290 | 291 | local USE_WGET=$( echo $(get_curl) | awk -F"|" '{print $1}' ) 292 | local CURL_C=$( echo $(get_curl) | awk -F"|" '{print $2}' ) 293 | 294 | new_line 295 | show_message info "[-] I need to ask you a few questions before starting the setup." 296 | show_message info "[-] You can leave the default options and just press enter if you are ok with them." 297 | new_line 298 | new_line 299 | 300 | # checks for script 301 | check_user 302 | check_os_platform 303 | check_os_distro 304 | check_deps_initsystem 305 | 306 | 307 | 308 | # Server Ip Address 309 | echo "[+] First, provide the IPv4 address of the network interface" 310 | # Autodetect IP address and pre-fill for the user 311 | IP=$(ip addr | grep 'inet' | grep -v inet6 | grep -vE '127\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}' | grep -oE '[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}' | head -1) 312 | read -p "IP address: " -e -i $IP IP 313 | # If $IP is a private IP address, the server must be behind NAT 314 | if echo "$IP" | grep -qE '^(10\.|172\.1[6789]\.|172\.2[0-9]\.|172\.3[01]\.|192\.168)'; then 315 | show_message error "${ERR_NOT_PUBLIC_IP[1]}" 316 | exit "${ERR_NOT_PUBLIC_IP[0]}" 317 | fi 318 | 319 | # Hostname 320 | echo "[+] What is your Codius hostname?" 321 | read -p "Hostname: " -e -i codius.example.com HOSTNAME 322 | if [[ -z "$HOSTNAME" ]]; then 323 | show_message error "No Hostname entered, exiting..." 324 | exit 0 325 | fi 326 | 327 | # Wallet secret for Moneyd 328 | echo "[+] What is your XRP wallet secret? This is required for you to receive XRP via Moneyd." 329 | 330 | while true; do 331 | read -p "Wallet Secret: " -e SECRET 332 | if [[ -z "$SECRET" ]] || ! [[ "$SECRET" =~ ^s[a-zA-Z0-9]{28,}+$ ]] ; then 333 | show_message error "Invalid wallet secret entered, try again..." 334 | else 335 | break 336 | fi 337 | done 338 | 339 | 340 | # Email for certbot 341 | echo "[+] What is your email address?" 342 | while true; do 343 | read -p "Email: " -e EMAIL 344 | 345 | if [[ -z "$EMAIL" ]] || ! [[ "$EMAIL" =~ ^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,4}$ ]]; then 346 | show_message error "Invalid email entered, try again..." 347 | else 348 | break 349 | fi 350 | done 351 | 352 | 353 | show_message debug "Setting hostname using 'hostnamectl'" 354 | # Set hostname 355 | ${SUDO} hostnamectl set-hostname $HOSTNAME 356 | 357 | 358 | # Repositories and required packages ==================================== 359 | 360 | show_message info "[+] Installing required packages..." 361 | 362 | if [[ "${LSB_DISTRO}" == "centos" ]] && [[ "${CMAJOR}" == "7" ]];then 363 | _exec "rpm -ivh https://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm ; yum install -y gcc-c++ make epel-release git" 364 | elif [[ "${LSB_DISTRO}" == "centos" ]] && [[ "${CMAJOR}" == "6" ]];then 365 | _exec "rpm -ivh https://dl.fedoraproject.org/pub/epel/epel-release-latest-6.noarch.rpm ; yum install -y gcc-c++ make epel-release git" 366 | elif [[ "${LSB_DISTRO}" == "ubuntu" ]];then 367 | _exec "apt-get install -y software-properties-common ; add-apt-repository ppa:certbot/certbot ; apt-get install -y build-essential git qemu-kvm libvirt0 aufs-tools" 368 | elif [[ "${LSB_DISTRO}" == "debian" ]];then 369 | _exec "apt-get update ; apt-get install -y build-essential git qemu-kvm libvirt0 aufs-tools" 370 | fi 371 | 372 | 373 | # Hyperd ============================================== 374 | 375 | show_message info "[+] Installing Hyperd... " 376 | 377 | ${SUDO} ${CURL_C} /tmp/hyper-bootstrap.sh ${HYPERD_URL} >>"${LOG_OUTPUT}" 2>&1 && ${SUDO} chmod a+x /tmp/hyper-bootstrap.sh 378 | 379 | _exec bash /tmp/hyper-bootstrap.sh 380 | 381 | show_message info "[*] Starting Hyperd... " 382 | 383 | if [[ "${INIT_SYSTEM}" == "systemd" ]];then 384 | _exec "systemctl daemon-reload; systemctl enable hyperd; systemctl restart hyperd" 385 | else 386 | _exec "service hyperd enable; service hyperd restart" 387 | fi 388 | 389 | 390 | # ============================================== Hyperd 391 | 392 | # Nodejs ============================================== 393 | 394 | show_message info "[+] Installing Nodejs... " 395 | 396 | 397 | if [[ "${LSB_DISTRO}" == "centos" ]] || [[ "${LSB_DISTRO}" == "fedora" ]] ;then 398 | ${SUDO} ${CURL_C} /tmp/nodejs_10.sh ${NODEJS_RPM_URL} >>"${LOG_OUTPUT}" 2>&1 && ${SUDO} chmod a+x /tmp/nodejs_10.sh 399 | _exec "bash /tmp/nodejs_10.sh && yum install -y nodejs" 400 | elif [[ "${LSB_DISTRO}" == "ubuntu" ]] || [[ "${LSB_DISTRO}" == "debian" ]] ;then 401 | ${SUDO} ${CURL_C} /tmp/nodejs_10.sh ${NODEJS_DEB_URL} >>"${LOG_OUTPUT}" 2>&1 && ${SUDO} chmod a+x /tmp/nodejs_10.sh 402 | _exec "bash /tmp/nodejs_10.sh && apt-get install -y nodejs" 403 | fi 404 | 405 | # ============================================== Nodejs 406 | 407 | # Moneyd ============================================== 408 | 409 | show_message info "[+] Installing Moneyd... " 410 | # _exec yum install -y https://s3.us-east-2.amazonaws.com/codius-bucket/moneyd-xrp-4.0.0-1.x86_64.rpm 411 | _exec npm install -g moneyd moneyd-uplink-xrp --unsafe-perm 412 | 413 | ${SUDO} ${BASH_C} 'echo "[Unit] 414 | Description=ILP provider using XRP payment channels 415 | After=network.target nss-lookup.target 416 | 417 | [Service] 418 | ExecStart=/usr/bin/moneyd xrp:start 419 | Environment="DEBUG=*" 420 | Restart=always 421 | StandardOutput=syslog 422 | StandardError=syslog 423 | SyslogIdentifier=moneyd 424 | User=root 425 | Group=root 426 | 427 | [Install] 428 | WantedBy=multi-user.target" > /etc/systemd/system/moneyd-xrp.service' 429 | 430 | 431 | # Configuring Moneyd and starting service 432 | if [ -f ~/.moneyd.json ]; then 433 | show_message warn "old ~/.moneyd.json config file found , backup to ~/.moneyd.json.back" 434 | ${SUDO} mv ~/.moneyd.json ~/.moneyd.json.back 435 | fi 436 | 437 | 438 | # Todo: need to check 439 | # https://github.com/N3TC4T/codius-install/issues/4 440 | 441 | echo -ne "$SECRET\n" | ${SUDO} $(which moneyd) xrp:configure > /dev/null 2>&1 || { show_message error "${ERR_MONEYD_CONFIGURE[1]}" ; exit "${ERR_MONEYD_CONFIGURE[0]}" ; } 442 | 443 | # this will generate an random channel name 444 | #UUID_CHANNEL=$(cat /dev/urandom | tr -dc 'a-zA-Z0-9' | fold -w 32 | head -n 1) 445 | #sed -i "s/btp+wss:\/\//&${UUID_CHANNEL}/g" ~/.moneyd.json 446 | 447 | 448 | show_message info "[*] Starting Moneyd... " 449 | 450 | if [[ "${INIT_SYSTEM}" == "systemd" ]];then 451 | _exec "systemctl daemon-reload; systemctl enable moneyd-xrp ; systemctl restart moneyd-xrp" 452 | else 453 | _exec "service moneyd-xrp enable; service moneyd-xrp restart" 454 | fi 455 | 456 | 457 | # ============================================== Moneyd 458 | 459 | 460 | # Codius ============================================== 461 | 462 | show_message info "[+] Installing Codius... " 463 | _exec npm install -g codiusd --unsafe-perm 464 | 465 | ${SUDO} ${BASH_C} 'echo "[Unit] 466 | Description=Codiusd 467 | After=network.target nss-lookup.target 468 | [Service] 469 | ExecStart=/usr/bin/codiusd 470 | Environment="DEBUG=*" 471 | Environment="CODIUS_PUBLIC_URI=https://$HOSTNAME" 472 | Environment="CODIUS_XRP_PER_MONTH=10" 473 | Restart=always 474 | StandardOutput=syslog 475 | StandardError=syslog 476 | SyslogIdentifier=codiusd 477 | User=root 478 | Group=root 479 | [Install] 480 | WantedBy=multi-user.target" > /etc/systemd/system/codiusd.service' 481 | 482 | show_message info "[*] Starting Codius..." 483 | 484 | if [[ "${INIT_SYSTEM}" == "systemd" ]];then 485 | _exec "systemctl daemon-reload; systemctl enable codiusd ; systemctl restart codiusd" 486 | else 487 | _exec "service codiusd enable ; service codiusd restart" 488 | fi 489 | 490 | 491 | # ============================================== Codius 492 | 493 | # Subdomain DNS ============================================== 494 | new_line 495 | show_message info "[+] Please create two A records within your domain DNS like the examples below:" 496 | new_line 497 | cat < /dev/null; then 510 | break 511 | else 512 | show_message warn "It looks like the $HOSTNAME cannot be resolved yet, waiting 30s... " 513 | fi 514 | sleep 30 #check again in SLEEP seconds 515 | done 516 | 517 | # ============================================== Subdomain DNS 518 | 519 | 520 | # CertBOt ============================================== 521 | show_message info "[+] Generating certificate for ${HOSTNAME}" 522 | # certbot stuff 523 | 524 | show_message info "[+] Installing CertBot... " 525 | if [[ "${LSB_DISTRO}" == "centos" ]] || [[ "${LSB_DISTRO}" == "fedora" ]] ;then 526 | _exec "yum -y install certbot" 527 | elif [[ "${LSB_DISTRO}" == "ubuntu" ]];then 528 | _exec "apt-get install -y certbot" 529 | elif [[ "${LSB_DISTRO}" == "debian" ]];then 530 | ${SUDO} ${CURL_C} /usr/bin/certbot ${CERTBOT_AUTO_URL} >>"${LOG_OUTPUT}" 2>&1 && ${SUDO} chmod a+x /usr/bin/certbot 531 | _exec "/usr/bin/certbot" 532 | fi 533 | 534 | new_line 535 | show_message warn "In the next step you need to create two TXT records on your DNS as part of the DNS challenge \nPlease wait some time after creating these records before continuing." 536 | read -n1 -r -p "Press any key to continue..." 537 | 538 | # if [[ "${USE_WGET}" == "true" ]];then 539 | # ${CURL_C} -O /usr/sbin/certbot-auto ${CERTBOT_URL} >>"${LOG_OUTPUT}" 2>&1 && chmod a+x /usr/sbin/certbot-auto 540 | # else 541 | # ${CURL_C} /usr/sbin/certbot-auto ${NODEJS_URL} >>"${LOG_OUTPUT}" 2>&1 && chmod a+x /usr/sbin/certbot-auto 542 | # fi 543 | 544 | # certbot-auto --noninteractive --os-packages-only 545 | 546 | ${SUDO} certbot certonly --manual -d "${HOSTNAME}" -d "*.${HOSTNAME}" --agree-tos --email "${EMAIL}" --preferred-challenges dns-01 --server https://acme-v02.api.letsencrypt.org/directory 547 | 548 | # ============================================== CertBOt 549 | 550 | 551 | # Nginx ============================================== 552 | 553 | show_message info "[!] Installing Nginx... " 554 | 555 | 556 | if [[ "${LSB_DISTRO}" == "centos" ]] || [[ "${LSB_DISTRO}" == "fedora" ]] ;then 557 | # Install Package 558 | # Selinux allow nginx 559 | # Enable access for port 443 in firewalld 560 | _exec "yum -y install nginx ; setsebool -P httpd_can_network_connect 1 ; firewall-cmd --zone=public --add-port=443/tcp --permanent ; firewall-cmd --reload" 561 | 562 | elif [[ "${LSB_DISTRO}" == "ubuntu" ]] || [[ "${LSB_DISTRO}" == "debian" ]] ;then 563 | # Install Package 564 | # Adjust the Firewall 565 | _exec "apt-get install -y nginx ; ufw allow 'Nginx HTTP'" 566 | 567 | fi 568 | 569 | # show_message done "[!] Success installed Nginx" 570 | 571 | if [[ ! -e /etc/nginx/default.d ]]; then 572 | ${SUDO} mkdir /etc/nginx/default.d 573 | fi 574 | 575 | ${SUDO} echo 'return 301 https://$host$request_uri;' | ${SUDO} tee /etc/nginx/default.d/ssl-redirect.conf >> "${LOG_OUTPUT}" 2>&1 576 | 577 | show_message info "[!] Generating SSL file... It takes a while, don't panic." 578 | 579 | _exec openssl dhparam -out /etc/nginx/dhparam.pem 2048 580 | 581 | 582 | if [[ ! -e /etc/nginx/conf.d ]]; then 583 | ${SUDO} mkdir /etc/nginx/conf.d 584 | fi 585 | 586 | ${SUDO} ${BASH_C} 'echo " 587 | map \$http_upgrade \$connection_upgrade { 588 | default upgrade; 589 | '\'''\'' \$http_connection; 590 | } 591 | server { 592 | listen 443 ssl; 593 | 594 | ssl_certificate /etc/letsencrypt/live/$HOSTNAME/fullchain.pem; 595 | ssl_certificate_key /etc/letsencrypt/live/$HOSTNAME/privkey.pem; 596 | 597 | ssl_protocols TLSv1.2; 598 | ssl_prefer_server_ciphers on; 599 | ssl_dhparam /etc/nginx/dhparam.pem; 600 | ssl_ciphers ECDHE-RSA-AES256-GCM-SHA512:DHE-RSA-AES256-GCM-SHA512:ECDHE-RSA-AES256-GCM-SHA384:DHE-RSA-AES256-GCM-SHA384:ECDHE-RSA-AES256-SHA384; 601 | ssl_ecdh_curve secp384r1; 602 | ssl_session_timeout 10m; 603 | ssl_session_cache shared:SSL:10m; 604 | ssl_session_tickets off; 605 | ssl_stapling on; 606 | ssl_stapling_verify on; 607 | resolver 1.1.1.1 1.0.0.1 valid=300s; 608 | resolver_timeout 5s; 609 | add_header Strict-Transport-Security '\''max-age=63072000; includeSubDomains; preload'\''; 610 | add_header X-Frame-Options DENY; 611 | add_header X-Content-Type-Options nosniff; 612 | add_header X-XSS-Protection '\''1; mode=block'\''; 613 | 614 | location / { 615 | proxy_pass http://127.0.0.1:3000; 616 | proxy_set_header Upgrade \$http_upgrade; 617 | proxy_set_header Connection \$connection_upgrade; 618 | proxy_buffering off; 619 | proxy_set_header Host \$host; 620 | proxy_set_header X-Forwarded-For \$remote_addr; 621 | proxy_connect_timeout 300; 622 | proxy_send_timeout 300; 623 | proxy_read_timeout 300; 624 | send_timeout 300; 625 | 626 | } 627 | }" > /etc/nginx/conf.d/codius.conf' 628 | 629 | show_message info "[*] Starting Nginx... " 630 | 631 | if [[ "${INIT_SYSTEM}" == "systemd" ]];then 632 | _exec "systemctl daemon-reload; systemctl enable nginx ; systemctl restart nginx" 633 | else 634 | _exec "service nginx enable ; service nginx restart" 635 | fi 636 | 637 | # ============================================== Nginx 638 | 639 | 640 | # ============================================== Finishing 641 | new_line 642 | printf '%*s\n' "${COLUMNS:-$(tput cols)}" '' | tr ' ' = 643 | new_line 644 | show_message done "[!] Congratulations, it looks like you installed Codius successfully!" 645 | new_line 646 | show_message done "[-] You can check your Codius by opening https://$HOSTNAME or by searching for your host at https://codiushosts.com" 647 | show_message done "[-] For installation log visit $LOG_OUTPUT" 648 | new_line 649 | printf '%*s\n' "${COLUMNS:-$(tput cols)}" '' | tr ' ' = 650 | 651 | 652 | new_line 653 | show_message warn "If you have problems opening Codius we recommend rebooting your system to complete the installation." 654 | new_line 655 | read -p "Reboot now? [y/N]: " -e REBOOT 656 | 657 | if [[ "$REBOOT" = 'y' || "$REBOOT" = 'Y' ]]; then 658 | echo "Rebooting ..." 659 | ${SUDO} reboot 660 | else 661 | exit 662 | fi 663 | } 664 | 665 | 666 | 667 | ################### UPDATE ########################### 668 | 669 | update() 670 | { 671 | check_deps_initsystem 672 | check_user 673 | # We need to check if Moneyd installed with NPM or Yarn 674 | 675 | local PACKAGES=(moneyd codiusd moneyd-uplink-xrp) 676 | local PACKAGE_MANAGER= 677 | 678 | show_message info "[-] Checking packages availability..." 679 | for package in "${PACKAGES[@]}" 680 | do 681 | local FOUND_IN_YARN=0 682 | local FOUND_IN_NPM=0 683 | # check if Moneyd installed with NPM 684 | npm list --depth 0 --global "$package" > /dev/null 2>&1 && { local FOUND_IN_NPM=1; } 685 | # check in Yarn 686 | yarn global list --depth=0 2>&1 | grep -q "$package" && { local FOUND_IN_YARN=1; } 687 | 688 | if [ $FOUND_IN_YARN == 0 ] && [ $FOUND_IN_NPM == 0 ]; then 689 | show_message error "$package is not installed with YARN or NPM !" 690 | PACKAGES=( "${PACKAGES[@]/$package}" ) 691 | fi 692 | 693 | if ! [[ "$PACKAGE_MANAGER" ]]; then 694 | if [ $FOUND_IN_YARN == 1 ]; then 695 | PACKAGE_MANAGER='yarn' 696 | elif [ $FOUND_IN_NPM == 1 ]; then 697 | PACKAGE_MANAGER='npm' 698 | fi 699 | fi 700 | 701 | 702 | done 703 | 704 | if [ -z "$PACKAGES" ]; then 705 | show_message error "No package to update!" && exit 0 706 | fi 707 | 708 | if [ "$PACKAGE_MANAGER" == "npm" ]; then 709 | new_line 710 | show_message debug "Checking $(echo "${PACKAGES[@]}") version using NPM ..." 711 | for package in ${PACKAGES[@]} 712 | do 713 | output=$(npm -g outdated --parseable --depth=0 | grep "$package" || :) 714 | if [[ $output ]] ; then 715 | local from_version=$( echo $output | cut -d: -f3) 716 | local to_version=$( echo $output | cut -d: -f2) 717 | show_message info "[+] Updating ${package} from ${from_version} to ${to_version}... " 718 | _exec npm update -g $package --unsafe-perm 719 | else 720 | show_message info "[+] ${package} already installed latest version." 721 | fi 722 | done 723 | else 724 | show_message debug "Updating $(echo "${PACKAGES[@]}") using YARN ..." 725 | new_line 726 | show_message info "[!] please press SPACE on your keyboard to activate the packages needed to upgrade." 727 | new_line 728 | ${SUDO} yarn global add moneyd@latest codiusd@latest moneyd-uplink-xrp@latest --force 729 | fi 730 | 731 | printf "\n\n" 732 | read -p "[?] Restarting Moneyd and Codiusd services? [y/N]: " -e RESTART_SERVICE 733 | 734 | if [[ "$RESTART_SERVICE" = 'y' || "$RESTART_SERVICE" = 'Y' ]]; then 735 | for service in moneyd-xrp codiusd 736 | do 737 | show_message info "[-] Restarting ${service} ..." 738 | if [[ "${INIT_SYSTEM}" == "systemd" ]];then 739 | ${SUDO} systemctl restart $service 740 | else 741 | ${SUDO} service $service restart 742 | fi 743 | done 744 | fi 745 | printf "\n\n" 746 | show_message done "[!] Everything done!" 747 | 748 | printf "\n\n" 749 | 750 | exit 751 | 752 | } 753 | 754 | ################### CLEANUP ########################### 755 | 756 | clean(){ 757 | 758 | check_user 759 | check_os_platform 760 | check_os_distro 761 | check_deps_initsystem 762 | 763 | local services=( hyperd moneyd-xrp codiusd nginx ) 764 | 765 | show_message warn "This action will remove packages listed below and all configuration files belonging to them: 766 | \n* Codiusd\n* Moneyd\n* Hyperd\n* Certbot\n* Nginx\n* Nodejs (npm & yarn)" 767 | 768 | new_line 769 | read -p "Continue Anyway? [y/N]: " -e CONTINUE 770 | 771 | if ! [[ "$CONTINUE" = 'y' || "$CONTINUE" = 'Y' ]]; then 772 | exit 0 773 | fi 774 | 775 | 776 | show_message info "[!] Stoping services... " 777 | for i in "${services[@]}" 778 | do 779 | if [[ "${INIT_SYSTEM}" == "systemd" ]];then 780 | ${SUDO} systemctl stop $i || true 781 | else 782 | ${SUDO} service $i stop || true 783 | fi 784 | done 785 | 786 | # umount hyperd running pods 787 | for mount in `cat /proc/mounts | grep /run/hyper | awk '{ print $2 }'`; do umount $mount || true; done 788 | for mount in `cat /proc/mounts | grep /var/lib/hyper/hosts | awk '{ print $2 }'`; do umount $mount || true; done 789 | 790 | # remove packages from yarn 791 | if (command_exist yarn);then 792 | ${SUDO} yarn global remove moneyd codiusd moneyd-uplink-xrp || true 793 | fi 794 | 795 | 796 | # npm uninstall -g 797 | ${SUDO} npm uninstall -g moneyd codiusd moneyd-uplink-xrp --unsafe-perm 798 | 799 | 800 | if [[ "${LSB_DISTRO}" == "centos" ]] || [[ "${LSB_DISTRO}" == "fedora" ]] ;then 801 | ${SUDO} yum remove -y nodejs hyperd nginx qemu-hyper hyperstart hyper-container certbot 802 | elif [[ "${LSB_DISTRO}" == "ubuntu" ]] || [[ "${LSB_DISTRO}" == "debian" ]] ;then 803 | for i in nodejs hyperd nginx qemu-kvm libvirt0 hyperstart hypercontainer certbot aufs-tools; do ${SUDO} apt-get -y remove $i || true ;done 804 | ${SUDO} apt -y autoremove || true 805 | fi 806 | 807 | files_to_remove=("$HOME/.moneyd.json" "$HOME/.moneyd.json.back" "/etc/systemd/system/moneyd-xrp.service" "/etc/systemd/system/codiusd.service" , "/usr/bin/certbot", "/etc/nginx/conf.d/codius.conf") 808 | dirs_to_remove=("$HOME/.yarn" "/etc/letsencrypt" "/var/lib/hyper" "/run/hyper" "/var/log/hyper") 809 | 810 | for f in "${files_to_remove[@]}" 811 | do 812 | if [[ -f $f ]]; then 813 | ${SUDO} rm -rf $f 814 | fi 815 | done 816 | 817 | for d in "${dirs_to_remove[@]}" 818 | do 819 | if [ -d "$d" ]; then 820 | ${SUDO} rm -rf $d 821 | fi 822 | done 823 | 824 | 825 | if [[ "${INIT_SYSTEM}" == "systemd" ]];then 826 | ${SUDO} systemctl daemon-reload 827 | fi 828 | 829 | printf "\n\n" 830 | show_message done "[*] Everything cleaned successfully!" 831 | printf "\n\n" 832 | 833 | exit 0 834 | } 835 | 836 | 837 | ################### RENEW ########################### 838 | renew() 839 | { 840 | show_message info "[*] Checking for certificate status..." 841 | new_line 842 | new_line 843 | 844 | 845 | local HOSTNAME=$(hostname) 846 | 847 | local canRenew=false 848 | local notBefore=`echo | /usr/bin/openssl s_client -connect ${HOSTNAME}:443 2>/dev/null | openssl x509 -noout -dates | grep notBefore | cut -d'=' -f2` 849 | local notAfter=`echo | /usr/bin/openssl s_client -connect ${HOSTNAME}:443 2>/dev/null | openssl x509 -noout -dates | grep notAfter | cut -d'=' -f2` 850 | 851 | local notBeforeUnix=`date --date="${notBefore}" +"%s"` 852 | local today=`date` 853 | local todayUnix=`date --date="${today}" +"%s"` 854 | local eightyfivedays="7344000" 855 | local renewDateUnix=$((notBeforeUnix + eightyfivedays)) 856 | local renewDate=`date -d @$renewDateUnix` 857 | 858 | if [ $renewDateUnix -gt $todayUnix ]; then 859 | show_message success "You still have time. \nToday is ${today}. \nWaiting until ${renewDate} to renew. \n${notAfter} is when your SSL certificate expires." 860 | new_line 861 | exit 0 862 | else 863 | show_message warn "Time to renew your certificate. Today is ${today} and your certificate expires ${notAfter}." 864 | fi 865 | 866 | 867 | #check for certbot command 868 | CERTBOT=$(which certbot-auto certbot|head -n1) 869 | if [ -z "$CERTBOT" ]; then 870 | show_message error "${ERR_NO_CERTBOT_INSTALLED[1]}" && exit ${ERR_NO_CERTBOT_INSTALLED[0]} 871 | fi 872 | 873 | # ask if user wants to renew 874 | read -p "Do you want to renew? [y/N]: " -e RENEW 875 | 876 | if [[ "$RENEW" = 'y' || "$RENEW" = 'Y' ]]; then 877 | new_line 878 | show_message warn "If the challenge TXT dosn't exist in your DNS please create them. \nAnd Please don't forget to wait some time after creating records!" 879 | read -n1 -r -p "Press any key to continue ..." 880 | 881 | ${SUDO} ${CERTBOT} certonly --manual -d "${HOSTNAME}" -d "*.${HOSTNAME}" --agree-tos --preferred-challenges dns-01 --server https://acme-v02.api.letsencrypt.org/directory 882 | 883 | show_message info "[!] Regenerating SSL file. It takes a while, don't panic." 884 | _exec openssl dhparam -out /etc/nginx/dhparam.pem 2048 885 | 886 | show_message info "[*] Restarting Nginx... " 887 | 888 | if [[ "${INIT_SYSTEM}" == "systemd" ]];then 889 | _exec "systemctl restart nginx" 890 | else 891 | _exec "service nginx restart" 892 | fi 893 | 894 | show_message done "[*] Everything done!" 895 | new_line 896 | fi 897 | 898 | exit 0 899 | 900 | 901 | } 902 | 903 | 904 | ################### DEBUG ########################### 905 | debug(){ 906 | check_deps_initsystem 907 | 908 | # active debug for commands 909 | export DEBUG=* 910 | # get hostname 911 | local HOSTNAME=$(hostname) 912 | # some env variables 913 | export CODIUS_PUBLIC_URI=https://$HOSTNAME 914 | 915 | 916 | local services=( hyperd moneyd codiusd nginx ) 917 | local commands=( node npm hyperd hyperctl moneyd codiusd certbot ) 918 | local debug_commands=('node -v ; npm -v ; yarn -v' 919 | 'hyperd run -t test /bin/sh' 920 | 'hyperctl info' 921 | 'hyperctl list' 922 | 'moneyd xrp:start' 923 | 'moneyd xrp:info' 924 | 'codiusd' 925 | 'netstat -tulpn' 926 | ) 927 | 928 | 929 | new_line 930 | # check for codius avaiblity throught URL 931 | status="$(curl -Is https://${HOSTNAME}/version | head -1)" 932 | if [[ $status ]]; then 933 | validate=( $status ) 934 | if [ ${validate[-2]} == "200" ]; then 935 | show_message success "[*] It looks likes Codius is running properly in your host." 936 | new_line 937 | read -p "Continue Anyway ? [y/N]: " -e CONTINUE 938 | 939 | if ! [[ "$CONTINUE" = 'y' || "$CONTINUE" = 'Y' ]]; then 940 | exit 0 941 | fi 942 | 943 | else 944 | show_message warn "It looks like Codius is not running as expected ..." 945 | fi 946 | else 947 | show_message warn "It looks like Codius is not running as expected..." 948 | fi 949 | 950 | 951 | show_message info "[+] Start Debuging ..." 952 | printf "\n\n" 953 | _box "Checking required installed packages" 954 | new_line 955 | echo "------------------------------------------" 956 | printf "%-20s %-5s\n" "PACKAGE" "STATUS" 957 | echo "------------------------------------------" 958 | for i in "${commands[@]}" 959 | do 960 | printf "%-20s %-5s" $i $(echo_if $(program_is_installed $i)) 961 | printf "\n" 962 | done 963 | 964 | new_line 965 | _box "Checking required running services" 966 | new_line 967 | echo "------------------------------------------" 968 | printf "%-20s %-5s\n" "SERVICE" "STATUS" 969 | echo "------------------------------------------" 970 | for i in "${services[@]}" 971 | do 972 | printf "%-20s %-5s" $i $(echo_if $(service_is_running $i)) 973 | printf "\n" 974 | done 975 | 976 | 977 | show_message info "[?] Creating full services log file?" 978 | show_message warn "With this action all Codius services will restart for debuging." 979 | new_line 980 | read -p "Do you want to continue ? [y/N]: " -e DEBUG 981 | if ! [[ "$DEBUG" = 'y' || "$DEBUG" = 'Y' ]]; then 982 | exit 0 983 | fi 984 | 985 | 986 | local TMPFILE="/tmp/codius_debug-$(date +%Y-%m-%d.%H-%M)" 987 | 988 | show_message info "[!] Stoping services... " 989 | for i in "${services[@]}" 990 | do 991 | if [ "$i" = moneyd ]; then i='moneyd-xrp'; fi 992 | if [[ "${INIT_SYSTEM}" == "systemd" ]];then 993 | ${SUDO} systemctl stop $i >>"${TMPFILE}" 2>&1 994 | else 995 | ${SUDO} service $i stop >>"${TMPFILE}" 2>&1 996 | fi 997 | done 998 | 999 | show_message info "[!] Execute services and commands in debug mode ... " 1000 | show_message info "[*] This will take some time..." 1001 | for c in "${debug_commands[@]}" 1002 | do 1003 | echo -e "\n==================================" >> "${TMPFILE}" 1004 | echo "${c}" >> "${TMPFILE}" 1005 | echo -e "==================================\n" >> "${TMPFILE}" 1006 | exec 3>$(tty) 1007 | exec 3>&- 1008 | 1009 | eval "${SUDO} bash -c '${c}'" >>"${TMPFILE}" 2>&1 & 1010 | sleep 20 1011 | exec 3>&- 1012 | done 1013 | 1014 | show_message info "[!] Killing debug proccess..." 1015 | commands_to_kill=(moneyd codiusd hyperd) 1016 | for p in "${commands_to_kill[@]}" 1017 | do 1018 | ${SUDO} kill -9 $(ps -ef|grep $p |grep -v "grep"|awk '{print $2}') || true 1019 | done 1020 | 1021 | show_message info "[+] Starting services... " 1022 | for i in "${services[@]}" 1023 | do 1024 | if [[ $i = moneyd ]]; then i='moneyd-xrp'; fi 1025 | if [[ "${INIT_SYSTEM}" == "systemd" ]];then 1026 | ${SUDO} systemctl restart $i >>"${TMPFILE}" 2>&1 || true 1027 | else 1028 | ${SUDO} service $i restart >>"${TMPFILE}" 2>&1 || true 1029 | fi 1030 | done 1031 | 1032 | new_line 1033 | printf '%*s\n' "${COLUMNS:-$(tput cols)}" '' | tr ' ' = 1034 | show_message done "[!] The debuging proccess is done." 1035 | new_line 1036 | show_message done "[-] Please check $TMPFILE for full log output ." 1037 | printf '%*s\n' "${COLUMNS:-$(tput cols)}" '' | tr ' ' = 1038 | 1039 | 1040 | exit 1041 | 1042 | } 1043 | 1044 | 1045 | ################### CHECK FOR SCRIPT UPDATES ########################### 1046 | 1047 | check_script_update() { 1048 | LATEST_FILE=$(curl "$INSTALLER_URL" 2>/dev/null) || { printf '%s\n' 'Unable to check for updates.'; curlFailed=1; } 1049 | THIS_MOD=$(grep -m1 '# Last Modified Date: ' $0) 1050 | LASTED_MOD=$(grep -m1 '# Last Modified Date: ' <<<"$LATEST_FILE") 1051 | 1052 | if [[ "$THIS_MOD" != "$LASTED_MOD" ]] && [[ ! -n "$curlFailed" ]]; then 1053 | show_message info "[!] An update is available For the script... " 1054 | read -p "Update Now ? [y/N]: " -e UPDATE 1055 | 1056 | if [[ "$UPDATE" = 'y' || "$UPDATE" = 'Y' ]]; then 1057 | show_message info "[+] Updating now.\n" 1058 | tmpfile=$(mktemp) 1059 | chmod +x "$tmpfile" 1060 | cat <<<"$LATEST_FILE" > "$tmpfile" 1061 | mv "$tmpfile" "$0" 1062 | show_message done "\n[-] Installer successfully updated to the latest version. Please restart the script to continue.\n" 1063 | exit 1064 | fi 1065 | fi 1066 | 1067 | new_line 1068 | 1069 | } 1070 | 1071 | ################### MAIN ########################### 1072 | 1073 | while : 1074 | do 1075 | clear 1076 | display_header 1077 | 1078 | # check for script Update at startup 1079 | check_script_update 1080 | 1081 | echo "What do you want to do?" 1082 | echo " 1) Install and run Codius in your system" 1083 | echo " 2) Check your system for Codius errors" 1084 | echo " 3) Check for certificate status and renew" 1085 | echo " 4) Cleanup the codius from the server" 1086 | echo " 5) Update Codiusd & Moneyd to the lastest version" 1087 | echo " 6) Exit" 1088 | read -p "Select an option [1-6]: " option 1089 | 1090 | case $option in 1091 | 1)install;; 1092 | 2)debug;; 1093 | 3)renew;; 1094 | 4)clean;; 1095 | 5)update;; 1096 | 6)exit;; 1097 | esac 1098 | done 1099 | 1100 | --------------------------------------------------------------------------------