Skip to content

Commit 6e6bef4

Browse files
committed
Format shell script
Signed-off-by: Riddhesh Sanghvi <riddhesh237@gmail.com>
1 parent 1d264af commit 6e6bef4

File tree

2 files changed

+44
-45
lines changed

2 files changed

+44
-45
lines changed

entrypoint.sh

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -3,28 +3,28 @@
33
# Check required env variables
44
flag=0
55
if [[ -z "$SSH_PRIVATE_KEY" ]]; then
6-
flag=1
7-
missing_secret="SSH_PRIVATE_KEY"
8-
if [[ -n "$VAULT_ADDR" ]] && [[ -n "$VAULT_TOKEN" ]]; then
9-
flag=0
10-
fi
11-
if [[ -n "$VAULT_ADDR" ]] || [[ -n "$VAULT_TOKEN" ]]; then
12-
missing_secret="VAULT_ADDR and/or VAULT_TOKEN"
13-
fi
6+
flag=1
7+
missing_secret="SSH_PRIVATE_KEY"
8+
if [[ -n "$VAULT_ADDR" ]] && [[ -n "$VAULT_TOKEN" ]]; then
9+
flag=0
10+
fi
11+
if [[ -n "$VAULT_ADDR" ]] || [[ -n "$VAULT_TOKEN" ]]; then
12+
missing_secret="VAULT_ADDR and/or VAULT_TOKEN"
13+
fi
1414
fi
1515

1616
if [[ "$flag" -eq 1 ]]; then
17-
printf "[\e[0;31mERROR\e[0m] Secret \`$missing_secret\` is missing. Please add it to this action for proper execution.\nRefer https://github.com/rtCamp/action-deploy-wordpress for more information.\n"
18-
exit 1
17+
printf "[\e[0;31mERROR\e[0m] Secret \`$missing_secret\` is missing. Please add it to this action for proper execution.\nRefer https://github.com/rtCamp/action-deploy-wordpress for more information.\n"
18+
exit 1
1919
fi
2020

2121
# custom path for files to override default files
2222
custom_path="$GITHUB_WORKSPACE/.github/deploy"
2323
main_script="/main.sh"
2424

