github.com/klaytn/klaytn@v1.12.1/build/package-tar.sh (about) 1 #!/bin/bash 2 3 MYDIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )" 4 DAEMON_BINARIES=(kcn kpn ken kbn kscn kspn ksen) 5 BINARIES=(kgen homi) 6 7 set -e 8 9 function printUsage { 10 echo "Usage: ${0} [-b] <arch> <target>" 11 echo " -b: use baobab configuration" 12 echo " <arch>: linux-386 | linux-amd64 | darwin-amd64 | windows-386 | windows-amd64" 13 echo " <target>: kcn | kpn | ken | kbn | kscn | kspn | ksen | kgen | homi" 14 echo "" 15 echo " ${0} linux-amd64 kcn" 16 exit 1 17 } 18 19 # Parse options. 20 BAOBAB= 21 while getopts "b" opt; do 22 case ${opt} in 23 b) 24 echo "Using baobab configuration..." 25 BAOBAB="-baobab" 26 ;; 27 esac 28 done 29 shift $((OPTIND -1)) 30 31 # Parse subcommand. 32 SUBCOMMAND=$1 33 case "$SUBCOMMAND" in 34 linux-386) 35 PLATFORM_SUFFIX="linux-386" 36 shift 37 ;; 38 linux-amd64) 39 PLATFORM_SUFFIX="linux-amd64" 40 shift 41 ;; 42 darwin-amd64) 43 PLATFORM_SUFFIX="darwin-10.10-amd64" 44 shift 45 ;; 46 windows-386) 47 PLATFORM_SUFFIX="windows-386" 48 shift 49 ;; 50 windows-amd64) 51 PLATFORM_SUFFIX="windows-amd64" 52 shift 53 ;; 54 *) 55 echo "Undefined architecture for packaging. Supported architectures: linux-386, linux-amd64, darwin-amd64, windows-386, windows-amd64" 56 printUsage 57 ;; 58 esac 59 60 # Parse target 61 TARGET=$1 62 if [ -z "$TARGET" ]; then 63 echo "specify target binary: ${DAEMON_BINARIES[*]} ${DAEMON[*]}" 64 printUsage 65 fi 66 67 pushd $MYDIR/.. 68 69 # Install trap to return PWD. 70 function finish { 71 # Your cleanup code here 72 popd 73 } 74 trap finish EXIT 75 76 KLAYTN_VERSION=$(go run build/rpm/main.go version) 77 KLAYTN_RELEASE_NUM=$(go run build/rpm/main.go release_num) 78 PACKAGE_SUFFIX="${KLAYTN_VERSION}-${KLAYTN_RELEASE_NUM}-${PLATFORM_SUFFIX}.tar.gz" 79 80 PACK_NAME= 81 KLAYTN_PACKAGE_NAME= 82 DAEMON= 83 84 # Search the target from DAEMON_BINARIES. 85 for b in ${DAEMON_BINARIES[*]}; do 86 if [ "$TARGET" == "$b" ]; then 87 PACK_NAME=${b}-${PLATFORM_SUFFIX} 88 KLAYTN_PACKAGE_NAME="${b}${BAOBAB}-${PACKAGE_SUFFIX}" 89 DAEMON=1 90 fi 91 done 92 93 # Search the target from BINARIES 94 for b in ${BINARIES[*]}; do 95 if [ "$TARGET" == "$b" ]; then 96 PACK_NAME=${b}-${PLATFORM_SUFFIX} 97 KLAYTN_PACKAGE_NAME="${b}${BAOBAB}-${PACKAGE_SUFFIX}" 98 fi 99 done 100 101 if [ -z "$PACK_NAME" ]; then 102 echo "Undefined binary name: $TARGET. Defined binaries: ${DAEMON_BINARIES[*]} ${DAEMON[*]}" 103 104 printUsage 105 fi 106 107 # Copy the target binary 108 mkdir -p ${PACK_NAME}/bin 109 cp build/bin/${TARGET} ${PACK_NAME}/bin/${TARGET} 110 111 # Copy the configuration file and the daemon file. 112 if [ ! -z "$DAEMON" ]; then 113 mkdir -p ${PACK_NAME}/conf 114 CONF_FILE=build/packaging/linux/conf/${TARGET}d.conf 115 if [ ! -z "$BAOBAB" ]; then 116 BAOBAB_CONF_FILE=build/packaging/linux/conf/${TARGET}d_baobab.conf 117 if [ -e "$BAOBAB_CONF_FILE" ]; then 118 CONF_FILE=$BAOBAB_CONF_FILE 119 else 120 echo "Since $BAOBAB_CONF_FILE does not exist, using $CONF_FILE." 121 fi 122 fi 123 cp build/packaging/linux/bin/${TARGET}d ${PACK_NAME}/bin/ 124 cp $CONF_FILE ${PACK_NAME}/conf/ 125 fi 126 127 # Compress! 128 mkdir -p packages 129 tar czf packages/$KLAYTN_PACKAGE_NAME $PACK_NAME