2020-03-16 02:51:30 +11:00
|
|
|
#!/usr/bin/env bash
|
|
|
|
set -eo pipefail
|
|
|
|
|
2021-03-13 07:12:13 +11:00
|
|
|
HERE="$(dirname "$(readlink -f "$0")")"
|
2020-03-22 06:20:57 +11:00
|
|
|
MIRAGE_REPO_URL='https://github.com/mirukana/mirage'
|
2021-03-13 07:12:13 +11:00
|
|
|
PY_XYZ=3.9.1
|
|
|
|
PY_XY="$(cut -d . -f 1-2 <<< "$PY_XYZ")"
|
2020-03-21 05:01:52 +11:00
|
|
|
|
2020-03-16 02:51:30 +11:00
|
|
|
|
|
|
|
check_distro() {
|
|
|
|
if grep -q '^\s*Ubuntu\s*16.04' /etc/issue; then return; fi
|
|
|
|
|
|
|
|
echo "Not running on expected distribution or version, aborting!" >&2
|
2020-03-27 09:51:30 +11:00
|
|
|
echo "See <repo root>/packaging/appimage/README.md for more info." >&2
|
2020-03-16 02:51:30 +11:00
|
|
|
exit 99
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
parse_cli_arguments() {
|
|
|
|
if [ "$1" = --skip-install-prerequisites ] || [ "$1" = -s ]; then
|
|
|
|
skip_pre=true
|
|
|
|
else
|
|
|
|
skip_pre=false
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
setup_dns() {
|
|
|
|
if ! grep -q 'dns-nameservers 9.9.9.9' /etc/network/interfaces; then
|
|
|
|
sed -i '/iface eth0 inet dhcp/a dns-nameservers 9.9.9.9' \
|
|
|
|
/etc/network/interfaces
|
|
|
|
|
|
|
|
invoke-rc.d networking restart
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
install_apt_packages() {
|
|
|
|
apt install -y software-properties-common
|
2021-03-01 05:20:58 +11:00
|
|
|
add-apt-repository -y ppa:beineri/opt-qt-5.12.9-xenial
|
2021-07-12 02:57:56 +10:00
|
|
|
add-apt-repository -y ppa:beineri/opt-qt-5.12.9-xenial
|
2020-03-16 02:51:30 +11:00
|
|
|
apt update -y
|
|
|
|
|
2020-03-19 10:12:38 +11:00
|
|
|
apt install -y \
|
|
|
|
qt512base qt512declarative qt512graphicaleffects \
|
2021-03-01 15:00:04 +11:00
|
|
|
qt512imageformats qt512quickcontrols2 qt512svg \
|
2020-03-16 02:51:30 +11:00
|
|
|
zip git wget cmake ccache \
|
|
|
|
build-essential mesa-common-dev libglu1-mesa-dev freeglut3-dev \
|
2020-05-31 09:39:02 +10:00
|
|
|
libglfw3-dev libgles2-mesa-dev libssl-dev \
|
2020-03-16 02:51:30 +11:00
|
|
|
python3-dev python3-setuptools python3-pip libgdbm-dev libc6-dev \
|
2020-05-31 09:39:02 +10:00
|
|
|
libsqlite3-dev libffi-dev openssl libreadline-dev \
|
2020-07-18 01:18:23 +10:00
|
|
|
libjpeg-turbo8-dev zlib1g-dev \
|
|
|
|
libtiff5-dev liblcms2-dev libwebp-dev libopenjp2-7-dev \
|
2021-03-01 15:00:04 +11:00
|
|
|
libx11-dev libxss-dev libasound2-dev \
|
2021-01-15 21:22:37 +11:00
|
|
|
pkg-config libdbus-1-dev libglib2.0-dev \
|
2021-07-12 02:57:56 +10:00
|
|
|
appstream-util desktop-file-utils # for appimage-lint.sh
|
2020-03-16 02:51:30 +11:00
|
|
|
|
|
|
|
/usr/sbin/update-ccache-symlinks
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
setup_env() {
|
|
|
|
set +euo pipefail
|
|
|
|
# shellcheck disable=SC1091
|
|
|
|
source /opt/qt512/bin/qt512-env.sh
|
|
|
|
set -euo pipefail
|
|
|
|
|
|
|
|
export PATH="/usr/lib/ccache:$PATH"
|
2021-03-13 07:12:13 +11:00
|
|
|
export LD_LIBRARY_PATH="$HOME/.local/lib/python$PY_XY/site-packages/PIL/.libs/:$HOME/.local/lib/python$PY_XY/site-packages/.libs_cffi_backend/:/usr/lib/x86_64-linux-gnu/:/usr/lib:$LD_LIBRARY_PATH"
|
2020-03-16 02:51:30 +11:00
|
|
|
export PREFIX=/usr
|
|
|
|
|
|
|
|
export CFLAGS="-march=x86-64 -O2 -pipe -fPIC"
|
|
|
|
export CXXFLAGS="$CFLAGS"
|
|
|
|
export MAKEFLAGS="-j$(($(nproc) + 1))"
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
install_python() {
|
|
|
|
cd ~
|
|
|
|
|
|
|
|
if ! [ -d ~/.pyenv ]; then
|
|
|
|
wget -O - https://github.com/pyenv/pyenv-installer/raw/master/bin/pyenv-installer | bash
|
|
|
|
fi
|
|
|
|
|
|
|
|
export PATH="$HOME/.pyenv/bin:$PATH"
|
|
|
|
|
|
|
|
set +euo pipefail
|
|
|
|
eval "$(pyenv init -)"
|
|
|
|
eval "$(pyenv virtualenv-init -)"
|
|
|
|
set -euo pipefail
|
|
|
|
|
|
|
|
export PYTHON_CFLAGS="$CFLAGS"
|
|
|
|
export PYTHON_CONFIGURE_OPTS='--enable-shared --enable-optimizations --with-lto'
|
|
|
|
|
|
|
|
pyenv update
|
2021-03-13 07:12:13 +11:00
|
|
|
pyenv install --verbose --skip-existing $PY_XYZ
|
|
|
|
pyenv global $PY_XYZ
|
2020-03-16 02:51:30 +11:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
install_olm() {
|
|
|
|
cd ~
|
|
|
|
|
2021-03-01 21:42:04 +11:00
|
|
|
rm -rf olm-master.tar.gz olm-master
|
|
|
|
wget 'https://gitlab.matrix.org/matrix-org/olm/-/archive/master/olm-master.tar.gz'
|
2020-03-16 02:51:30 +11:00
|
|
|
tar xf olm-master.tar.gz
|
|
|
|
|
|
|
|
cd olm-master
|
2021-03-13 07:12:13 +11:00
|
|
|
make clean
|
2020-03-16 02:51:30 +11:00
|
|
|
cmake . -Bbuild
|
|
|
|
cmake --build build
|
|
|
|
make install
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
install_pyotherside() {
|
|
|
|
cd ~
|
|
|
|
|
|
|
|
if ! [ -f 1.5.9.tar.gz ]; then
|
|
|
|
wget 'https://github.com/thp/pyotherside/archive/1.5.9.tar.gz'
|
|
|
|
fi
|
|
|
|
|
|
|
|
tar xf 1.5.9.tar.gz
|
|
|
|
|
|
|
|
cd pyotherside-1.5.9
|
2021-03-13 07:12:13 +11:00
|
|
|
make clean
|
|
|
|
find . -name Makefile -delete
|
2020-03-16 02:51:30 +11:00
|
|
|
qmake
|
|
|
|
make install
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
get_app_and_pip_dependencies() {
|
|
|
|
cd ~
|
|
|
|
|
|
|
|
if ! [ -d mirage ]; then
|
2020-03-21 05:01:52 +11:00
|
|
|
git clone --recursive "$MIRAGE_REPO_URL"
|
2020-03-16 02:51:30 +11:00
|
|
|
fi
|
|
|
|
|
|
|
|
cd mirage
|
2020-07-18 01:18:23 +10:00
|
|
|
pip3 uninstall Pillow --yes
|
|
|
|
pip3 install Pillow --no-binary :all:
|
2020-03-16 02:51:30 +11:00
|
|
|
pip3 install --user -Ur requirements.txt
|
2020-05-21 13:56:19 +10:00
|
|
|
pip3 install --user -U certifi
|
2020-03-16 02:51:30 +11:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
initialize_appdir() {
|
|
|
|
cd ~/mirage
|
2020-03-24 07:11:06 +11:00
|
|
|
rm -rf .qmake.stash Makefile build
|
|
|
|
|
2020-05-31 08:57:02 +10:00
|
|
|
qmake mirage.pro PREFIX=/usr
|
2020-03-16 02:51:30 +11:00
|
|
|
make install INSTALL_ROOT=build/appdir
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
complete_appdir() {
|
|
|
|
cd ~/mirage/build
|
|
|
|
|
2021-03-13 07:12:13 +11:00
|
|
|
cp -r ~/.pyenv/versions/$PY_XYZ/* appdir/usr
|
|
|
|
cp -r "$HOME/.local/lib/python$PY_XY/site-packages/"* \
|
|
|
|
"appdir/usr/lib/python$PY_XY/site-packages"
|
2020-03-16 02:51:30 +11:00
|
|
|
|
2020-04-03 23:32:26 +11:00
|
|
|
cd ~/mirage/build/appdir/usr/lib
|
2021-03-13 07:12:13 +11:00
|
|
|
ln -s "python$PY_XY/site-packages/Pillow.libs/"* .
|
2020-04-03 23:32:26 +11:00
|
|
|
cd ~/mirage/build
|
|
|
|
|
2020-03-19 10:12:38 +11:00
|
|
|
if ! [ -f ~/linuxdeployqt.AppImage ]; then
|
|
|
|
wget 'https://github.com/probonopd/linuxdeployqt/releases/download/continuous/linuxdeployqt-continuous-x86_64.AppImage' \
|
|
|
|
-O ~/linuxdeployqt.AppImage
|
2020-03-16 02:51:30 +11:00
|
|
|
fi
|
2020-03-19 10:12:38 +11:00
|
|
|
chmod +x ~/linuxdeployqt.AppImage
|
2020-03-16 02:51:30 +11:00
|
|
|
|
2020-03-19 10:12:38 +11:00
|
|
|
~/linuxdeployqt.AppImage appdir/usr/share/applications/mirage.desktop \
|
|
|
|
-bundle-non-qt-libs -qmldir=../src/gui
|
2020-03-16 02:51:30 +11:00
|
|
|
|
2021-07-12 02:57:56 +10:00
|
|
|
mkdir -p appdir/usr/share/metainfo
|
|
|
|
cp ~/mirage/packaging/mirage.appdata.xml appdir/usr/share/metainfo
|
|
|
|
|
2021-03-13 07:12:13 +11:00
|
|
|
cp /opt/qt512/qml/io/thp/pyotherside/qmldir \
|
|
|
|
appdir/usr/qml/io/thp/pyotherside
|
2020-03-16 02:51:30 +11:00
|
|
|
|
|
|
|
# Remove useless heavy test data
|
2021-03-13 07:12:13 +11:00
|
|
|
rm -rf "appdir/usr/lib/python$PY_XY/test"
|
|
|
|
rm -rf "appdir/usr/lib/python$PY_XY/site-packages/Crypto/SelfTest/"
|
2020-03-16 02:51:30 +11:00
|
|
|
|
|
|
|
# Remove python cache files
|
|
|
|
find appdir -name '*.pyc' -delete
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
fix_apprun_launcher() {
|
|
|
|
cd ~/mirage/build/appdir
|
2021-03-13 07:12:13 +11:00
|
|
|
rm -f AppRun # because it's a symlink
|
|
|
|
sed "s/\\\$PY_XY/$PY_XY/" "$HERE/AppRun.sh" > AppRun
|
2020-03-16 02:51:30 +11:00
|
|
|
chmod +x AppRun
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
generate_appimage() {
|
|
|
|
cd ~/mirage/build
|
|
|
|
|
2020-03-19 10:12:38 +11:00
|
|
|
if ! [ -f ~/appimagetool.AppImage ]; then
|
|
|
|
wget "https://github.com/AppImage/AppImageKit/releases/download/continuous/appimagetool-x86_64.AppImage" \
|
|
|
|
-O ~/appimagetool.AppImage
|
|
|
|
fi
|
|
|
|
|
|
|
|
chmod +x ~/appimagetool.AppImage
|
|
|
|
~/appimagetool.AppImage appdir
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
lint_appdir() {
|
|
|
|
cd ~
|
|
|
|
|
|
|
|
cat << 'EOF' > /usr/local/bin/mimetype
|
|
|
|
#!/usr/bin/env sh
|
|
|
|
file --mime-type "$@" | tr -d ';'
|
|
|
|
EOF
|
|
|
|
chmod +x /usr/local/bin/mimetype
|
|
|
|
|
|
|
|
if ! [ -d pkg2appimage ]; then
|
|
|
|
git clone https://github.com/AppImage/pkg2appimage
|
2020-03-16 02:51:30 +11:00
|
|
|
fi
|
2020-03-19 10:12:38 +11:00
|
|
|
chmod +x pkg2appimage/appdir-lint.sh
|
2020-03-16 02:51:30 +11:00
|
|
|
|
2020-03-19 10:12:38 +11:00
|
|
|
cd ~/mirage/build
|
|
|
|
echo -e "\e[34m\nAppDir linting result:\n\e[0m"
|
|
|
|
~/pkg2appimage/appdir-lint.sh appdir
|
2020-03-16 02:51:30 +11:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
check_distro
|
|
|
|
parse_cli_arguments "$@"
|
|
|
|
setup_dns
|
|
|
|
|
|
|
|
if [ "$skip_pre" = false ]; then install_apt_packages; fi
|
|
|
|
|
|
|
|
setup_env
|
|
|
|
|
|
|
|
if [ "$skip_pre" = false ]; then
|
|
|
|
install_python
|
|
|
|
install_olm
|
|
|
|
install_pyotherside
|
|
|
|
get_app_and_pip_dependencies
|
|
|
|
fi
|
|
|
|
|
|
|
|
initialize_appdir
|
|
|
|
complete_appdir
|
|
|
|
fix_apprun_launcher
|
|
|
|
generate_appimage
|
2020-03-19 10:12:38 +11:00
|
|
|
lint_appdir
|