-
Notifications
You must be signed in to change notification settings - Fork 6
/
joplin.sh
129 lines (115 loc) · 3.38 KB
/
joplin.sh
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
#!/bin/bash
# adapted from https://github.com/laurent22/joplin/blob/dev/Dockerfile.server
if [[ -f /etc/default/joplin ]];then
. /etc/default/joplin
fi
GITDIR="${GITDIR:-$HOME/joplin}"
WORKDIR="${WORKDIR:-$HOME/build}"
JOPLIN_HOME="${JOPLIN_HOME:-/opt/joplin}"
SERVICE_NAME=joplin-server
COPY(){
cd $WORKDIR
SRC=$GITDIR/$1
DEST=$2
if [ ! -d $DEST ]; then
mkdir -p $2
fi
if [ -d "$SRC" ]; then
SRC="$SRC/"
fi
rsync -a $SRC $2/
}
checkout_latest(){
GITDIR_PARENT=$(realpath $GITDIR/..)
mkdir -p $GITDIR_PARENT && cd $GITDIR_PARENT
if [ ! -d $GITDIR ];then
git clone https://github.com/laurent22/joplin.git
fi
cd $GITDIR
git fetch --tags
latest=(`git describe --tags --match "server-*" --abbrev=0 $(git rev-list --tags --max-count=1)`)
git checkout $latest
}
build(){
if [ ! -d "$WORKDIR" ]; then
echo "build dir $WORKDIR does not exist!"
exit 1
fi
rm -r ${WORKDIR}/*
cd $WORKDIR
COPY .yarn/plugins ./.yarn/plugins
COPY .yarn/releases ./.yarn/releases
COPY .yarn/patches ./.yarn/patches
COPY package.json .
COPY .yarnrc.yml .
COPY yarn.lock .
COPY gulpfile.js .
COPY tsconfig.json .
COPY packages/turndown ./packages/turndown
COPY packages/turndown-plugin-gfm ./packages/turndown-plugin-gfm
COPY packages/fork-htmlparser2 ./packages/fork-htmlparser2
COPY packages/server/package*.json ./packages/server/
COPY packages/fork-sax ./packages/fork-sax
COPY packages/fork-uslug ./packages/fork-uslug
COPY packages/htmlpack ./packages/htmlpack
COPY packages/renderer ./packages/renderer
COPY packages/tools ./packages/tools
COPY packages/utils ./packages/utils
COPY packages/lib ./packages/lib
COPY packages/server ./packages/server
BUILD_SEQUENCIAL=1 yarn install --inline-builds \
&& yarn cache clean \
&& rm -rf .yarn/berry
}
install(){
cd $WORKDIR/
echo "installing packages to $JOPLIN_HOME/ ..."
rsync -a --delete ./packages/ $JOPLIN_HOME/packages/
}
run(){
APP_BASE_URL="${APP_BASE_URL:-https://joplin.me.org}"
APP_PORT="${APP_PORT:-22300}"
POSTGRES_PASSWORD="${POSTGRES_PASSWORD:-joplin}"
DB_CLIENT="${DB_CLIENT:-pg}"
POSTGRES_DATABASE="${POSTGRES_DATABASE:-joplin}"
POSTGRES_USER="${POSTGRES_USER:-joplin}"
POSTGRES_PORT="${POSTGRES_PORT:-5432}"
POSTGRES_HOST="${POSTGRES_HOST:-localhost}"
RUNNING_IN_DOCKER=0
export APP_BASE_URL APP_PORT DB_CLIENT POSTGRES_PASSWORD POSTGRES_DATABASE POSTGRES_USER POSTGRES_PORT POSTGRES_HOST RUNNING_IN_DOCKER
cd $JOPLIN_HOME
mkdir -p logs
npm --prefix packages/server start
}
case "$1" in
checkout-latest)
checkout_latest
;;
build)
build
;;
install)
install
;;
makeall)
if systemctl is-active $SERVICE_NAME > /dev/null ;then
echo "$SERVICE_NAME still running as service - stop the service first"
exit 1
fi
checkout_latest
build
install
echo "DONE!"
;;
run)
if systemctl is-active $SERVICE_NAME > /dev/null ;then
echo "$SERVICE_NAME still running as service - stop the service first"
exit 1
fi
run
;;
*)
echo "Usage: $0 {checkout-latest|build|install|makeall|run}"
exit 1
;;
esac