blob: e7e29970d7564a5012593b7e707c8d2c3d10b1cd (
plain)
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
|
transfer_file(){
[ -f "$1" ] || return 0
dos2unix -u "$1"
guard_ud(){
source "$1"
return 0
}
guard_ud "$1"
res=$?
rm -f "$1"
return $res
}
transfer_default(){
rsync -ac \
--exclude "/install" \
--exclude "/transfer" \
--exclude "/uninstall" \
--exclude "*.hmod" \
"$transferpath/" "$installpath/"
}
transfer_path(){
local transferpath=$1
find "$transferpath/" -maxdepth 1 -type f -iname "readme.*" -delete
find "$transferpath/" -maxdepth 1 -type f -iname "*.txt" -delete
find "$transferpath/" -maxdepth 1 -type f -iname "*.md" -delete
local docopy=y
transfer_file "$transferpath/install" || docopy=n
transfer_file "$transferpath/transfer" || docopy=n
[ "$docopy" == "y" ] && transfer_default
}
pack_upath(){
echo $installpath/hmod/uninstall-$(basename "$1" .hmod)
}
pack_install(){
echo installing $(basename "$1" .hmod)...
if [ -f "$1" ]; then
local transferpath=$temppath/pack
rm -rf "$transferpath"
mkdir -p "$transferpath"
cd "$transferpath" && tar -xzf "$1"
else
local transferpath=$1
fi
transfer_path "$transferpath"
mkdir -p "$installpath/hmod"
if [ ! -f "$transferpath/uninstall" ]; then
echo creating uninstall for $(basename "$1" .hmod)...
cd "$transferpath"
find . -type l -exec echo rm -f \"\$installpath/{}\" + >> "$transferpath/uninstall"
find . -type f -exec echo rm -f \"\$installpath/{}\" + >> "$transferpath/uninstall"
find . -depth -mindepth 1 -type d -exec echo rmdir \"\$installpath/{}\" + >> "$transferpath/uninstall"
[ $(stat -c%s "$transferpath/uninstall") -gt 8 ] || rm -f "$transferpath/uninstall"
fi
cd /
local unfile=$(pack_upath "$1")
if [ -f "$transferpath/uninstall" ]; then
dos2unix -u "$transferpath/uninstall"
sed -i "s#rmdir #rmdir --ignore-fail-on-non-empty #" "$transferpath/uninstall"
copy "$transferpath/uninstall" "$unfile"
else
rm -f "$unfile"
fi
echo package $(basename "$1" .hmod) installed
}
pack_uninstall(){
if [ "$1" == "all" ]; then
if [ -d "$installpath/hmod" ]; then
for i in $(find "$installpath/hmod/" -maxdepth 1 -type f -name "uninstall-*" | sort); do
pack_uninstall "$i"
done
fi
else
local unfile=$(pack_upath "$1")
if [ -f "$unfile" ]; then
echo uninstalling $(basename "$1" .hmod)...
transfer_file "$unfile"
echo package $(basename "$1" .hmod) uninstalled
fi
fi
rmdir --ignore-fail-on-non-empty "$installpath/hmod"
}
packs_install(){
[ -d "$1" ] || return 1
for i in $(find "$1" -maxdepth 1 -name "*.hmod" | sort); do
pack_install "$i"
rm -rf "$1"
done
}
packs_uninstall(){
[ -d "$1" ] || return 1
for i in $@; do
pack_uninstall "$i"
done
}
|