github.com/e154/smart-home@v0.17.2-0.20240311175135-e530a6e5cd45/bin/project.sh (about) 1 # 2 # This file is part of the Smart Home 3 # Program complex distribution https://github.com/e154/smart-home 4 # Copyright (C) 2016-2023, Filippov Alex 5 # 6 # This library is free software: you can redistribute it and/or 7 # modify it under the terms of the GNU Lesser General Public 8 # License as published by the Free Software Foundation; either 9 # version 3 of the License, or (at your option) any later version. 10 # 11 # This library is distributed in the hope that it will be useful, 12 # but WITHOUT ANY WARRANTY; without even the implied warranty of 13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 # Library General Public License for more details. 15 # 16 # You should have received a copy of the GNU Lesser General Public 17 # License along with this library. If not, see 18 # <https://www.gnu.org/licenses/>. 19 # 20 21 #!/usr/bin/env bash 22 23 set -o errexit 24 25 # 26 # base variables 27 # 28 FILENAME=$0 29 ROOT="$( cd "$( dirname "${BASH_SOURCE[0]}")" && cd ../ && pwd)" 30 EXEC="server" 31 TMP_DIR="${ROOT}/tmp/${EXEC}" 32 ARCHIVE="smart-home-${EXEC}.tar.gz" 33 34 COMMAND=$* 35 36 OS_TYPE="unknown" 37 OS_ARCH="unknown" 38 39 UNAME=`which uname` 40 41 if [ -z "$UNAME" ]; then 42 message "Required tools are missing - check beginning of \"$0\" file for details." 43 exit 1 44 fi 45 46 47 main() { 48 49 # get os type 50 case $COMMAND in 51 --init) 52 __init 53 ;; 54 --clean) 55 __clean 56 ;; 57 --build) 58 __build 59 ;; 60 (*) 61 __help 62 ;; 63 esac 64 } 65 66 __init() { 67 68 cd ${ROOT} 69 70 go install $(go list ./... | grep -v "/vendor\|/database") 71 go get -u github.com/jteeuwen/go-bindata/... 72 73 cp ${ROOT}/conf/config.dev.json ${ROOT}/conf/config.json 74 cp ${ROOT}/conf/dbconfig.dev.yml ${ROOT}/conf/dbconfig.yml 75 76 __pg_help 77 } 78 79 __clean() { 80 81 rm -rf ${ROOT}/build 82 rm -rf ${ROOT}/tmp 83 rm -rf ${ROOT}/vendor 84 rm -rf ${TMP_DIR} 85 } 86 87 __build() { 88 89 __check_os 90 91 mkdir -p ${TMP_DIR}/conf 92 mkdir -p ${TMP_DIR}/data 93 94 cd ${ROOT} 95 go build -o ${TMP_DIR}/${EXEC}-${OS_TYPE}-${OS_ARCH} 96 97 98 cp ${ROOT}/conf/config.dev.json ${TMP_DIR}/conf 99 cp ${ROOT}/conf/dbconfig.dev.yml ${TMP_DIR}/conf 100 cp ${ROOT}/LICENSE ${TMP_DIR} 101 cp ${ROOT}/README* ${TMP_DIR} 102 cp ${ROOT}/contributors.txt ${TMP_DIR} 103 cp ${ROOT}/bin/server ${TMP_DIR} 104 cp -r ${ROOT}/data/icons ${TMP_DIR}/data 105 cp -r ${ROOT}/data/scripts ${TMP_DIR}/data 106 cp -r ${ROOT}/assets ${TMP_DIR} 107 cp -r ${ROOT}/snapshots ${TMP_DIR} 108 cd ${TMP_DIR} 109 # echo "tar: ${ARCHIVE} copy to ${HOME}" 110 # tar -zcf ${HOME}/${ARCHIVE} . 111 } 112 113 __pg_help() { 114 cat <<EOF 115 116 # 117 # please install postgres database 118 # 119 120 su - postgres 121 122 createuser smart_home; 123 create database smart_home; 124 125 psql ( enter the password for postgressql) 126 127 alter user smart_home with encrypted password 'smart_home'; 128 grant all privileges on database smart_home to smart_home; 129 130 EOF 131 } 132 133 __help() { 134 cat <<EOF 135 Usage: project.sh [options] 136 137 OPTIONS: 138 139 --init - init project environment in develop mode 140 --clean - cleaning of temporary directories 141 --build - build documentation 142 143 -h / --help - show this help text and exit 0 144 145 EOF 146 } 147 148 __check_os() { 149 150 # get os type 151 case `${UNAME} -s` in 152 (Linux) 153 OS_TYPE="linux" 154 ;; 155 (Darwin) 156 OS_TYPE="darwin-10.6" 157 ;; 158 esac 159 160 # get os arch 161 case `${UNAME} -m` in 162 (x86_64) 163 OS_ARCH="amd64" 164 ;; 165 (386) 166 OS_ARCH="386" 167 ;; 168 (armv7l) 169 OS_ARCH="arm-7" 170 ;; 171 (armv64l) 172 OS_ARCH="arm-64" 173 ;; 174 (armv6l) 175 OS_ARCH="arm-6" 176 ;; 177 (armv5l) 178 OS_ARCH="arm-5" 179 ;; 180 (mip64) 181 OS_ARCH="mip64" 182 ;; 183 (mip64le) 184 OS_ARCH="mip64le" 185 ;; 186 esac 187 } 188 189 main