2525
if [[ -d "$custom_path" ]]; then
26-
rsync -av "$custom_path/" /
27-
chmod +x /*.sh
26+
rsync -av "$custom_path/" /
27+
chmod +x /*.sh
2828
fi
2929

3030
bash "$main_script"

main.sh

Lines changed: 32 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ export HTDOCS="$HOME/htdocs"
77
export GITHUB_BRANCH=${GITHUB_REF##*heads/}
88
export CI_SCRIPT_OPTIONS="ci_script_options"
99

10-
1110
function init_checks() {
1211

1312
# Check if branch is available
@@ -18,7 +17,7 @@ function init_checks() {
1817

1918
# Check for SSH key if jump host is defined
2019
if [[ ! -z "$JUMPHOST_SERVER" ]]; then
21-
20+
2221
if [[ -z "$SSH_PRIVATE_KEY" ]]; then
2322
echo "Jump host configuration does not work with vault ssh signing."
2423
echo "SSH_PRIVATE_KEY secret needs to be added."
@@ -45,9 +44,9 @@ function check_branch_in_hosts_file() {
4544

4645
match=0
4746
for branch in $(cat "$hosts_file" | shyaml keys); do
48-
[[ "$GITHUB_REF" = "refs/heads/$branch" ]] && \
49-
echo "$GITHUB_REF matches refs/heads/$branch" && \
50-
match=1
47+
[[ "$GITHUB_REF" = "refs/heads/$branch" ]] &&
48+
echo "$GITHUB_REF matches refs/heads/$branch" &&
49+
match=1
5150
done
5251

5352
# Exit neutral if no match found
@@ -60,14 +59,14 @@ function check_branch_in_hosts_file() {
6059
function setup_private_key() {
6160

6261
if [[ -n "$SSH_PRIVATE_KEY" ]]; then
63-
echo "$SSH_PRIVATE_KEY" | tr -d '\r' > "$SSH_DIR/id_rsa"
64-
chmod 600 "$SSH_DIR/id_rsa"
65-
eval "$(ssh-agent -s)"
66-
ssh-add "$SSH_DIR/id_rsa"
62+
echo "$SSH_PRIVATE_KEY" | tr -d '\r' >"$SSH_DIR/id_rsa"
63+
chmod 600 "$SSH_DIR/id_rsa"
64+
eval "$(ssh-agent -s)"
65+
ssh-add "$SSH_DIR/id_rsa"
6766

68-
if [[ -n "$JUMPHOST_SERVER" ]]; then
69-
ssh-keyscan -H "$JUMPHOST_SERVER" >> /etc/ssh/known_hosts
70-
fi
67+
if [[ -n "$JUMPHOST_SERVER" ]]; then
68+
ssh-keyscan -H "$JUMPHOST_SERVER" >>/etc/ssh/known_hosts
69+
fi
7170
else
7271
# Generate a key-pair
7372
ssh-keygen -t rsa -b 4096 -C "GH-actions-ssh-deploy-key" -f "$HOME/.ssh/id_rsa" -N ""
@@ -79,28 +78,28 @@ function maybe_get_ssh_cert_from_vault() {
7978
# Get signed key from vault
8079
if [[ -n "$VAULT_GITHUB_TOKEN" ]]; then
8180
unset VAULT_TOKEN
82-
vault login -method=github token="$VAULT_GITHUB_TOKEN" > /dev/null
81+
vault login -method=github token="$VAULT_GITHUB_TOKEN" >/dev/null
8382
fi
8483

8584
if [[ -n "$VAULT_ADDR" ]]; then
86-
vault write -field=signed_key ssh-client-signer/sign/my-role public_key=@$HOME/.ssh/id_rsa.pub > $HOME/.ssh/signed-cert.pub
85+
vault write -field=signed_key ssh-client-signer/sign/my-role public_key=@$HOME/.ssh/id_rsa.pub >$HOME/.ssh/signed-cert.pub
8786
fi
8887
}
8988

9089
function configure_ssh_config() {
9190

92-
if [[ -z "$JUMPHOST_SERVER" ]]; then
93-
# Create ssh config file. `~/.ssh/config` does not work.
94-
cat > /etc/ssh/ssh_config <<EOL
91+
if [[ -z "$JUMPHOST_SERVER" ]]; then
92+
# Create ssh config file. `~/.ssh/config` does not work.
93+
cat >/etc/ssh/ssh_config <<EOL
9594
Host $hostname
9695
HostName $hostname
9796
IdentityFile ${SSH_DIR}/signed-cert.pub
9897
IdentityFile ${SSH_DIR}/id_rsa
9998
User $ssh_user
10099
EOL
101-
else
102-
# Create ssh config file. `~/.ssh/config` does not work.
103-
cat > /etc/ssh/ssh_config <<EOL
100+
else
101+
# Create ssh config file. `~/.ssh/config` does not work.
102+
cat >/etc/ssh/ssh_config <<EOL
104103
Host jumphost
105104
HostName $JUMPHOST_SERVER
106105
UserKnownHostsFile /etc/ssh/known_hosts
@@ -112,7 +111,7 @@ Host $hostname
112111
UserKnownHostsFile /etc/ssh/known_hosts
113112
User $ssh_user
114113
EOL
115-
fi
114+
fi
116115

117116
}
118117

@@ -138,26 +137,26 @@ function maybe_install_submodules() {
138137
# Check and update submodules if any
139138
if [[ -f "$GITHUB_WORKSPACE/.gitmodules" ]]; then
140139
# add github's public key
141-
echo "|1|qPmmP7LVZ7Qbpk7AylmkfR0FApQ=|WUy1WS3F4qcr3R5Sc728778goPw= ssh-rsa AAAAB3NzaC1yc2EAAAABIwAAAQEAq2A7hRGmdnm9tUDbO9IDSwBK6TbQa+PXYPCPy6rbTrTtw7PHkccKrpp0yVhp5HdEIcKr6pLlVDBfOLX9QUsyCOV0wzfjIJNlGEYsdlLJizHhbn2mUjvSAHQqZETYP81eFzLQNnPHt4EVVUh7VfDESU84KezmD5QlWpXLmvU31/yMf+Se8xhHTvKSCZIFImWwoG6mbUoWf9nzpIoaSjB+weqqUUmpaaasXVal72J+UX2B+2RPW3RcT0eOzQgqlJL3RKrTJvdsjE3JEAvGq3lGHSZXy28G3skua2SmVi/w4yCE6gbODqnTWlg7+wC604ydGXA8VJiS5ap43JXiUFFAaQ==" >> /etc/ssh/known_hosts
140+
echo "|1|qPmmP7LVZ7Qbpk7AylmkfR0FApQ=|WUy1WS3F4qcr3R5Sc728778goPw= ssh-rsa AAAAB3NzaC1yc2EAAAABIwAAAQEAq2A7hRGmdnm9tUDbO9IDSwBK6TbQa+PXYPCPy6rbTrTtw7PHkccKrpp0yVhp5HdEIcKr6pLlVDBfOLX9QUsyCOV0wzfjIJNlGEYsdlLJizHhbn2mUjvSAHQqZETYP81eFzLQNnPHt4EVVUh7VfDESU84KezmD5QlWpXLmvU31/yMf+Se8xhHTvKSCZIFImWwoG6mbUoWf9nzpIoaSjB+weqqUUmpaaasXVal72J+UX2B+2RPW3RcT0eOzQgqlJL3RKrTJvdsjE3JEAvGq3lGHSZXy28G3skua2SmVi/w4yCE6gbODqnTWlg7+wC604ydGXA8VJiS5ap43JXiUFFAaQ==" >>/etc/ssh/known_hosts
142141

143142
identity_file=''
144143
if [[ -n "$SUBMODULE_DEPLOY_KEY" ]]; then
145-
echo "$SUBMODULE_DEPLOY_KEY" | tr -d '\r' > "$SSH_DIR/submodule_deploy_key"
144+
echo "$SUBMODULE_DEPLOY_KEY" | tr -d '\r' >"$SSH_DIR/submodule_deploy_key"
146145
chmod 600 "$SSH_DIR/submodule_deploy_key"
147146
ssh-add "$SSH_DIR/submodule_deploy_key"
148147
identity_file="IdentityFile ${SSH_DIR}/submodule_deploy_key"
149148
fi
150149

151-
# Setup config file for proper git cloning
152-
cat >> /etc/ssh/ssh_config <<EOL
150+
# Setup config file for proper git cloning
151+
cat >>/etc/ssh/ssh_config <<EOL
153152
Host github.com
154153
HostName github.com
155154
User git
156155
UserKnownHostsFile /etc/ssh/known_hosts
157156
${identity_file}
158157
EOL
159-
git submodule update --init --recursive
160-
fi
158+
git submodule update --init --recursive
159+
fi
161160
}
162161

163162
function setup_wordpress_files() {
@@ -166,7 +165,7 @@ function setup_wordpress_files() {
166165
cd "$HTDOCS"
167166
export build_root="$(pwd)"
168167

169-
hosts_wp_version=$(cat "$hosts_file" | shyaml get-value "$GITHUB_BRANCH.WP_VERSION" 2> /dev/null)
168+
hosts_wp_version=$(cat "$hosts_file" | shyaml get-value "$GITHUB_BRANCH.WP_VERSION" 2>/dev/null)
170169

171170
# Check if WP_VERSION is already defined in hosts.yml
172171
# Priority: 1. hosts.yml, 2. workflow file, else use latest
@@ -177,9 +176,9 @@ function setup_wordpress_files() {
177176
fi
178177

179178
if [[ "$WP_MINOR_UPDATE" == "true" ]] && [[ "$WP_VERSION" != "latest" ]]; then
180-
LATEST_MINOR_VERSION=$(\
181-
curl -s "https://api.wordpress.org/core/version-check/1.7/?version=$WP_VERSION" | \
182-
jq -r '[.offers[]|select(.response=="autoupdate")][-1].version'
179+
LATEST_MINOR_VERSION=$(
180+
curl -s "https://api.wordpress.org/core/version-check/1.7/?version=$WP_VERSION" |
181+
jq -r '[.offers[]|select(.response=="autoupdate")][-1].version'
183182
)
184183
MAJOR_DOT_MINOR=$(echo "$WP_VERSION" | cut -c1-3)
185184
if [[ "$LATEST_MINOR_VERSION" == "$MAJOR_DOT_MINOR"* ]]; then
@@ -196,11 +195,11 @@ function setup_wordpress_files() {
196195

197196
# Include webroot-files in htdocs if they exists
198197
if [[ -d "$GITHUB_WORKSPACE/webroot-files" ]]; then
199-
rsync -av "$GITHUB_WORKSPACE/webroot-files/" "$HTDOCS/" > /dev/null
198+
rsync -av "$GITHUB_WORKSPACE/webroot-files/" "$HTDOCS/" >/dev/null
200199
rm -rf "$GITHUB_WORKSPACE/webroot-files/"
201200
fi
202201

203-
rsync -av "$GITHUB_WORKSPACE/" "$HTDOCS/wp-content/" > /dev/null
202+
rsync -av "$GITHUB_WORKSPACE/" "$HTDOCS/wp-content/" >/dev/null
204203

205204
# Remove uploads directory
206205
cd "$HTDOCS/wp-content/"

0 commit comments

Comments
 (0)