Skip to content

Instantly share code, notes, and snippets.

@drzhnn
Last active May 21, 2022 11:41
Show Gist options
  • Save drzhnn/02ae663ea78c6799f330063a95b29612 to your computer and use it in GitHub Desktop.
Save drzhnn/02ae663ea78c6799f330063a95b29612 to your computer and use it in GitHub Desktop.
Extract Bitwig Studio flatpak installer and copy all the files to the right places #bitwig #linux #fedora
#!/bin/bash
# Usage: sudo install_unflatpaked_bitwig.sh ["Bitwig Studio <version>.flatpak"]
# Check if running the script as root.
if [ "$EUID" -ne 0 ]; then
echo "Please run as root"
exit 0
fi
# Check if Bitwig Studio app is currently running.
if pgrep -x "bitwig-studio" > /dev/null; then
echo "Close Bitwig Studio before running this script"
exit 0
fi
TEMP_DIR=$(mktemp -dp .)
REPO=$(basename $TEMP_DIR)
UNFLATED=$REPO/unflated
SHARE_DEST=~/.local/share/
FILES_DEST=/opt
echo "Initializing a new empty repository"
ostree init --repo="$REPO" --mode=bare-user
errors=$?
echo "Applying static delta file"
ostree static-delta apply-offline --repo="$REPO" "$1"
errors+=$?
echo "Checking out a commit into a filesystem tree"
ostree checkout --repo="$REPO" \
-U $(basename $(echo $REPO/objects/*/*.commit |
cut --delimiter='/' --fields='3-' --output-delimiter='' |
tr -d '\0') .commit) $UNFLATED
errors+=$?
if [ $errors -ne 0 ]; then
echo "Unpacking finished with errors" >&2
echo "Removing temporary files..."
rm -rf $TEMP_DIR
exit 1
fi
# Exit immediately if a command exits with a non-zero status.
# Change to 'set -ex' for debugging.
set -e
echo "Setting modification date for extracted files"
# otherwise module icons won't show up in the Grid.
find "$UNFLATED" -print | while read filename; do
touch -m "$filename"
done
echo "Checking extracted folder structure"
if [ ! -d $UNFLATED/export/share ] && [ ! -f $UNFLATED/files/bitwig-studio ]; then
echo "Folder structure of the extracted flatpak is unknown"
echo "Update the script"
exit 1
fi
echo "Updating Bitwig Studio .desktop file to force it run under X11"
# otherwise the startup splash screen won't show up if run under Wayland.
sed -i -e 's/Exec=bitwig-studio/Exec=env GDK_BACKEND=x11 bitwig-studio/g' \
"$UNFLATED/export/share/applications/com.bitwig.BitwigStudio.desktop"
echo "Installing icons and .desktop file"
cp -r "$UNFLATED/export/share/applications" $SHARE_DEST
cp -r "$UNFLATED/export/share/icons" $SHARE_DEST
cp -r "$UNFLATED/export/share/mime" $SHARE_DEST
if [ -d $FILES_DEST/bitwig-studio ]; then
echo "Renaming previous Bitwig Studio installation folder"
sudo mv "$FILES_DEST/bitwig-studio" "$FILES_DEST/bitwig-studio-old"
fi
echo "Installing Bitwig Studio program files"
mkdir -p "$FILES_DEST/bitwig-studio"
sudo mv "$UNFLATED"/files/* "$FILES_DEST/bitwig-studio"
sudo chown -R root:root "$FILES_DEST/bitwig-studio"
echo "Creating symlink for bitwig-studio"
ln -sf "$FILES_DEST/bitwig-studio/bitwig-studio" /bin/
echo "Removing temporary files"
rm -rf "$TEMP_DIR"
echo "Removing old Bitwig Studio version"
sudo rm -rf $FILES_DEST/bitwig-studio-old
echo "Installation complete!"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment