forked from tryforsure/PM4Linux-installer
-
Notifications
You must be signed in to change notification settings - Fork 0
/
compile
executable file
·122 lines (104 loc) · 3.2 KB
/
compile
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
121
122
#!/bin/bash
# Constants
base_url="http://linux.palemoon.org"
version="0.2.2"
# Compile the scripts into a single self-extracting script and package it within a *.tar.bz2
show_help () {
echo "Usage: $0 [OPTIONS]"
cat << EOM
Compile the scripts into a single self-extracting script and package it within a
*.tar.bz2.
Options:
--base-url=URL Use a custom base URL instead of the default
--no-minify Don't minify scripts
--no-cleanup Don't remove temporary files from build/ directory.
EOM
}
show_error_msg () {
echo "Argument not recognized: $1"
echo "Please type $0 --help for help."
}
# Exit on most errors
set -e
unset CDPATH
while [[ ! -z "$1" ]]; do
case "$1" in
--base-url=*)
base_url="$(echo "$1" | sed -r 's|^--base-url=||g;s|/$||g')"
if [[ ! $base_url =~ ^(https?|ftp)://[a-z0-9_.]+/.*$ ]]; then
echo "The base URL is not valid!"
exit 1
fi
shift
;;
--no-minify)
no_minify=1
shift
;;
--no-cleanup)
no_cleanup=1
shift
;;
--help)
show_help
exit 0
;;
*)
show_error_msg "$1"
exit 1
esac
done
pkgfileslist=("bin" "tools" "files" "userdocs" "installer.sh")
sfxscript="sfx.sh"
readmefile="userdocs/README"
installer="pminstaller.sh"
archive="pminstaller-$version.tar.bz2"
cd "$(dirname "$0")"
selfdir="$(pwd)"
if [[ -e build ]]; then
rm -rf build
fi
echo "Copying required files..."
mkdir build
cp -rv ${pkgfileslist[@]} "$sfxscript" build/
fold -w 80 -s "$readmefile" > build/"$(basename "$readmefile")"
cd build
# Perform required substitutions
echo "Perform required substitutions in the script(s)..."
while read filename; do
sed -i'' -r "s|__BASE_URL__|$base_url|g;s|__VERSION__|$version|g" "$filename"
done < <(find . -type f ! -wholename '*/bin/*')
# Minify scripts
if [[ -z $no_minify ]]; then
echo "Minifying scripts..."
while read filename; do
if head -n 1 "$filename" | grep -E '^#!/bin/(ba)?sh' &> /dev/null; then
echo "Minifying $filename..."
# bash_obfus seems to have some problems with stripping indented comments, so...
"$selfdir/bashobfus/bash_obfus.pl" -i "$filename" -o /dev/stdout -C -F | grep -Ev '^#[^!]' > "$filename.1"
mv "$filename.1" "$filename"
fi
done < <(find . -type f ! -wholename "*/files/*")
fi
# Set permissions
echo "Setting permissions for files in SFX archive..."
while read filename; do
if head -c 4 "$filename" | grep -E $'(#!|\x7fELF)' &> /dev/null; then
chmod -v a+x "$filename"
fi
done < <(find . -type f)
# Prepare SFX
tar --verbose --numeric-owner --group=0 --owner=0 -cJf tmp.tar.xz ${pkgfileslist[@]}
lines=$(($(cat "$sfxscript" | wc -l) + 1))
sed s/__LINENUM__/$lines/ "$sfxscript" > "$installer"
cat tmp.tar.xz >> "$installer"
checksum=$(sed -r s/__CHECKSUM__// "$installer" | sha256sum | grep -Eo [a-f0-9]{64})
sed s/__CHECKSUM__/$checksum/ "$installer" > "$installer.1"
mv "$installer.1" "$installer"
# Package in redistributable format
echo "Packaging installer within tarball..."
chmod -v 755 "$installer"
tar --verbose --numeric-owner --group=0 --owner=0 -cjf "$archive" "$(basename "$readmefile")" "$installer"
if [[ -z $no_cleanup ]]; then
find . ! -name "$archive" -delete
fi