From 0bafbe23a6312128f421c9c7b1f9aed7a3034d84 Mon Sep 17 00:00:00 2001 From: Andrey Onishchenko Date: Thu, 15 Feb 2024 16:39:22 +0300 Subject: [PATCH] Refactoring of build_deb.sh Braces fix --- build_deb.sh | 182 ++++++++++++++++++--------------------------------- 1 file changed, 64 insertions(+), 118 deletions(-) diff --git a/build_deb.sh b/build_deb.sh index ad15f06..daa5650 100755 --- a/build_deb.sh +++ b/build_deb.sh @@ -10,26 +10,56 @@ usage() { echo " -h Show this help and exit" } -x64=1 +download_electron_binary(){ + arch=${1} + echo "Downloading electron ${arch}" + curl -L -o "${TEMPDIR}/electron-${arch}.zip" "https://github.com/electron/electron/releases/download/v27.3.0/electron-v27.3.0-linux-${arch}.zip" + unzip -q "${TEMPDIR}/electron-${arch}.zip" -d "${TEMPDIR}/electron-${arch}" +} + +build_deb(){ + arch=${1} + pkgarch=${2} + + echo "Building ${arch} package" + pkgdir="${TEMPDIR}/yandex-music-${arch}" + + mkdir -p "${pkgdir}/DEBIAN" + cp "./templates/control" "${pkgdir}/DEBIAN/control" + sed -i "s/%version%/${version}/g" "${pkgdir}/DEBIAN/control" + sed -i "s/%arch%/${pkgarch}/g" "${pkgdir}/DEBIAN/control" + + mkdir -p "${pkgdir}/usr/lib/yandex-music" + mkdir -p "${pkgdir}/usr/share/applications" + mkdir -p "${pkgdir}/usr/share/licenses/yandex-music" + mkdir -p "${pkgdir}/usr/share/pixmaps" + mkdir -p "${pkgdir}/usr/bin" + + install -Dm644 "${TEMPDIR}/app/yandex-music.asar" "${pkgdir}/usr/lib/yandex-music/yandex-music.asar" + install -Dm644 "${TEMPDIR}/app/favicon.png" "${pkgdir}/usr/share/pixmaps/yandex-music.png" + install -Dm644 "./templates/desktop" "${pkgdir}/usr/share/applications/yandex-music.desktop" + install -Dm644 "./LICENSE.md" "${pkgdir}/usr/share/licenses/yandex-music/LICENSE" + mv "${TEMPDIR}/electron-${arch}/" "${pkgdir}/usr/lib/yandex-music/electron" + + echo "#!/bin/sh" > "${pkgdir}/usr/bin/yandex-music" + echo 'exec /usr/lib/yandex-music/electron/electron /usr/lib/yandex-music/yandex-music.asar "$@"' >> "${pkgdir}/usr/bin/yandex-music" + chmod 755 "${pkgdir}/usr/bin/yandex-music" + + dpkg-deb --build "${pkgdir}" "deb/yandex-music_${version}_${pkgarch}.deb" +} + +x64=0 armv7l=0 arm64=0 #checking for arch option (if not specified set x64) and h option while getopts :a:h name; do - case $name in + case ${name} in a) - case $OPTARG in - x64) - x64=1 - ;; - armv7l) - armv7l=1 - x64=0 - ;; - arm64) - arm64=1 - x64=0 - ;; + case ${OPTARG} in + x64) x64=1 ;; + armv7l) armv7l=1 ;; + arm64) arm64=1 ;; all) x64=1 armv7l=1 @@ -53,8 +83,13 @@ while getopts :a:h name; do esac done +#checking if at least one arch is specified else set x64 +if [ ${x64} -eq 0 ] && [ ${armv7l} -eq 0 ] && [ ${arm64} -eq 0 ]; then + x64=1 +fi + clear() { - rm -rf "$TEMPDIR" + rm -rf "${TEMPDIR}" } TEMPDIR="$(mktemp -d)" trap clear EXIT @@ -66,118 +101,29 @@ exe_link=$(jq -r '.exe_link' ./utility/version_info.json) exe_sha256=$(jq -r '.exe_sha256' ./utility/version_info.json) #downloading exe -echo "Downloading $exe_name" -curl -L -o "$TEMPDIR/$exe_name" "$exe_link" +echo "Downloading ${exe_name}" +curl -L -o "${TEMPDIR}/${exe_name}" "${exe_link}" #checking sha256 echo "Checking sha256" -echo "$exe_sha256 $TEMPDIR/$exe_name" | sha256sum -c +echo "${exe_sha256} ${TEMPDIR}/${exe_name}" | sha256sum -c -echo "Repaking $exe_name" -sh repack.sh -o "$TEMPDIR/app" "$TEMPDIR/$exe_name" - -#downloading electron binaries -if [ $x64 -eq 1 ]; then - echo "Downloading electron x64" - curl -L -o "$TEMPDIR/electron-x64.zip" "https://github.com/electron/electron/releases/download/v27.3.0/electron-v27.3.0-linux-x64.zip" - unzip -q "$TEMPDIR/electron-x64.zip" -d "$TEMPDIR/electron-x64" -fi - -if [ $armv7l -eq 1 ]; then - echo "Downloading electron armv7l" - curl -L -o "$TEMPDIR/electron-armv7l.zip" "https://github.com/electron/electron/releases/download/v27.3.0/electron-v27.3.0-linux-armv7l.zip" - unzip -q "$TEMPDIR/electron-armv7l.zip" -d "$TEMPDIR/electron-armv7l" -fi - -if [ $arm64 -eq 1 ]; then - echo "Downloading electron arm64" - curl -L -o "$TEMPDIR/electron-arm64.zip" "https://github.com/electron/electron/releases/download/v27.3.0/electron-v27.3.0-linux-arm64.zip" - unzip -q "$TEMPDIR/electron-arm64.zip" -d "$TEMPDIR/electron-arm64" -fi +echo "Repaking ${exe_name}" +sh repack.sh -o "${TEMPDIR}/app" "${TEMPDIR}/${exe_name}" mkdir -p "deb" -#bulding packages -if [ $x64 -eq 1 ]; then - echo "Building x64 package" - pkgdir="$TEMPDIR/yandex-music-x64" - - mkdir -p "$pkgdir/DEBIAN" - cp "./templates/control" "$pkgdir/DEBIAN/control" - sed -i "s/%version%/$version/g" "$pkgdir/DEBIAN/control" - sed -i "s/%arch%/amd64/g" "$pkgdir/DEBIAN/control" - - mkdir -p "$pkgdir/usr/lib/yandex-music" - mkdir -p "$pkgdir/usr/share/applications" - mkdir -p "$pkgdir/usr/share/licenses/yandex-music" - mkdir -p "$pkgdir/usr/share/pixmaps" - mkdir -p "$pkgdir/usr/bin" - - install -Dm644 "$TEMPDIR/app/yandex-music.asar" "$pkgdir/usr/lib/yandex-music/yandex-music.asar" - install -Dm644 "$TEMPDIR/app/favicon.png" "$pkgdir/usr/share/pixmaps/yandex-music.png" - install -Dm644 "./templates/desktop" "$pkgdir/usr/share/applications/yandex-music.desktop" - install -Dm644 "./LICENSE.md" "$pkgdir/usr/share/licenses/yandex-music/LICENSE" - mv "$TEMPDIR/electron-x64/" "$pkgdir/usr/lib/yandex-music/electron" - - echo "#!/bin/sh" > "$pkgdir/usr/bin/yandex-music" - echo 'exec /usr/lib/yandex-music/electron/electron /usr/lib/yandex-music/yandex-music.asar "$@"' >> "$pkgdir/usr/bin/yandex-music" - chmod 755 "$pkgdir/usr/bin/yandex-music" - - dpkg-deb --build "$pkgdir" "deb/yandex-music_${version}_amd64.deb" +if [ ${x64} -eq 1 ]; then + download_electron_binary "x64" + build_deb "x64" "amd64" fi -if [ $armv7l -eq 1 ]; then - echo "Building armv7l package" - pkgdir="$TEMPDIR/yandex-music-armv7l" - - mkdir -p "$pkgdir/DEBIAN" - cp "./templates/control" "$pkgdir/DEBIAN/control" - sed -i "s/%version%/$version/g" "$pkgdir/DEBIAN/control" - sed -i "s/%arch%/armhf/g" "$pkgdir/DEBIAN/control" - - mkdir -p "$pkgdir/usr/lib/yandex-music" - mkdir -p "$pkgdir/usr/share/applications" - mkdir -p "$pkgdir/usr/share/licenses/yandex-music" - mkdir -p "$pkgdir/usr/share/pixmaps" - mkdir -p "$pkgdir/usr/bin" - - install -Dm644 "$TEMPDIR/app/yandex-music.asar" "$pkgdir/usr/lib/yandex-music/yandex-music.asar" - install -Dm644 "$TEMPDIR/app/favicon.png" "$pkgdir/usr/share/pixmaps/yandex-music.png" - install -Dm644 "./templates/desktop" "$pkgdir/usr/share/applications/yandex-music.desktop" - install -Dm644 "./LICENSE.md" "$pkgdir/usr/share/licenses/yandex-music/LICENSE" - mv "$TEMPDIR/electron-armv7l/" "$pkgdir/usr/lib/yandex-music/electron" - - echo "#!/bin/sh" > "$pkgdir/usr/bin/yandex-music" - echo 'exec /usr/lib/yandex-music/electron/electron /usr/lib/yandex-music/yandex-music.asar "$@"' >> "$pkgdir/usr/bin/yandex-music" - chmod 755 "$pkgdir/usr/bin/yandex-music" - - dpkg-deb --build "$pkgdir" "deb/yandex-music_${version}_armhf.deb" +if [ ${armv7l} -eq 1 ]; then + download_electron_binary "armv7l" + build_deb "armv7l" "armhf" fi -if [ $arm64 -eq 1 ]; then - echo "Building arm64 package" - pkgdir="$TEMPDIR/yandex-music-arm64" - - mkdir -p "$pkgdir/DEBIAN" - cp "./templates/control" "$pkgdir/DEBIAN/control" - sed -i "s/%version%/$version/g" "$pkgdir/DEBIAN/control" - sed -i "s/%arch%/arm64/g" "$pkgdir/DEBIAN/control" - - mkdir -p "$pkgdir/usr/lib/yandex-music" - mkdir -p "$pkgdir/usr/share/applications" - mkdir -p "$pkgdir/usr/share/licenses/yandex-music" - mkdir -p "$pkgdir/usr/share/pixmaps" - mkdir -p "$pkgdir/usr/bin" - - install -Dm644 "$TEMPDIR/app/yandex-music.asar" "$pkgdir/usr/lib/yandex-music/yandex-music.asar" - install -Dm644 "$TEMPDIR/app/favicon.png" "$pkgdir/usr/share/pixmaps/yandex-music.png" - install -Dm644 "./templates/desktop" "$pkgdir/usr/share/applications/yandex-music.desktop" - install -Dm644 "./LICENSE.md" "$pkgdir/usr/share/licenses/yandex-music/LICENSE" - mv "$TEMPDIR/electron-arm64/" "$pkgdir/usr/lib/yandex-music/electron" - - echo "#!/bin/sh" > "$pkgdir/usr/bin/yandex-music" - echo 'exec /usr/lib/yandex-music/electron/electron /usr/lib/yandex-music/yandex-music.asar "$@"' >> "$pkgdir/usr/bin/yandex-music" - chmod 755 "$pkgdir/usr/bin/yandex-music" - - dpkg-deb --build "$pkgdir" "deb/yandex-music_${version}_arm64.deb" +if [ ${arm64} -eq 1 ]; then + download_electron_binary "arm64" + build_deb "arm64" "arm64" fi \ No newline at end of file