This repository has been archived by the owner on Mar 28, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathsquashfs-start.sh
executable file
·114 lines (83 loc) · 2.85 KB
/
squashfs-start.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
#!/usr/bin/env bash
## Required packages: fuse
# Prevent launching as root
if [ -z $ALLOW_ROOT ]; then
if [ $EUID = 0 ]; then
echo "Do not run this app as root!"
echo
echo "If you really need to run it as root, set ALLOW_ROOT env variable"
exit 1
fi
fi
# Full path to the script
script="$(readlink -f "${BASH_SOURCE[0]}")"
# Working directory where squashfs image will be mounted
# Default path: /tmp/scriptname_username_randomnumber
working_dir=/tmp/"$(basename "$0")"_"$(id -un)"_$RANDOM
# It's important to set correct sizes below, otherwise there will be
# a problem with mounting the squashfs image due to an incorrectly calculated offset.
# The size of this script
scriptsize=2920
# The size of the squashfuse.tar archive
# Squashfuse.tar contains squashfuse binaries
sfusesize=1423360
# Offset where the squashfs image is stored
offset=$((scriptsize+sfusesize))
appname="Wine (amd64) Portable SquashFS"
# Enable this if packed Wine requires a 64-bit OS to work
app_arch_amd64=1
if [ "$1" = "--help" ] || [ "$1" = "-h" ]; then
echo -e "-e \tExtract app files"
echo -e "-o \tShow squashfs offset"
exit
elif [ "$1" = "-e" ]; then
if command -v unsquashfs 1>/dev/null; then
unsquashfs -o $offset -d "$(basename "$0")"_files "${script}"
else
echo "To extract the image install squashfs-tools."
fi
exit
elif [ "$1" = "-o" ]; then
echo $offset
exit
fi
# If the app is 64-bit, then check if the OS is 64-bit too
if [ $app_arch_amd64 = 1 ] && [ $(getconf LONG_BIT) != 64 ]; then
echo "64-bit OS is required for this app to work!"
exit 1
fi
# Check if FUSE is installed
if ! command -v fusermount 1>/dev/null; then
echo "Please install fuse and run the app again"
exit 1
fi
echo "$appname"
echo
# Check if squashfuse is installed, and if it's not, then use the builtin binaries
if ! command -v squashfuse 1>/dev/null || [ -z "$USE_SYSTEM_SQUASHFUSE" ]; then
mkdir -p "${working_dir}"
tail -c +$((scriptsize+1)) "${script}" | head -c $sfusesize > "${working_dir}"/squashfuse.tar
tar -C "${working_dir}" -xf "${working_dir}"/squashfuse.tar
rm "${working_dir}"/squashfuse.tar
export LD_LIBRARY_PATH="${LD_LIBRARY_PATH}:${working_dir}/squashfuse/squashfuse-amd64"
sfuse="${working_dir}"/squashfuse/squashfuse-amd64/squashfuse
chmod +x "${sfuse}"
else
echo "Using squashfuse installed in the system"
echo
sfuse=squashfuse
fi
mkdir -p "${working_dir}"/mnt
fusermount -u "${working_dir}"/mnt 2>/dev/null || umount "${working_dir}"/mnt 2>/dev/null
"${sfuse}" -o offset=$offset "${script}" "${working_dir}"/mnt
if [ $? = 0 ]; then
if [ "$1" = "wine" ]; then shift; fi
if [ "$1" = "wine64" ]; then shift; fi
env -u LD_LIBRARY_PATH "${working_dir}"/mnt/wine.sh "$@"
fusermount -uz "${working_dir}"/mnt 2>/dev/null || umount --lazy "${working_dir}"/mnt 2>/dev/null
else
echo "Mounting the squashfs image failed!"
exit 1
fi
rm -rf "${working_dir}"
exit