#!/bin/bash # This is MAX update script for Porteus # Version 2026-01-07 # Copyright 2026-2035, Blaze, Dankov, Russia # All rights reserved. # # Redistribution and use of this script, with or without modification, is # permitted provided that the following conditions are met: # # 1. Redistributions of this script must retain the above copyright # notice, this list of conditions and the following disclaimer. # # THIS SOFTWARE IS PROVIDED BY THE AUTHOR "AS IS" AND ANY EXPRESS OR IMPLIED # WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF # MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO # EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, # SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, # PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; # OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, # WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR # OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF # ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. # root check if [ `whoami` != "root" ]; then echo -e "\nYou need to be root to run this script.\n" exit 1 fi PRGNAM=${PRGNAM:-MAX} BUILD=${BUILD:-1} ARCH=$( uname -m ) VERSION=$(lynx --source https://aur.archlinux.org/cgit/aur.git/plain/PKGBUILD?h=max-bin | grep pkgver | cut -d'=' -f2) SOURCE=$(echo https://download.max.ru/electron/MAX.rpm) BOLD=${BOLD:-"\e[1m"} CYAN=${CYAN:-"\e[96m"} GREEN=${GREEN:-"\e[92m"} RED=${RED:-"\e[31m"} RESET=${RESET:-"\e[0m"} CWD=$(pwd) TMPDIR=/tmp/portch PKG=$TMPDIR/package-$PRGNAM PKGINFO=$PKG/var/lib/pkgtools/packages OUTPUT=${OUTPUT:-/tmp} cleanup(){ [ -d $TMPDIR ] && rm -rf $TMPDIR [ -d $PKG ] && rm -rf $PKG exit } # check if MAX installed in the system if [[ -f "/opt/MAX/MAX" ]]; then MYVER=${MYVER:-`basename /var/lib/pkgtools/packages/MAX* | cut -d'-' -f2`} fi if [ "$MYVER" == "$VERSION" ]; then echo -e "You have the latest ${GREEN}$MYVER${RESET} version of $PRGNAM messenger." sleep 5 exit else read -p "$(echo -e Would you like to build $PRGNAM ${GREEN}$VERSION${RESET} xzm module? [y/n])" -n 1 -r -s && echo if [[ $REPLY =~ ^[Yy]$ ]]; then echo "We continue the execution of the $0 script" &>/dev/null else exit fi fi rm -rf $PKG mkdir -p $TMPDIR $PKG/usr/bin cd $PKG # download and extract MAX echo -e "\nDownloading ${CYAN}${BOLD}${PRGNAM}-${VERSION}${RESET}" wget -q --show-progress "$SOURCE" rpm2cpio MAX.rpm | cpio -idmv &>/dev/null rm -f *.rpm $PKG/opt/${PRGNAM}/LICENSE* chown -R root:root . find -L . \ \( -perm 777 -o -perm 775 -o -perm 750 -o -perm 711 -o -perm 555 \ -o -perm 511 \) -exec chmod 755 {} \; -o \ \( -perm 666 -o -perm 664 -o -perm 640 -o -perm 600 -o -perm 444 \ -o -perm 440 -o -perm 400 \) -exec chmod 644 {} \; find $PKG -print0 | xargs -0 file | grep -e "executable" -e "shared object" | grep ELF \ | cut -f 1 -d : | xargs strip --strip-unneeded 2> /dev/null || true ## functions to choose locale from a menu array_menu(){ echo echo "$1" echo "$2" select CHOICE in ${RESULT[@]}; do if [ -z "$CHOICE" ]; then CHOICE="en-US" echo "English locale chosen." && echo else echo -e "${BOLD}${CYAN}${CHOICE}${RESET} locale chosen" fi break done } get_locale(){ # Set locales in array for a in af am ar bg bn ca cs da de el en-GB en-US es-419 es et fa fi fil fr gu he hi hr hu id it ja kn ko lt lv ml mr ms nb nl pl pt-BR pt-PT ro ru sk sl sr sv sw ta te th tr uk ur vi zh-CN zh-TW; do RESULT+=( $a ) done array_menu "Choose a locale from the list." "All other locales will be removed." ${RESULT[@]} unset RESULT } get_locale echo "Removing locales ..." find $PKG/opt/${PRGNAM}/locales/ -maxdepth 1 ! -name 'locales' ! -name 'en-US.pak' | grep -Ev "${CHOICE}".pak | xargs -i rm -rf {} # create a symlink at MAX to usr/bin ln -sf /opt/$PRGNAM/${PRGNAM} $PKG/usr/bin # add Russian description sed -i '/Comment=MAX/a\Comment[ru]=MAX чат клиент для ПК' $PKG/usr/share/applications/MAX.desktop ### fake Slackware type package info: super dumb version mkdir -p $PKGINFO echo "PACKAGE NAME: $PRGNAM-$VERSION-$ARCH" > $PKGINFO/$PRGNAM-$VERSION-$ARCH cat >> $PKGINFO/$PRGNAM-$VERSION-$ARCH << EOM PACKAGE DESCRIPTION: telegram: MAX (messaging app) telegram: telegram: MAX is a cloud-based mobile and desktop messaging app telegram: with a focus on security and speed. telegram: telegram: https://max.ru/ telegram: FILE LIST: EOM find * | grep -v var >> $PKGINFO/$PRGNAM-$VERSION-$ARCH # downloading dependencies libappindicator and libindicator for tray icon support if [[ "$XDG_CURRENT_DESKTOP" == "GNOME" || "$XDG_CURRENT_DESKTOP" == "KDE" || "$XDG_CURRENT_DESKTOP" == "LXQt" ]]; then echo -e "\nDownloading dependencies for ${BOLD}$PRGNAM-$VERSION-$ARCH${RESET}" rm -f ${OUTPUT}/*.txz XZM=no getpkg -q libappindicator libindicator for i in $(find ${OUTPUT} -type f | grep ".txz" | sort); do ROOT=$PKG installpkg $i >/dev/null; done rm -rf ${OUTPUT}/*.txz # clean unusful stuff rm -rf $PKG/usr/{doc,man,include,info,src} rm -rf $PKG/usr/lib{,64}/{cmake,girepository-1.0,pkgconfig} rm -rf $PKG/usr/lib{,64}/python*/site-packages/*.egg-info rm -rf $PKG/usr/share/{doc,gir-1.0,gtk-doc,help,licenses,man,pkgconfig} rm -rf $PKG/var/lib/pkgtools/douninst.sh rm -f $PKG/var/log/scripts/* rm -f $PKG/{,usr/}lib{,64}/*.la find $PKG -type f -name "*.la" -delete find $PKG -type f -name "*.a" -delete find $PKG -type f -name "*.h" -delete find $PKG -type f -iname "README" -delete find $PKG -type f -iname "README*.txt" -delete find $PKG -type f -iname "LICENSE*.txt" -delete fi dir2xzm $PKG $OUTPUT/$PRGNAM-$VERSION-$ARCH-$BUILD.xzm # check on MAX xzm file exists in /tmp if [ -f "$OUTPUT/${PRGNAM}-${VERSION}-${ARCH}-${BUILD}.xzm" ]; then echo -e "\n${BOLD}Your $PRGNAM module is at: ${GREEN}${BOLD}$OUTPUT/$PRGNAM-$VERSION-${ARCH}-${BUILD}.xzm${RESET}\n${BOLD}Please copy it to your modules folder to survive a reboot.${RESET}\n" else echo -e "\n${RED}${BOLD}Faile. Your $PRGNAM module is not built.${RESET}\n" fi cleanup