blob: 7697c6c748ec46fce1ceb39658062f3892a3541d (
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
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
|
transfer_file(){
[ -f "$1" ] || return 0
dos2unix -u "$1"
source "$1"
local res=$?
rm -f "$1"
return $res
}
transfer_default(){
rsync -ac \
--exclude "/install" \
--exclude "/transfer" \
--exclude "/uninstall" \
--exclude "*.hmod" \
"$transferpath/" "$rootfs/"
}
transfer_path(){
local transferpath="$1"
chown -R 0:0 "$transferpath/"
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
cd "$transferpath"
[ -d "./bin" ] && chmod 755 ./bin/*
[ -d "./etc/init.d" ] && chmod 755 ./etc/init.d/*
transfer_file "$transferpath/install" || docopy=n
cd "$transferpath"
transfer_file "$transferpath/transfer" || docopy=n
[ "$docopy" == "y" ] && transfer_default
}
pack_upath(){
echo "$installpath/hmod/uninstall-$(basename "$1" .hmod)"
}
pack_install(){
local packFile="$(readlink -f "$1")"
local packName="$(basename "$1" .hmod)"
echo "installing $packName..."
if [ -f "$packFile" ]; then
local transferpath="$temppath/pack"
rm -rf "$transferpath"
mkdir -p "$transferpath"
cd "$transferpath" && tar -xzf "$packFile"
else
local transferpath="$packFile"
fi
transfer_path "$transferpath"
if grep -xqF "no-uninstall" "$transferpath/uninstall"; then
echo "package $packName installed"
return 0
fi
echo "creating uninstall for $packName..."
echo >> "$transferpath/uninstall"
echo "# auto-generated" >> "$transferpath/uninstall"
cd "$transferpath"
find . -type l -exec echo rm -f \"\$rootfs/{}\" + >> "$transferpath/uninstall"
find . -type f -exec echo rm -f \"\$rootfs/{}\" + >> "$transferpath/uninstall"
find . -depth -mindepth 1 -type d -exec echo rmdir \"\$rootfs/{}\" + >> "$transferpath/uninstall"
[ $(stat -c%s "$transferpath/uninstall") -gt 8 ] || rm -f "$transferpath/uninstall"
cd /
local unfile="$(pack_upath "$packFile")"
if [ -f "$transferpath/uninstall" ]; then
dos2unix -u "$transferpath/uninstall"
sed -i "s#rmdir #rmdir --ignore-fail-on-non-empty #" "$transferpath/uninstall"
mkdir -p "$installpath/hmod"
copy "$transferpath/uninstall" "$unfile"
else
rm -f "$unfile"
fi
echo "package $packName installed"
}
pack_list(){
if [ -d "$installpath/hmod" ]; then
for i in $(find "$installpath/hmod/" -maxdepth 1 -type f -name "uninstall-*" | sort); do
echo "${i##$installpath/hmod/uninstall-}"
done
fi
}
pack_uninstall(){
if [ "$1" == "all" ]; then
for i in $(pack_list); do
pack_uninstall "$i"
done
else
local unfile="$(pack_upath "$1")"
if [ -f "$unfile" ]; then
local packName="$(basename "$1" .hmod)"
echo "uninstalling $packName..."
cd "$rootfs"
transfer_file "$unfile"
echo "package $packName uninstalled"
fi
fi
cd /
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 "$i"
done
}
packs_uninstall(){
for i in $@; do
pack_uninstall "$i"
done
}
|