Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit c32453f

Browse files
author
Adam Parkin
committed
Add shellcheck checks
1 parent e093c9f commit c32453f

File tree

3 files changed

+35
-26
lines changed

3 files changed

+35
-26
lines changed

Dockerfile

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,19 @@
1-
FROM alpine:latest
1+
FROM koalaman/shellcheck-alpine
22

33
WORKDIR /build
44

55
RUN apk add --no-cache --update \
66
python3 nodejs
77

88
RUN python3 -m ensurepip
9+
RUN pip3 install --upgrade pip
910

1011
RUN npm install -g markdownlint-cli
1112

1213
COPY requirements.txt /build/requirements.txt
1314
RUN pip3 install -r requirements.txt
1415

16+
COPY *.sh /build/shell/
1517
COPY .markdownlint.json /build/content/
1618
COPY *.py /build/python/
1719
COPY content/ /build/content/

Makefile

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,8 @@ help:
3939
@echo ' make s3_upload upload the web site via S3 '
4040
@echo ' make markdownlint run markdownlint on content '
4141
@echo ' make pylint run pylint on content '
42+
@echo ' make shellcheck run shellcheck on all the scripts '
43+
@echo ' make lint_the_things run all linters & checks '
4244
@echo ' make dockerbuild build docker image '
4345
@echo ' make dockerrun run a shell in built Docker image '
4446
@echo ' '
@@ -87,15 +89,20 @@ publish:
8789
$(PELICAN) $(INPUTDIR) -o $(OUTPUTDIR) -s $(PUBLISHCONF) $(PELICANOPTS)
8890
if test -d $(BASEDIR)/extra; then cp $(BASEDIR)/extra/* $(OUTPUTDIR)/; fi
8991

90-
s3_upload: publish markdownlint pylint
92+
s3_upload: publish lint_the_things
9193
aws s3 sync $(OUTPUTDIR) s3://$(S3_BUCKET) --delete $(S3OPTS)
9294

95+
lint_the_things: markdownlint pylint shellcheck
96+
9397
markdownlint: dockerbuild
9498
docker run --rm -it -w /build/content $(DOCKER_IMAGE_NAME):latest markdownlint .
9599

96100
pylint: dockerbuild
97101
docker run --rm -it -w /build/python $(DOCKER_IMAGE_NAME):latest pylint *.py
98102

103+
shellcheck: dockerbuild
104+
docker run --rm -it -w /build/shell $(DOCKER_IMAGE_NAME):latest shellcheck *.sh
105+
99106
dockerbuild:
100107
docker build -t $(DOCKER_IMAGE_NAME):latest .
101108

develop_server.sh

Lines changed: 24 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -28,55 +28,55 @@ function usage(){
2828
}
2929

3030
function alive() {
31-
kill -0 $1 >/dev/null 2>&1
31+
kill -0 "$1" >/dev/null 2>&1
3232
}
3333

3434
function shut_down(){
35-
PID=$(cat $SRV_PID)
36-
if [[ $? -eq 0 ]]; then
37-
if alive $PID; then
35+
PID=$(cat "$SRV_PID")
36+
if [ -z "$PID" ]; then
37+
echo "HTTP server PIDFile not found"
38+
else
39+
if alive "$PID"; then
3840
echo "Stopping HTTP server"
39-
kill $PID
41+
kill "$PID"
4042
else
4143
echo "Stale PID, deleting"
4244
fi
43-
rm $SRV_PID
44-
else
45-
echo "HTTP server PIDFile not found"
45+
rm "$SRV_PID"
4646
fi
4747

48-
PID=$(cat $PELICAN_PID)
49-
if [[ $? -eq 0 ]]; then
50-
if alive $PID; then
48+
PID=$(cat "$PELICAN_PID")
49+
if [ -z "$PID" ]; then
50+
echo "Pelican PIDFile not found"
51+
else
52+
if alive "$PID"; then
5153
echo "Killing Pelican"
52-
kill $PID
54+
kill "$PID"
5355
else
5456
echo "Stale PID, deleting"
5557
fi
56-
rm $PELICAN_PID
57-
else
58-
echo "Pelican PIDFile not found"
58+
rm "$PELICAN_PID"
5959
fi
6060
}
6161

6262
function start_up(){
6363
local port=$1
6464
echo "Starting up Pelican and HTTP server"
6565
shift
66-
$PELICAN --debug --autoreload -r $INPUTDIR -o $OUTPUTDIR -s $CONFFILE $PELICANOPTS &
66+
$PELICAN --debug --autoreload -r "$INPUTDIR" -o "$OUTPUTDIR" -s "$CONFFILE" "$PELICANOPTS" &
6767
pelican_pid=$!
68-
echo $pelican_pid > $PELICAN_PID
69-
mkdir -p $OUTPUTDIR && cd $OUTPUTDIR
70-
$PY -m pelican.server $port &
68+
echo $pelican_pid > "$PELICAN_PID"
69+
mkdir -p "$OUTPUTDIR" && "cd $OUTPUTDIR" || exit
70+
$PY -m pelican.server "$port" &
7171
srv_pid=$!
72-
echo $srv_pid > $SRV_PID
73-
cd $BASEDIR
72+
echo $srv_pid > "$SRV_PID"
73+
cd "$BASEDIR" || exit
7474
sleep 1
7575
if ! alive $pelican_pid ; then
7676
echo "Pelican didn't start. Is the Pelican package installed?"
7777
return 1
7878
elif ! alive $srv_pid ; then
79-
echo "The HTTP server didn't start. Is there another service using port" $port "?"
79+
echo "The HTTP server didn't start. Is there another service using port $port ?"
8080
return 1
8181
fi
8282
echo 'Pelican and HTTP server processes now running in background.'
@@ -94,9 +94,9 @@ if [[ $1 == "stop" ]]; then
9494
shut_down
9595
elif [[ $1 == "restart" ]]; then
9696
shut_down
97-
start_up $port
97+
start_up "$port"
9898
elif [[ $1 == "start" ]]; then
99-
if ! start_up $port; then
99+
if ! start_up "$port"; then
100100
shut_down
101101
fi
102102
else

0 commit comments

Comments
 (0)