-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathdeploy.sh
More file actions
139 lines (117 loc) · 2.85 KB
/
deploy.sh
File metadata and controls
139 lines (117 loc) · 2.85 KB
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
#!/bin/bash
#deploy.sh -c $VERSION_NUMBER compiling the programm and create symlink
#deploy.sh -s $FILENAME only create symlink
declare -r BASE_IMGNAME="bingo.tar.gz"
declare -r DATE=$(date +%F)
declare -r SYMLINK="/srv/http/play/bingo.tar.gz"
declare -r SCRIPT_NAME="$0"
##### directories
declare -r BASE_DIR="/home/ivr/work/programming/bash-scripting/deploy"
declare -r RUN_DIR="$( cd -P "$( dirname "$SCRIPT_NAME" )" && pwd )"
declare -r BUILD_DIR="${BASE_DIR}/bingo/src/Binary/Bingo" #without end slash
declare -r IMAGE_DIR="${BASE_DIR}/bingo/builds"
function error_mes()
{
if [[ $1 == "" ]] ; then
local MESSAGE="usage: $SCRIPT_NAME -s '${FILENAME}' - to create symlink \n $SCRIPT_NAME - to compile and create symlink"
else
local MESSAGE="bad parameter $1 \nusage: $SCRIPT_NAME -s '${FILENAME}' - to create symlink \n$SCRIPT_NAME - to compile and create symlink"
fi
echo -e "$MESSAGE"
return 0
}
function main()
{
#command line arguments parsing
echo "options: $1 $2 $3"
local OPT_ACTION="$1"
local OPT_SECOND="$2"
case "$OPT_ACTION" in
-s ) create_symlink $OPT_SECOND ;;
-c ) build_image $OPT_SECOND ;;
* ) error_mes ; exit 1 ;;
esac
exit 0
}
function create_symlink()
{
local LINK_TO=$1
############
# check play image exist
if [[ ! -f "$LINK_TO" ]] ; then
echo "file $LINK_TO not found"
error_mes $LINK_TO
exit
fi
rm -f "$SYMLINK"
ln -s "${IMAGE_DIR}/$(basename $LINK_TO)" "$SYMLINK"
if [[ ! -L "$SYMLINK" ]] ; then
echo "cannot create symlink"
exit 1
else
ls -l "$SYMLINK"
echo "create sucesfully"
fi
return 0
}
function build_image()
{
########################
#check directories exist
if ! mkdir -p "$BUILD_DIR" "$IMAGE_DIR" ; then
echo "cannoot create working directories, permission denied"
exit 1
fi
################
# create file prefix
local NULL_PREF="$$"
echo $NULL_PREF
local PREF=""
if [[ "$1" == "" ]] ; then
(( PREF = $NULL_PREF + $(date +%d) + $(date +%H) ))
else
local PREF="$1"
fi
echo $PREF
################
################
# check file exists
local FULL_RESULT_FNAME="${IMAGE_DIR}/${PREF}.${DATE}.${BASE_IMGNAME}"
if [[ -f "$FULL_RESULT_FNAME" ]] ; then
echo "file $FULL_RESULT_FNAME exist"
error_mes $FULL_RESULT_FNAME
exit 1
fi
if compile ; then
echo "compile is ok"
else
echo "compile not sucessfull"
exit 1
fi
cd "$BUILD_DIR"
tar czf "$FULL_RESULT_FNAME" *
rm -r *
cd "$RUN_DIR"
#################
# create symlink
create_symlink "$FULL_RESULT_FNAME"
return 0
}
function compile()
{
# Put here your compile command
# if compile is ok ; then return 0
# if compile is trouble ; then return 1
touch "${BUILD_DIR}/Bingo.exe" "${BUILD_DIR}/test.mdb" #remove, only for tests
mkdir -p "${BUILD_DIR}/Resources"
############
# check compile
if [[ -f "${BUILD_DIR}/Bingo.exe" ]] ; then
return 0
else
return 1
fi
}
#############
# entry point to the program
main $*