Skip to content

Commit f05e164

Browse files
committed
Rewrite deploy.bash.
1 parent ee88c7e commit f05e164

10 files changed

Lines changed: 153 additions & 186 deletions

File tree

README.md

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,26 @@ In the above command, **demo** is cmd-file. **helloworld** is cmd-function.
104104
105105
More examples, see the files in th [cmd](https://github.com/liudng/dev/tree/master/cmd) directory.
106106

107+
## The Library Scripts
108+
109+
Import a library script to current command file, Add following line to file start:
110+
111+
```sh
112+
dev_import dev file
113+
```
114+
115+
It will load the script file from dev project's lib/file.bash.
116+
117+
## Global Variables Reference
118+
119+
* `$dev_global_project` The project name.
120+
* `$dev_global_base` The project base directory.
121+
122+
## Global Functions Reference
123+
124+
* `dev_import` Import a library file to current file.
125+
* `dev_run`
126+
107127
## Multi-project
108128

109129
Using [dev](https://github.com/liudng/dev) to manage multiple projects is very easy.
@@ -114,6 +134,6 @@ More project examples, see the [sys](https://github.com/liudng/sys) project.
114134

115135
## Copyright
116136

117-
Copyright 2017 The [dev](https://github.com/liudng/dev) Authors. All rights reserved.
137+
Copyright 2018 The [dev](https://github.com/liudng/dev) Authors. All rights reserved.
118138

119139
Use of this source code is governed by a BSD-style license that can be found in the LICENSE file.

bin/dev-bootstrap.bash

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ dev_kernel_optional_arguments() {
4444
}
4545

4646
# The dev package version
47-
declare -gr dev_global_version="2.0.1"
47+
declare -gr dev_global_version="2.1.0"
4848

4949
# The dev execution file path
5050
declare -gr dev_global_self="$(realpath $0)"

cmd/deploy.bash

Lines changed: 112 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,112 @@
1+
# Copyright 2017 The dev Authors. All rights reserved.
2+
# Use of this source code is governed by a BSD-style
3+
# license that can be found in the LICENSE file.
4+
5+
dev_import dev io
6+
dev_import dev network
7+
8+
cmd_init() {
9+
[ -z "$1" ] && echo "Usage: dev deploy init <prj>" >&2 && return 1
10+
11+
declare prj="$1" wkdir="${dev_conf_projects[$1]}"
12+
13+
if [[ -z "${dev_conf_projects[$1]}" ]]; then
14+
dev_error "Project not found, add the following line to $dev_global_base/etc/dev.conf:" >&2
15+
dev_error " [$prj]=/home/ld/$prj" >&2
16+
return 1
17+
fi
18+
19+
mkdir -p $HOME/bin $HOME/.local/{bin,lib,lib64,share}
20+
mkdir -p $wkdir/{bin,cmd,etc,lib,src,usr} $wkdir/var/downloads
21+
mkdir -m a+w -p $wkdir/var/{log,tmp}
22+
23+
if [ ! -f $HOME/.bash_completion ]; then
24+
touch $HOME/.bash_completion
25+
fi
26+
27+
if [ -f $dev_global_base/share/completion.bash ]; then
28+
grep -q "_dev_init_completion" $HOME/.bash_completion || \
29+
cat $dev_global_base/share/completion.bash >> $HOME/.bash_completion
30+
fi
31+
32+
grep -q "complete -F _dev_init_completion $prj" $HOME/.bash_completion || \
33+
echo "complete -F _dev_init_completion $prj" >> $HOME/.bash_completion
34+
35+
if [ ! -f $wkdir/bin/$prj.bash ]; then
36+
echo "dev-bootstrap $prj \$@" > $wkdir/bin/$prj.bash
37+
chmod a+x $wkdir/bin/$prj.bash
38+
fi
39+
40+
if [ ! -L $wkdir/bin/$prj ]; then
41+
cd $wkdir/bin
42+
ln -s $prj.bash $prj
43+
fi
44+
45+
[ -L $HOME/bin/dev ] || ln -s $dev_global_base/bin/dev.bash $HOME/bin/dev
46+
[ -L $HOME/bin/dev-bootstrap ] || ln -s $dev_global_base/bin/dev-bootstrap.bash $HOME/bin/dev-bootstrap
47+
48+
[ -L $HOME/bin/$prj ] || ln -s $wkdir/bin/$prj.bash $HOME/bin/$prj
49+
50+
if [ ! -f $wkdir/.gitignore ]; then
51+
echo "/src" > $wkdir/.gitignore
52+
echo "/usr" >> $wkdir/.gitignore
53+
echo "/var" >> $wkdir/.gitignore
54+
fi
55+
56+
cd $wkdir/usr
57+
58+
[ -L $wkdir/usr/etc ] || ln -s ../etc etc
59+
[ -L $wkdir/usr/src ] || ln -s ../src src
60+
[ -L $wkdir/usr/var ] || ln -s ../var var
61+
62+
dev_verbose "done"
63+
}
64+
65+
#
66+
# Usage:
67+
# dev deploy rsync <prj> <user_and_host>
68+
#
69+
cmd_rsync() {
70+
if [[ $# -lt 2 ]]; then
71+
dev_info "Usage: dev deploy rsync <prj> <user_and_host>" >&2
72+
return 1;
73+
fi
74+
75+
declare prj="$1" wkdir="${dev_conf_projects[$1]}" user_and_host="$2"
76+
77+
if [[ -z "${dev_conf_projects[$1]}" ]]; then
78+
dev_error "Project not found, add the following line to $dev_global_base/etc/dev.conf:" >&2
79+
dev_error " [$prj]=/home/ld/$prj" >&2
80+
return 1
81+
fi
82+
83+
# -e to specify ssh instead of the default.
84+
# rsync -aprzv -e ssh --include '*/' --include='*.class' --exclude='*' . server:/path
85+
86+
# -a, --archive archive mode; equals -rlptgoD (no -H,-A,-X)
87+
# -C, --cvs-exclude auto-ignore files in the same way CVS does
88+
# -d, --dirs transfer directories without recursing
89+
# -l, --links copy symlinks as symlink
90+
# -p, --perms preserve permissions
91+
# -r, --recursive recurse into directories
92+
# -z, --compress compress file data during the transfer
93+
# --delete
94+
rsync -alprz \
95+
--delete \
96+
--cvs-exclude \
97+
--exclude-from=$dev_global_base/etc/rsync.excludes \
98+
$wkdir $user_and_host:\$HOME
99+
}
100+
101+
cmd_sudoer() {
102+
[ $# -lt 2 ] && dev_error "Usage: dev deploy sudoer <sudoer> <user_and_host>" >&2 && return 1
103+
104+
declare sudoer="$1" user_and_host="$2"
105+
106+
dev_scp $glb_wkdir/share/sudoer.bash $user@$host:\$HOME
107+
108+
cmd="chmod a+x \$HOME/sudoer.bash; \$HOME/sudoer.bash $sudoer; rm \$HOME/sudoer.bash"
109+
dev_ssh $user@$host "$cmd"
110+
111+
dev_verbose "done"
112+
}

cmd/deploy/deploy.bash

Lines changed: 0 additions & 49 deletions
This file was deleted.

cmd/deploy/init.bash

Lines changed: 0 additions & 47 deletions
This file was deleted.

cmd/deploy/rsync.bash

Lines changed: 0 additions & 29 deletions
This file was deleted.

cmd/deploy/sudoer.bash

Lines changed: 0 additions & 51 deletions
This file was deleted.

cmd/examples/example.bash

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,14 @@ cmd_sleep() {
1717
}
1818

1919
cmd_basename() {
20-
dev_basename "abc-1.2.0.tar.gz"
21-
dev_basename "abc-1.2.0.tar.bz2"
22-
dev_basename "abc-1.2.0.tgz"
20+
echo "file-1.2.0.tar.gz"
21+
dev_file_basename "file-1.2.0.tar.gz"
22+
echo "file-1.2.0.tar.bz2"
23+
dev_file_basename "file-1.2.0.tar.bz2"
24+
echo "file-1.2.0.tgz"
25+
dev_file_basename "file-1.2.0.tgz"
26+
}
27+
28+
cmd_interactive() {
29+
[[ $- == *i* ]] && echo 'Interactive' || echo 'Not interactive'
2330
}

etc/rsync.excludes

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
1-
.git
21
etc/dev.conf
3-
src/*
2+
src/
43
tags
5-
usr/*
6-
var/*
4+
usr/
5+
var/

share/sudoer.bash

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,13 @@
1-
#!/bin/bash
21
# Copyright 2017 The dev Authors. All rights reserved.
32
# Use of this source code is governed by a BSD-style
43
# license that can be found in the LICENSE file.
54

5+
# trace ERR through pipes
6+
set -o pipefail
7+
8+
# set -e : exit the script if any statement returns a non-true return value
9+
set -o errexit
10+
611
[ $# -lt 1 ] && echo "Usage: dev sudoer <sudoer>" >&2 && return 1
712

813
declare sudoer="$1" home="/home/$1"

0 commit comments

Comments
 (0)