Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in
Toggle navigation
E
emcode-provision
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Registry
Registry
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
public
emcode-provision
Commits
656cf6ba
Verified
Commit
656cf6ba
authored
Apr 05, 2019
by
DevOps
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
New remote
parent
af3d51c9
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
38 additions
and
29 deletions
+38
-29
update
update
+38
-29
No files found.
update
View file @
656cf6ba
#!/usr/bin/env bash
#!/usr/bin/env bash
set
-e
x
set
-e
SCRIPTPATH
=
"
$(
cd
$(
dirname
${
0
})
;
pwd
-P
)
"
SCRIPTPATH
=
"
$(
cd
$(
dirname
${
0
})
;
pwd
-P
)
"
SERVER_ADDR
=
"http
s://app.emcode-provision.app.docker.rew.to
"
SERVER_ADDR
=
"http
://emd.instraroam.net
"
TOKEN
=
"
Rgg5gzEZuzLfF9hR
"
TOKEN
=
"
5b3sCn6uRkBY4f8uQ1UdcJ
"
### path to store state of code
### path to store state of code
STATE_PATH
=
"
${
HOME
}
/emcode-store"
STATE_PATH
=
"
${
HOME
}
/emcode-store"
### absolute path to store code (default: <STATE_PATH>)
### absolute path to store code (default: <STATE_PATH>)
CODE_PATH
=
"
${
STATE_PATH
}
/code.js"
CODE_PATH
=
"
${
STATE_PATH
}
/code.js"
_query_args
=
"token=
${
TOKEN
}
"
init_config
()
{
init_config
()
{
local
write_config
=
false
local
write_config
=
false
...
@@ -23,11 +21,38 @@ init_config() {
...
@@ -23,11 +21,38 @@ init_config() {
write_config
=
true
write_config
=
true
fi
fi
while
getopts
"t:s:p:h?"
opt
;
do
case
$opt
in
t
)
TOKEN
=
${
OPTARG
}
;;
s
)
STATE_PATH
=
${
OPTARG
}
;;
p
)
CODE_PATH
=
${
OPTARG
}
;;
h|
\?
)
usage
exit
1
;;
esac
done
if
[[
${
write_config
}
==
true
]]
;
then
if
[[
${
write_config
}
==
true
]]
;
then
save_config
save_config
fi
fi
}
}
usage
()
{
echo
-n
"
$(
realpath
${
0
})
[OPTIONS]
-t TOKEN Access token (default:
${
TOKEN
}
)
-s PATH Path to store state of code (default:
${
STATE_PATH
}
)
-p PATH Path to store code (default:
${
CODE_PATH
}
)
"
}
save_config
()
{
save_config
()
{
cat
<<
EOF
>
${
SCRIPTPATH
}
/config.txt
cat
<<
EOF
>
${
SCRIPTPATH
}
/config.txt
STATE_PATH=
${
STATE_PATH
}
STATE_PATH=
${
STATE_PATH
}
...
@@ -36,24 +61,8 @@ TOKEN=${TOKEN}
...
@@ -36,24 +61,8 @@ TOKEN=${TOKEN}
EOF
EOF
}
}
make_query_args
()
{
local
version
=
$(
cat
${
STATE_PATH
}
/version.txt 2>/dev/null |
tr
-d
'\n'
)
if
[[
!
-z
${
version
}
]]
;
then
_query_args+
=
"&ver=
${
version
}
"
fi
}
extract_version
()
{
extract_version
()
{
local
begin_comment
=
"<!--"
grep
-oP
"(?<=/
\*
)[0-9a-f_-]+(?=
\*
/)"
<<<
${
1
}
local
end_comment
=
"-->"
if
[[
${
CODE_TYPE
}
==
"script"
]]
;
then
begin_comment
=
"/
\*
"
end_comment
=
"
\*
/"
fi
grep
-oP
"(?<=
${
begin_comment
}
)[0-9a-f_-]+(?=
${
end_comment
}
)"
<<<
${
1
}
}
}
make_home
()
{
make_home
()
{
...
@@ -63,15 +72,15 @@ make_home() {
...
@@ -63,15 +72,15 @@ make_home() {
}
}
main
()
{
main
()
{
make_query_args
local
code
=
$(
curl
-s
-L
"
${
SERVER_ADDR
}
/token/
${
TOKEN
}
"
)
local
remote_ver
=
$(
extract_version
"
${
code
}
"
)
local
code
=
$(
curl
-s
-L
${
SERVER_ADDR
}
?
${
_query_args
})
local
local_ver
=
$(
cat
${
STATE_PATH
}
/version.txt 2>/dev/null |
tr
-d
'\n'
)
local
version
=
$(
extract_version
"
${
code
}
"
)
if
[[
!
-z
${
version
}
]]
;
then
if
[[
!
-z
${
remote_ver
}
]]
&&
[[
${
local_ver
}
!=
${
remote_ver
}
]]
;
then
make_home
make_home
cat
<<<
${
code
}
>
${
CODE_PATH
}
echo
'// HEADER'
>
${
CODE_PATH
}
echo
-n
${
version
}
>
${
STATE_PATH
}
/version.txt
echo
-n
${
code
}
>>
${
CODE_PATH
}
echo
-n
${
remote_ver
}
>
${
STATE_PATH
}
/version.txt
fi
fi
}
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment