-
Notifications
You must be signed in to change notification settings - Fork 0
/
pod
executable file
·180 lines (133 loc) · 3.24 KB
/
pod
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
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
#!/bin/sh
# pod
# Generated using mkx 2.3.0: https://github.com/remino/mkx
VERSION='1.1.1'
pod_main() {
trap _exit INT TERM
E_ARGS=16
E_MISSING_BIN=17
E_MISSING_DIR=18
E_DIR_EXISTS=19
SCRIPT_INV="$( basename "$0" )"
SCRIPT_PATH="$( readlink -f "$0" )"
SCRIPT_NAME="$( basename "$SCRIPT_PATH" )"
SCRIPT_DIR="$( cd "$( dirname "$SCRIPT_PATH" )" && pwd )"
while getopts hv OPT
do
case $OPT in
h) CMD=help ;;
v) CMD=version ;;
*) _invalid_opt ;;
esac
done
shift "$(( OPTIND - 1 ))"
[ -z "$CMD" ] && CMD="$1"
[ $# -gt 0 ] && shift
[ -z "$CMD" ] && CMD="help"
case "$CMD" in
help|new|process|version) "pod_$CMD" "$@" ;;
*) _mansite "$CMD" "$@" ;;
esac
_exit
}
pod_help() {
cat <<USAGE
$SCRIPT_NAME $VERSION
USAGE:
$SCRIPT_INV [<options>] <help|version>
$SCRIPT_INV [<options>] <new> <dest_dir> <pod_domain> <share_username> [<pod_title>]
Create a new pod part of a podsite.
COMMANDS:
help Show this help screen.
new Create new pod.
version Show script name and version number.
Any other command will be passed to mansite instead.
OPTIONS:
-h Show this help screen.
-v Show script name and version number.
USAGE
}
pod_new() {
[ $# -lt 3 ] && _fatal "$E_ARGS" "Missing required arguments."
_check_sere_version
_require bundle
_require git
_require git-dup
_require rename
_require pnpm
_require sed
src_dir="$SCRIPT_DIR"
dest_dir="$1"
pod_domain="$2"
share_username="$3"
pod_title="$4"
pod_name="$( basename "$dest_dir" )"
[ -z "$pod_title" ] && pod_title="$pod_name"
[ -d "$dest_dir" ] && _fatal "$E_DIR_EXISTS" "Destination directory already exists: $dest_dir"
git-dup "$src_dir" "$dest_dir"
[ ! -d "$dest_dir" ] && _fatal "$E_MISSING_DIR" "Destination directory not found: $dest_dir"
cd "$dest_dir" || _fatal "$E_MISSING_DIR" "Failed to change directory: $dest_dir"
git remote remove origin
sere "\bexample\.com\b" "$pod_domain"
sere "\bpod\b" "$pod_name"
sere "\bPod\b" "$pod_title"
sere "\busername\b" "$share_username"
cp .env.example .env
sere "\bexample\.com\b" "$pod_domain" .env
sere "\bpod\b" "$pod_name" .env
sere "\bPod\b" "$pod_title" .env
sere "\busername\b" "$share_username" .env
find . -name "pod" -type d -mindepth 2 -exec rename "s/pod/$pod_name/" {} \;
pnpm install
bundle
git checkout pod
git add .
git commit -m "Set pod domain & name to $pod_domain & $pod_name"
}
pod_version() {
_echo "$SCRIPT_NAME $VERSION"
}
_check_sere_version() {
_require sere
sere_version="$( sere -v )"
sere_req_version="2.1.0"
[ "$sere_version" = "$sere_req_version" ] && return 0
[ "$( printf '%s\n' "$sere_version" "$sere_req_version" | sort -V | head -n1 )" = "$sere_req_version" ] && return 0
_fatal "$E_MISSING_BIN" "sere version 2.x or higher required."
}
_echo() {
echo "$@"
}
_error() {
_echo "$@" >&2
}
_exit() {
exit_code=$?
exit "$exit_code"
}
_fatal() {
exit_code="$1"
shift
_error "$@"
exit "$exit_code"
}
_invalid_cmd() {
_error "Invalid command: $CMD"
_echo
pod_help
exit "$E_ARGS"
}
_invalid_opt() {
_error "Invalid option: $OPT"
_echo
pod_help
exit "$E_ARGS"
}
_mansite() {
"$SCRIPT_DIR/mansite" "$@"
}
_require() {
command -v "$1" >/dev/null 2>&1 && return 0
_fatal "$E_MISSING_BIN" "Required command not found: $1"
}
pod_main "$@"