Skip to content

Commit 13c7481

Browse files
FF-232 FF-233 Update Script (#9)
* basics of the stable update script * cleaning * added the latest update * fixed error with digest check * cleaning * changes requested by @open-schnick, updated readme * minor spelling fix. * added more >/dev/null 2>&1 * Bumped Version to 1.5 Co-authored-by: open-schnick <[email protected]>
1 parent 4e31885 commit 13c7481

File tree

7 files changed

+227
-21
lines changed

7 files changed

+227
-21
lines changed

Install.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ if [ $? == 127 ]; then # command does not exist add it to path
2828
echo "$newPATH" >>"$rc"
2929
commandToRun="source $rc"
3030
else
31-
echo "Couldn't add FileFighter Application to PATH. Please contact us at filefighter@t-online.de."
31+
echo "Couldn't add FileFighter Application to PATH. Please contact us at dev@filefighter.de."
3232
echo "Or add following line to your PATH variable:"
3333
echo "$rootDir"
3434
exit 1

README.md

Lines changed: 38 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ You need [Docker](https://www.docker.com/).
1414
Docker is a way to organise and run multiple applications. You can imagine it like a virtual machine (technical it`s a bit different), with a small file- and operating system within your machine.
1515
Sounds more scary than it actually is. Different Applications run in different containers, these only contain the necessary software to run the application.
1616
The containers use the resources of the host machine, depending on the load.
17-
Advantages are security and the possibility to easily shutdown and update the services. See more under [Usage](#Usage).
17+
Advantages are security and the possibility to easily shutdown and update the services. See more under ["Running FileFighter"](#Running FileFighter).
1818

1919
#### Docker
2020
First check whether you have Docker already installed.
@@ -26,7 +26,7 @@ If you see something like that (your version might be different):
2626
```shell script
2727
Docker version 19.03.13, build 4484c46d9f
2828
```
29-
You are good to go, and you can skip to [Usage](#Usage).
29+
You are good to go, and you can skip to ["Installing FileFighter"](#Installing FileFighter).
3030

3131
To install **Docker** on Unix you can either use [snap](https://www.howtogeek.com/660193/how-to-work-with-snap-packages-on-linux/) or [apt](https://en.wikipedia.org/wiki/APT_(software)) as a package manager.
3232
With snap its easier but of course it's not always possible to use snap.
@@ -44,16 +44,16 @@ After successfully installing Docker you can start using FileFighter.
4444
Just download this repository as a zipfile [here](https://github.com/FileFighter/ClientSetup/releases/).
4545
This repository contains the *Install.sh* installation script.
4646
```shell script
47-
dev@filefighter:~/Downloads/FileFighter-1.3 $ ls
47+
dev@filefighter:~/Downloads/FileFighter-1.5 $ ls
4848
config.cfg ffighter Install.sh lib README.md
4949
```
5050
You can execute the script:
5151
```shell script
52-
dev@filefighter:~/Downloads/FileFighter-1.3 $ ./Install.sh
52+
dev@filefighter:~/Downloads/FileFighter-1.5 $ ./Install.sh
5353
```
5454
And you should see something like that:
5555
```shell script
56-
dev@filefighter:~/Downloads/FileFighter-1.3 $ ./Install.sh
56+
dev@filefighter:~/Downloads/FileFighter-1.5 $ ./Install.sh
5757
Adding FileFighter Application to PATH...
5858
Adding FileFighter Application to PATH was successful.
5959
Please run the following command to finish the installation.
@@ -65,16 +65,16 @@ Running this command will add the FileFighter Application to your System.
6565
You can use the FileFighter Application with the command *ffighter*
6666
Running this command should show you something like that:
6767
```shell script
68-
dev@filefighter:~/Downloads/FileFighter-1.3 $ ffighter
68+
dev@filefighter:~/Downloads/FileFighter-1.5 $ ffighter
6969
_____ _ _ _____ _ _ _
7070
| ___| (_) | | ___ | ___| (_) __ _ | |__ | |_ ___ _ __
7171
| |_ | | | | / _ \ | |_ | | / _` | | '_ \ | __| / _ \ | '__|
7272
| _| | | | | | __/ | _| | | | (_| | | | | | | |_ | __/ | |
7373
|_| |_| |_| \___| |_| |_| \__, | |_| |_| \__| \___| |_|
7474
|___/
75-
Version v1.3 Last updated: 08.11.20
75+
Version v1.5 Last updated: 21.12.20
7676
Developed by Gimleux, Valentin, Open-Schnick.
77-
Development Blog: https://filefighter.github.io
77+
Development Blog: https://blog.filefighter.de
7878
The code can be found at: https://www.github.com/filefighter
7979
8080
-------------------------< Show Usage >---------------------------
@@ -86,6 +86,7 @@ usage: ffighter <args>
8686
start - start the services.
8787
stop - stop the services.
8888
remove - remove all services.
89+
update - update all the services that have a new version available.
8990
```
9091
You can see all the available options to run with *ffighter*.
9192
@@ -96,6 +97,7 @@ You can see all the available options to run with *ffighter*.
9697
| start | Start the services if already downloaded. |
9798
| stop | Stop the services if running. |
9899
| remove | Remove all services. |
100+
| update | Update all the services that have a new version available. |
99101
100102
To start the Application just run:
101103
```shell script
@@ -117,8 +119,7 @@ Valid keys to configure how FileFighter behaves are listed here:
117119
118120
| Key | Possible Values | Default | Description |
119121
| :----: | :----: | :----: | :----: |
120-
| rest_port | 0-65535 | 8080 | The port of the restapi service that will be published for the frontend. |
121-
| frontend_port | 0-65535 | 80 | The port of the webapp (frontend) service. You can visit the FileFighter application over this port. |
122+
| app_port | 0-65535 | 80 | The port of the application. You can visit the FileFighter application over this port. |
122123
| db_user | any string | root | The name of the Database running in the background. |
123124
| db_password | any string | none (see below) | The password of the database. (The database won't be exposed to the internet, but passwords never hurt.) |
124125
| db_name | any string | filefighter | The name of the database. |
@@ -130,8 +131,34 @@ If the `db_password` key is empty, a random password will be generated.
130131
131132
Be carefully as the developers of FileFighter won't take responsibility when you are using the application or configuration options wrong or in a not intended way.
132133
134+
## Updating
135+
To update us the update command:
136+
137+
```shell script
138+
ffighter update
139+
```
140+
This will check if new versions of the different services are available and will apply the updates.
141+
Depending on the configuration the update will either use the current stable version (recommended) or the newest latest version (experimental).
142+
143+
In case you are using the latest versions you will also need to install [regclient](https://github.com/regclient/regclient/releases).
144+
Download the right version depending on your operating system and architecture, rename it to 'regctl', make it executable and move it to a folder that is in your path variable.
145+
146+
### Auto update
147+
To achieve automatic updates you can set up a cron job as described in this [article](https://ostechnix.com/a-beginners-guide-to-cron-jobs/) with the update command.
148+
149+
## Other operation systems (Windows)
150+
151+
If you are not able to run the shell script for the installation you can still run FileFighter using [Docker Compose](https://docs.docker.com/compose/).
152+
Just download the [docker-compose.yml](https://raw.githubusercontent.com/FileFighter/ClientSetup/master/docker-compose.yml) file or clone this repo and execute this command in the folder where the file is located:
153+
154+
```shell script
155+
docker-compose up
156+
```
157+
This will also start all services and make them available [here](http://localhost:80/).
158+
159+
133160
## Remaining Files
134161
All the remaining not explicitly explained files are important for the scripts to work and should not be changed manually.
135162
136163
## Help
137-
For further help, feedback or questions write us an [email](mailto:filefighter@t-online.de).
164+
For further help, feedback or questions write us an [email](mailto:dev@filefighter.de).

ffighter

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,10 @@ source lib/install.sh
1111
source lib/start.sh
1212
source lib/stop.sh
1313
source lib/status.sh
14+
source lib/update.sh
1415

15-
version="v1.4"
16-
date="15.11.20"
16+
version="v1.5"
17+
date="21.12.20"
1718

1819
# Check if docker is running
1920
if ! docker info >/dev/null 2>&1; then
@@ -57,6 +58,12 @@ if [[ $1 == "remove" ]]; then
5758
exit 0
5859
fi
5960

61+
if [[ $1 == "update" ]]; then
62+
echoLogo $version $date "Updating FileFighter"
63+
ffupdate
64+
exit 0
65+
fi
66+
6067
echoLogo $version $date "Show Usage"
6168
printUsage
6269
exit 1

lib/install.sh

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,6 @@ ffinstall() {
123123
echo "Creating Frontend Container, with tag: $frontendVersion."
124124
echo "Downloading filefighter/frontend image."
125125
docker create \
126-
-e REST_PORT=$rest_port \
127126
--network $networkname \
128127
--name $frontendname filefighter/frontend:$frontendVersion >/dev/null 2>&1
129128

lib/remove.sh

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,10 @@ ffremove() {
66
reverseproxyname="FileFighterReverseProxy"
77

88
if [[ $(docker ps -a --format "{{.Names}}" | grep $restname) ]] || [[ $(docker ps -a --format "{{.Names}}" | grep $frontendname) ]] || [[ $(docker ps -a --format "{{.Names}}" | grep $dbname) ]] || [[ $(docker ps -a --format "{{.Names}}" | grep $reverseproxyname) ]]; then
9-
docker container stop $restname && docker container rm $restname
10-
docker container stop $frontendname && docker container rm $frontendname
11-
docker container stop $dbname && docker container rm $dbname
12-
docker container stop $reverseproxyname && docker container rm $reverseproxyname
9+
docker container stop $restname && docker container rm $restname >/dev/null 2>&1
10+
docker container stop $frontendname && docker container rm $frontendname >/dev/null 2>&1
11+
docker container stop $dbname && docker container rm $dbname >/dev/null 2>&1
12+
docker container stop $reverseproxyname && docker container rm $reverseproxyname >/dev/null 2>&1
1313

1414
echo ""
1515
echo "Removed FileFighter Application. Install it again with 'ffighter install'."

lib/update.sh

Lines changed: 172 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,172 @@
1+
restname="FileFighterREST"
2+
frontendname="FileFighterFrontend"
3+
networkname="FileFighterNetwork"
4+
dbname="FileFighterDB"
5+
6+
7+
ffupdate(){
8+
9+
if [[ $(docker ps -a --format "{{.Names}}" | grep $restname) ]] || [[ $(docker ps -a --format "{{.Names}}" | grep $frontendname) ]] || [[ $(docker ps -a --format "{{.Names}}" | grep $dbname) ]] || [[ $(docker ps -a --format "{{.Names}}" | grep $reverseproxyname) ]]; then
10+
echo "Installation is fine, starting to read config..."
11+
else
12+
echo "FileFighter is not installed, run 'ffighter install' first"
13+
fi
14+
15+
source lib/config.sh # load the config library functions
16+
source lib/dockertags.sh # load docker functions.
17+
18+
configFilePath=$(pwd)/config.cfg
19+
20+
# Read in default keys.
21+
app_port="$(read $configFilePath app_port)"
22+
db_name="$(read $configFilePath db_name)"
23+
db_user="$(read $configFilePath db_user)"
24+
db_password="$(read $configFilePath db_password)"
25+
use_stable_versions="$(read $configFilePath use_stable_versions)"
26+
27+
28+
if ! [[ $app_port ]]; then
29+
echo "Config for app_port not found, using defaults."
30+
app_port="$(read ./lib/config.cfg.defaults app_port)"
31+
fi
32+
33+
if ! [[ $db_name ]]; then
34+
echo "Config for db_name not found, using defaults."
35+
db_name="$(read config.cfg.defaults db_name)"
36+
fi
37+
38+
if ! [[ $db_user ]]; then
39+
echo "Config for db_user not found, using defaults."
40+
db_user="$(read config.cfg.defaults db_user)"
41+
fi
42+
43+
if ! [[ $db_password ]]; then
44+
echo "Config for db_password not found, using defaults."
45+
db_password="$(read config.cfg.defaults db_password)"
46+
fi
47+
48+
# Finished Config:
49+
echo "Finished reading config. starting update..."
50+
51+
# Check if (default) password was empty.
52+
if ! [[ $db_password ]]; then
53+
echo "Password was not set, please set the password in your config ($configFilePath) or run 'ffighter install' again"
54+
exit 1
55+
fi
56+
57+
# Check versions config
58+
if [[ $use_stable_versions == "true" ]]; then
59+
echo "Updating stable versions."
60+
ffupdateStable
61+
else
62+
echo "Warning! Updating latest versions."
63+
echo "Updating latest version is not recommended and might break the application. Please report found problems here: [email protected]."
64+
ffupdateLatest
65+
fi
66+
}
67+
68+
ffupdateStable(){
69+
70+
frontendVersionRepo="$(getTagsByName filefighter/frontend v | tail -1)"
71+
restVersionRepo="$(getTagsByName filefighter/rest v | tail -1)"
72+
73+
if [[ "$(docker images -q filefighter/frontend:$frontendVersionRepo 2> /dev/null)" == "" ]]; then
74+
echo "New version for FileFighter Frontend available, downloading it"
75+
docker container stop $frontendname && docker container rm $frontendname
76+
77+
echo "Creating Frontend Container, with tag: $frontendVersionRepo."
78+
echo "Downloading filefighter/frontend image."
79+
docker create \
80+
--network $networkname \
81+
--name $frontendname filefighter/frontend:$frontendVersionRepo >/dev/null 2>&1
82+
83+
echo "Finished downloading. Starting the updated container..."
84+
docker start $frontendname
85+
86+
else
87+
echo "FileFighter Frontend is up to date"
88+
fi
89+
90+
if [[ "$(docker images -q filefighter/rest:$restVersionRepo 2> /dev/null)" == "" ]]; then
91+
echo "New version for FileFighter Rest available, downloading it"
92+
docker container stop $restname && docker container rm $restname
93+
94+
# REST APP
95+
echo "Creating REST Container, with tag: $restVersionRepo."
96+
echo "Downloading filefighter/rest image."
97+
docker create \
98+
-e DB_USERNAME=$db_user \
99+
-e DB_PASSWORD=$db_password \
100+
-e DB_NAME=$db_name \
101+
-e DB_CONTAINER_NAME=$dbname \
102+
-e SPRING_PROFILES_ACTIVE="prod" \
103+
--expose 8080 \
104+
--network $networkname \
105+
--name $restname filefighter/rest:$restVersionRepo >/dev/null 2>&1
106+
107+
echo "Finished downloading. Restarting the updated container..."
108+
docker start $restname
109+
110+
echo ""
111+
else
112+
echo "FileFighter FileFighter Rest is up to date"
113+
fi
114+
}
115+
116+
ffupdateLatest(){
117+
118+
if ! type "regctl" >/dev/null 2>&1; then
119+
echo ""
120+
echo "regctl not found! Install it from here https://github.com/regclient/regclient/releases"
121+
echo ""
122+
exit 1
123+
fi
124+
125+
frontendDigest="$(regctl image digest --list filefighter/frontend:latest)"
126+
restDigest="$(regctl image digest --list filefighter/rest:latest)"
127+
128+
if [[ "$( docker inspect --format='{{.RepoDigests}}' filefighter/frontend:latest 2> /dev/null)" == "[filefighter/frontend@$frontendDigest]" ]]; then
129+
echo "FileFighter Frontend is up to date"
130+
else
131+
132+
echo "New version for FileFighter Frontend available, downloading it"
133+
134+
docker container stop $frontendname >/dev/null 2>&1 && docker container rm $frontendname >/dev/null 2>&1
135+
docker rmi filefighter/frontend:latest >/dev/null 2>&1
136+
137+
echo "Creating Frontend Container, with tag: latest."
138+
echo "Downloading filefighter/frontend image."
139+
docker create \
140+
--network $networkname \
141+
--name $frontendname filefighter/frontend:latest >/dev/null 2>&1
142+
143+
echo "Finished downloading. Restarting the updated container..."
144+
docker start $frontendname >/dev/null 2>&1
145+
fi
146+
147+
if [[ "$( docker inspect --format='{{.RepoDigests}}' filefighter/rest:latest 2> /dev/null)" == "[filefighter/rest@$restDigest]" ]]; then
148+
echo "FileFighter Rest is up to date"
149+
else
150+
echo "New version for FileFighter Rest available, downloading it"
151+
152+
docker container stop $restname >/dev/null 2>&1 && docker container rm $restname >/dev/null 2>&1
153+
docker rmi filefighter/rest:latest >/dev/null 2>&1
154+
155+
# REST APP
156+
echo "Creating REST Container, with tag: latest."
157+
echo "Downloading filefighter/rest image."
158+
docker create \
159+
-e DB_USERNAME=$db_user \
160+
-e DB_PASSWORD=$db_password \
161+
-e DB_NAME=$db_name \
162+
-e DB_CONTAINER_NAME=$dbname \
163+
-e SPRING_PROFILES_ACTIVE="prod" \
164+
--expose 8080 \
165+
--network $networkname \
166+
--name $restname filefighter/rest:latest >/dev/null 2>&1
167+
168+
echo "Finished downloading. Restarting the updated container..."
169+
docker start $restname >/dev/null 2>&1
170+
echo ""
171+
fi
172+
}

lib/utils.sh

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ echoLogo() {
77
echo " |___/ "
88
echo " Version $1 Last updated: $2"
99
echo " Developed by Gimleux, Valentin, Open-Schnick. "
10-
echo " Development Blog: https://filefighter.github.io "
10+
echo " Development Blog: https://blog.filefighter.de "
1111
echo " The code can be found at: https://www.github.com/filefighter "
1212
echo ""
1313
echo "-------------------------< $3 >---------------------------"
@@ -22,4 +22,5 @@ printUsage() {
2222
echo " start - start the services."
2323
echo " stop - stop the services."
2424
echo " remove - remove all services."
25-
}
25+
echo " update - update all the services that have a new version available."
26+
}

0 commit comments

Comments
 (0)