@@ -18,91 +18,94 @@ function module_ghost () {
1818 local title=" ghost"
1919 local condition=$( which " $title " 2> /dev/null)
2020
21- if pkg_installed docker-ce; then
22- local container=$( docker container ls -a | mawk ' /(^|[[:space:]])ghost([[:space:]]|$)/{print $1}' )
23- local image=$( docker image ls -a | mawk ' /(^|[[:space:]])ghost([[:space:]]|$)/{print $1":"$2}' )
24- fi
25-
26- GHOST_BASE=" ${SOFTWARE_FOLDER} /ghost"
21+ pkg_installed docker.io || module_docker install
22+ local container=$( docker container ls -a --filter " name=ghost" --format ' {{.ID}}' )
23+ local image=$( docker image ls -a --format ' {{.Repository}}:{{.Tag}}' | grep ' ^ghost:' | head -1)
2724
2825 local commands
2926 IFS=' ' read -r -a commands <<< " ${module_options[" module_ghost,example" ]}"
3027
31- case $1 in
32- " ${commands[0]} " )
28+ GHOST_BASE=" ${SOFTWARE_FOLDER} /ghost"
3329
34- # instatall mysql if not installed
35- if ! module_mysql status; then
36- module_mysql install
37- fi
30+ case " $1 " in
31+ " ${commands[0]} " )
32+ # Install mysql if not installed
33+ if ! module_mysql status; then
34+ module_mysql install
35+ fi
36+
37+ # Exit if ghost is already running
38+ if [[ " ${container} " && " ${image} " ]]; then
39+ echo " Ghost container is already installed and running."
40+ exit 0
41+ fi
3842
39- # exit if ghost is already running
40- if module_ghost status; then
41- exit 0
42- fi
43+ MYSQL_USER=" ${2:- armbian} "
44+ MYSQL_PASSWORD=" ${3:- armbian} "
4345
44- MYSQL_USER=" ${2:- armbian} "
45- MYSQL_PASSWORD=" ${3:- armbian} "
46+ [[ -d " $GHOST_BASE " ]] || mkdir -p " $GHOST_BASE " || { echo " Couldn't create storage directory: $GHOST_BASE " ; exit 1; }
47+ docker run -d \
48+ --name ghost \
49+ --net=lsio \
50+ --restart unless-stopped \
51+ -e database__client=mysql \
52+ -e database__connection__host=" mysql" \
53+ -e database__connection__user=" ${MYSQL_USER} " \
54+ -e database__connection__password=" ${MYSQL_PASSWORD} " \
55+ -e database__connection__database=" ghost" \
56+ -p " ${module_options["module_ghost,port"]} :2368" \
57+ -e url=" http://$LOCALIPADD :${module_options["module_ghost,port"]} " \
58+ -v " $GHOST_BASE :/var/lib/ghost/content" \
59+ ghost:6
4660
47- [[ -d " $GHOST_BASE " ]] || mkdir -p " $GHOST_BASE " || { echo " Couldn't create storage directory: $GHOST_BASE " ; exit 1; }
48- docker pull ghost:5-alpine
49- docker run -d \
50- --name ghost \
51- --net=lsio \
52- --restart unless-stopped \
53- -e database__client=mysql \
54- -e database__connection__host=" mysql" \
55- -e database__connection__user=" ${MYSQL_USER} " \
56- -e database__connection__password=" ${MYSQL_PASSWORD} " \
57- -e database__connection__database=" ghost" \
58- -p ${module_options["module_ghost,port"]} :2368 \
59- -e url=http://$LOCALIPADD :${module_options["module_ghost,port"]} \
60- -v " $GHOST_BASE :/var/lib/ghost/content" \
61- ghost:6
61+ # Wait for container to start
62+ for i in $( seq 1 20) ; do
63+ state=" $( docker inspect -f ' {{.State.Status}}' ghost 2> /dev/null || true) "
64+ if [[ " $state " == " running" ]]; then
65+ break
66+ fi
67+ sleep 3
68+ if [[ $i -eq 20 ]]; then
69+ echo -e " \nTimed out waiting for ${title} to start, consult logs (\` docker logs ghost\` )"
70+ exit 1
71+ fi
72+ done
6273 ;;
63- " ${commands[1]} " )
64- if pkg_installed docker-ce; then
65- local container=$( docker container ls -a | mawk ' /(^|[[:space:]])ghost([[:space:]]|$)/{print $1}' )
66- local image=$( docker image ls -a | mawk ' /(^|[[:space:]])ghost([[:space:]]|$)/{print $1":"$2}' )
67- fi
74+ " ${commands[1]} " )
6875 if [[ " ${container} " ]]; then
69- docker container rm -f " $container " > /dev/null
70- fi
71- if [[ " ${image} " ]]; then
72- docker image rm " $image " > /dev/null
76+ docker container rm -f " $container " > /dev/null 2>&1
7377 fi
7478 ;;
75- " ${commands[2]} " )
79+ " ${commands[2]} " )
7680 ${module_options["module_ghost,feature"]} ${commands[1]}
81+ if [[ " ${image} " ]]; then
82+ docker image rm " $image " > /dev/null 2>&1 || true
83+ fi
7784 if [[ -n " ${GHOST_BASE} " && " ${GHOST_BASE} " != " /" ]]; then
7885 rm -rf " ${GHOST_BASE} "
7986 fi
8087 ;;
81- " ${commands[3]} " )
82- if pkg_installed docker-ce; then
83- local container=$( docker container ls -a | mawk ' /(^|[[:space:]])ghost([[:space:]]|$)/{print $1}' )
84- local image=$( docker image ls -a | mawk ' /(^|[[:space:]])ghost([[:space:]]|$)/{print $1":"$2}' )
85- fi
88+ " ${commands[3]} " )
8689 if [[ " ${container} " && " ${image} " ]]; then
8790 return 0
8891 else
8992 return 1
9093 fi
9194 ;;
92- " ${commands[4]} " )
93- echo -e " \nUsage: ${module_options["module_ghost,feature"]} <command>"
94- echo -e " Commands: ${module_options["module_ghost,example"]} "
95- echo " Available commands:"
96- echo -e " \tinstall\t- Install $title ."
97- echo -e " \t Optionally accepts arguments:"
98- echo -e " \t db_host db_user db_pass db_name url "
99- echo -e " \tremove\t- Remove $title ."
100- echo -e " \tpurge\t- Purge $title image and data."
101- echo -e " \tstatus\t- Show container status."
102- echo
95+ " ${commands[4]} " )
96+ echo -e " \nUsage: ${module_options["module_ghost,feature"]} <command>"
97+ echo -e " Commands: ${module_options["module_ghost,example"]} "
98+ echo " Available commands:"
99+ echo -e " \tinstall\t- Install $title ."
100+ echo -e " \t Optionally accepts arguments:"
101+ echo -e " \t db_user db_pass"
102+ echo -e " \tremove\t- Remove $title ."
103+ echo -e " \tpurge\t- Purge $title data folder ."
104+ echo -e " \tstatus\t- Installation status $title ."
105+ echo
103106 ;;
104- * )
105- module_ghost " ${commands[4]} "
107+ * )
108+ ${module_options[" module_ghost,feature"]} ${commands[4]}
106109 ;;
107110 esac
108111}
0 commit comments