-
Notifications
You must be signed in to change notification settings - Fork 4
/
script.sh
executable file
·120 lines (92 loc) · 3.26 KB
/
script.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
#!/bin/bash
set -e
########################################################################
##
## Functions.
##
########################################################################
createTmpDir()
{
mkdir -v "$1"
trap "rm -rfv "$1"" 0 1 2 3 15
}
########################################################################
##
## Variables.
##
########################################################################
# All commands use a file "init.inc.sh". This file could be put in the top
# plugin directory ($fm_plugin_dir). However, one may copy a command to paste
# it elsewhere. In this case, the file "init.inc.sh" would no longer be usable.
# Therefore, the file is copied in each command directory.
prefix=cstm_
# Script containing the file "init.inc.sh" used as reference (the one modified
# to be copied later).
referenceScript=07e29d93
# All other scripts also using "init.inc.sh".
otherScripts=(5f2da32b 4dd8d781 5547e7e2 33004b48 4797e2c9 14ae0ba2 649b55e5 7397b1e3)
allScripts=("$referenceScript" "${otherScripts[@]}")
# Empty directories (for the plugin itself and for separators).
emptyDir=(73def2cb 34fb861a 59ec5ff8 49454e21)
########################################################################
##
## Main script code.
##
########################################################################
# Generate an archive from the source code. This archive can be used in SpaceFM
# to install the plugin.
if [[ $1 == archive ]]; then
if [[ $2 != @(en|fr|sv) ]]; then
echo "Please pass a valid language parameter."
exit 1
fi
tmpDir=corbeille-tmp
createTmpDir "$tmpDir"
for script in "${allScripts[@]}"; do
cp -rv "$prefix$script" "$tmpDir"
cp -v "$prefix$referenceScript/init.inc.sh" "$tmpDir/$prefix$script"
cp -v README.md "$tmpDir/$prefix$script"
done
for dir in "${emptyDir[@]}"; do
mkdir -v "$tmpDir/$prefix$dir"
done
cp -v plugin "$tmpDir"
if [[ -f sed-$2-patterns.txt ]]; then
sed -i -f "sed-$2-patterns.txt" "$tmpDir/plugin"
fi
cp -v gpl-3.0.txt "$tmpDir"
cp -v LISEZ-MOI.md "$tmpDir"
cp -v README.md "$tmpDir"
if [[ -n $3 ]]; then
version=$3
else
version=source
fi
tar -zcvf "Corbeille-$2-$version.spacefm-plugin.tar.gz" -C "$tmpDir" .
# Update the Corbeille-SpaceFM git repository from the contents of an archive
# exported by SpaceFM. It's expected that the archive will be in French, located
# on the desktop and named "Corbeille.spacefm-plugin.tar.gz".
elif [[ $1 == git ]]; then
desktopPath=$(xdg-user-dir DESKTOP)
archivePath=$desktopPath/Corbeille.spacefm-plugin.tar.gz
if [[ ! -e $archivePath ]]; then
echo "Please provide a valid path to the plugin archive."
exit 1
fi
tmpDir=${archivePath%.*.*}
createTmpDir "$tmpDir"
tar -zxvf "$archivePath" -C "$tmpDir"
for script in "${allScripts[@]}"; do
mkdir -pv "$prefix$script"
cp -v "$tmpDir/$prefix$script/exec.sh" "$prefix$script"
done
# Just one file "init.inc.sh" in the repository.
cp -v "$tmpDir/$prefix$referenceScript/init.inc.sh" "$prefix$referenceScript"
cp -v "$tmpDir/plugin" .
# Update the file "init.inc.sh" for all commands of the plugin used in SpaceFM.
elif [[ $1 == init ]]; then
path=$HOME/.config/spacefm/scripts
for script in "${otherScripts[@]}"; do
cp -v "$path/$prefix$referenceScript/init.inc.sh" "$path/$prefix$script"
done
fi