-
Notifications
You must be signed in to change notification settings - Fork 0
/
update.sh
50 lines (35 loc) · 1.18 KB
/
update.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
#!/bin/bash
user_home_dir=~
file_name=config.json
github_release_download_url="https://api.github.com/repos/ArttuKuikka/RuokalistaAanestyspaate/zipball/"
current_directory=$(pwd)
#Copy config to a safe place
echo "Copying $file_name to $user_home_dir"
cp $file_name $user_home_dir
#Download latest release from github
wget -O Release.zip $github_release_download_url
#shutdown the services
sudo systemctl stop ruokalista-aanestyspaate.service
#After downloading is succesfull remove old files and unzip new ones
shopt -s extglob
rm -f !("Release.zip")
shopt -u extglob
echo "All files except Release.zip have been removed."
#unzip new files
unzip Release.zip
#get folder name
# Pattern to match the start of folder names
pattern="ArttuKuikka-RuokalistaAanestyspaate-*"
# Find the first folder matching the pattern
matching_folder=$(find -type d -name "$pattern" -print -quit)
#copy contents of unzipped file
cp $matching_folder/* .
#Remove downloaded files
rm -rf $matching_folder/
rm -rf Release.zip
#Copy config back
echo "Copying config back"
cp $user_home_dir/$file_name $current_directory/$file_name
chmod +x *
#start the services
sudo systemctl start ruokalista-aanestyspaate.service