Skip to content

Instantly share code, notes, and snippets.

@lyshie
Last active November 17, 2023 00:06
Show Gist options
  • Star 36 You must be signed in to star a gist
  • Fork 14 You must be signed in to fork a gist
  • Save lyshie/0c49393076b8b375ca1bd98c28f95fb0 to your computer and use it in GitHub Desktop.
Save lyshie/0c49393076b8b375ca1bd98c28f95fb0 to your computer and use it in GitHub Desktop.
Scratch Desktop (Scratch 3.0 Offline Editor) on GNU/Linux
{
"src": "/tmp/scratch-desktop/",
"dest": "/tmp/",
"arch": "i386",
"icon": "/tmp/scratch-desktop/resources/Icon.png",
"categories": [
"Education"
]
}
{
"src": "/tmp/scratch-desktop/",
"dest": "/tmp/",
"arch": "amd64",
"icon": "/tmp/scratch-desktop/resources/Icon.png",
"categories": [
"Education"
]
}
{
"src": "/tmp/scratch-desktop/",
"dest": "/tmp/",
"arch": "x86_64",
"icon": "/tmp/scratch-desktop/resources/Icon.png",
"categories": [
"Education"
]
}
#!/bin/sh
######## install electron
sudo apt-get install -yq npm gdebi p7zip-full
cd ~
npm install electron --save-dev
######## extract scratch-desktop
rm -rf /tmp/scratch-desktop
mkdir /tmp/scratch-desktop
wget --max-redirect 5 -c -O /tmp/scratch-desktop.exe 'https://downloads.scratch.mit.edu/desktop/Scratch%20Setup.exe'
7za x -aoa -y /tmp/scratch-desktop.exe -o/tmp/scratch-desktop
######## create electron app
cp -rf ~/node_modules/electron/dist/* /tmp/scratch-desktop/
ln -fsr /tmp/scratch-desktop/electron /tmp/scratch-desktop/scratch-desktop
######## fix permissions
chmod 755 /tmp/scratch-desktop/locales
chmod 755 /tmp/scratch-desktop/swiftshader
chmod 755 /tmp/scratch-desktop/resources
chmod 755 /tmp/scratch-desktop/resources/static
chmod 755 /tmp/scratch-desktop/resources/static/assets
######## get application icon
wget -c -O /tmp/scratch-desktop/resources/Icon.png 'https://scratch.mit.edu/images/download/icon.png'
######## create deb package
cd ~
npm install electron-installer-debian@2.0.1
wget -c -O /tmp/config-deb-i386.json 'https://gist.githubusercontent.com/lyshie/0c49393076b8b375ca1bd98c28f95fb0/raw/9c08b1390cef3df4a0c1622b26875450adb108cd/config-deb-i386.json'
~/node_modules/.bin/electron-installer-debian --config /tmp/config-deb-i386.json
######## install deb file
sudo gdebi /tmp/scratch-desktop_3.12.0_i386.deb
#!/bin/sh
######## install electron
sudo apt-get install -yq npm gdebi p7zip-full
cd ~
## https://github.com/electron/electron/releases/download/v4.2.5/electron-v4.2.5-linux-arm64.zip
## https://github.com/electron/electron/releases/download/v4.2.5/electron-v4.2.5-linux-armv7l.zip
npm install electron --save-dev
######## extract scratch-desktop
rm -rf /tmp/scratch-desktop
mkdir /tmp/scratch-desktop
wget --max-redirect 5 -c -O /tmp/scratch-desktop.exe 'https://downloads.scratch.mit.edu/desktop/Scratch%20Setup.exe'
7za x -aoa -y /tmp/scratch-desktop.exe -o/tmp/scratch-desktop
######## create electron app
cp -rf ~/node_modules/electron/dist/* /tmp/scratch-desktop/
ln -fsr /tmp/scratch-desktop/electron /tmp/scratch-desktop/scratch-desktop
######## fix permissions
chmod 755 /tmp/scratch-desktop/locales
chmod 755 /tmp/scratch-desktop/swiftshader
chmod 755 /tmp/scratch-desktop/resources
chmod 755 /tmp/scratch-desktop/resources/static
chmod 755 /tmp/scratch-desktop/resources/static/assets
######## get application icon
wget -c -O /tmp/scratch-desktop/resources/Icon.png 'https://scratch.mit.edu/images/download/icon.png'
######## create deb package
cd ~
npm install electron-installer-debian
wget -c -O /tmp/config-deb.json 'https://gist.githubusercontent.com/lyshie/0c49393076b8b375ca1bd98c28f95fb0/raw/223cc112d99c3bdc1829fc25b19c260856134a82/config-deb.json'
~/node_modules/.bin/electron-installer-debian --config /tmp/config-deb.json
######## install deb file
sudo gdebi /tmp/scratch-desktop_3.12.0_amd64.deb
#!/bin/sh
######## install electron
sudo apt-get install -yq npm gdebi p7zip-full
cd ~
npm install electron --save-dev
######## extract scratch-desktop
rm -rf /tmp/scratch-desktop
mkdir /tmp/scratch-desktop
wget --max-redirect 5 -c -O /tmp/scratch-desktop.exe 'https://downloads.scratch.mit.edu/desktop/Scratch%20Setup.exe'
7za x -aoa -y /tmp/scratch-desktop.exe -o/tmp/scratch-desktop
######## create electron app
cp -rf ~/node_modules/electron/dist/* /tmp/scratch-desktop/
ln -fsr /tmp/scratch-desktop/electron /tmp/scratch-desktop/scratch-desktop
######## fix permissions
chmod 755 /tmp/scratch-desktop/locales
chmod 755 /tmp/scratch-desktop/swiftshader
chmod 755 /tmp/scratch-desktop/resources
chmod 755 /tmp/scratch-desktop/resources/static
chmod 755 /tmp/scratch-desktop/resources/static/assets
######## get application icon
wget -c -O /tmp/scratch-desktop/resources/Icon.png 'https://scratch.mit.edu/images/download/icon.png'
######## create deb package
cd ~
npm install electron-installer-debian
wget -c -O /tmp/config-deb.json 'https://gist.githubusercontent.com/lyshie/0c49393076b8b375ca1bd98c28f95fb0/raw/223cc112d99c3bdc1829fc25b19c260856134a82/config-deb.json'
~/node_modules/.bin/electron-installer-debian --config /tmp/config-deb.json
######## install deb file
sudo gdebi /tmp/scratch-desktop_3.12.0_amd64.deb
#!/bin/sh
######## install electron
cd ~
#npm install electron@4.1.4 --save-dev
npm install electron --save-dev
######## extract scratch-desktop
rm -rf /tmp/scratch-desktop
mkdir /tmp/scratch-desktop
wget --max-redirect 5 -c -O /tmp/scratch-desktop.exe 'https://downloads.scratch.mit.edu/desktop/Scratch%20Setup.exe'
7za x -aoa -y /tmp/scratch-desktop.exe -o/tmp/scratch-desktop
######## create electron app
cp -rf ~/node_modules/electron/dist/* /tmp/scratch-desktop/
ln -fsr /tmp/scratch-desktop/electron /tmp/scratch-desktop/scratch-desktop
######## fix permissions
chmod 755 /tmp/scratch-desktop/locales
chmod 755 /tmp/scratch-desktop/swiftshader
chmod 755 /tmp/scratch-desktop/resources
chmod 755 /tmp/scratch-desktop/resources/static
chmod 755 /tmp/scratch-desktop/resources/static/assets
######## get application icon
wget -c -O /tmp/scratch-desktop/resources/Icon.png 'https://scratch.mit.edu/images/download/icon.png'
######## create rpm package
sudo dnf install rpm-build
cd ~
npm install electron-installer-redhat
wget -c -O /tmp/config-rpm.json 'https://gist.githubusercontent.com/lyshie/0c49393076b8b375ca1bd98c28f95fb0/raw/223cc112d99c3bdc1829fc25b19c260856134a82/config-rpm.json'
~/node_modules/.bin/electron-installer-redhat --config /tmp/config-rpm.json

Scratch Desktop (Scratch 3.0 Offline Editor) on GNU/Linux

Install electron

$ cd ~
$ npm install electron --save-dev
$ ls ~/node_modules/electron/dist

Extract scratch-desktop

$ rm -rf /tmp/scratch-desktop
$ mkdir /tmp/scratch-desktop
$ wget --max-redirect 5 -c -O /tmp/scratch-desktop.exe 'https://downloads.scratch.mit.edu/desktop/Scratch%20Setup.exe'
$ 7za x -aoa -y /tmp/scratch-desktop.exe -o/tmp/scratch-desktop

Create and launch electron app

$ cp -rf ~/node_modules/electron/dist/* /tmp/scratch-desktop/
$ ln -fsr /tmp/scratch-desktop/electron /tmp/scratch-desktop/scratch-desktop
$ /tmp/scratch-desktop/scratch-desktop

Fix permissions

$ chmod 755 /tmp/scratch-desktop/locales
$ chmod 755 /tmp/scratch-desktop/swiftshader
$ chmod 755 /tmp/scratch-desktop/resources
$ chmod 755 /tmp/scratch-desktop/resources/static
$ chmod 755 /tmp/scratch-desktop/resources/static/assets

Inside the app.asar

$ cd /tmp/scratch-desktop/resources/
$ ~/node_modules/.bin/asar extract app.asar app
$ cat app/package.json

Create RPM package

$ sudo dnf install rpm-build
$ cd ~
$ npm install electron-installer-redhat

$ chmod 755 /tmp/scratch-desktop/locales
$ chmod 755 /tmp/scratch-desktop/swiftshader
$ chmod 755 /tmp/scratch-desktop/resources
$ chmod 755 /tmp/scratch-desktop/resources/static
$ chmod 755 /tmp/scratch-desktop/resources/static/assets
$ ~/node_modules/.bin/electron-installer-redhat /tmp/config-rpm.json

OR

$ ~/node_modules/.bin/electron-installer-redhat --src /tmp/scratch-desktop/ --dest /tmp/ --arch x86_64
$ sudo dnf install /tmp/scratch-desktop-3.10.2-1.x86_64.rpm

Create DEB package

$ sudo apt-get install -yq npm gdebi p7zip-full
$ ls /tmp
create-deb.sh   config-deb.json

$ sh /tmp/create-deb.sh
$ sudo gdebi /tmp/scratch-desktop_3.10.2_amd64.deb
@shaileshparanjpe
Copy link

I am trying to install .deb package on Ubuntu 22.04. I could successfully get upto cd /tmp/scratch-desktop/resources/ command.
However, when I try the next command i.e. ~/node_modules/.bin/asar extract app.asar app, I get /home/user/node_modules/.bin/asar: No such file or directory.
Please help.

@OMA2k
Copy link

OMA2k commented Mar 6, 2023

@shaileshparanjpe : To avoid that problem just install asar with:
npm install @electron/asar

Anyway, if you're using Ubuntu, instead of pasting all those lines, the only thing you need to do is this:

wget https://gist.githubusercontent.com/lyshie/0c49393076b8b375ca1bd98c28f95fb0/raw/e6bca7386ac58a99ce8de07489481a2e579b170f/create-deb.sh
chmod +x create-deb.sh
,/create-deb.sh

That's it.

If you're using a Raspberry Pi 4 with Ubuntu, you should change the architecture to arm64 (or armhf if you're running on 32-bit) in the config-deb.json file (you'll have to download it manually, edit it, then remove the "wget -c -O /tmp/config-rpm.json ..." line from the create-deb.sh file to avoid overwriting your arch modification). But this version of Scratch won't have access to the GPIO and SenseHat extensions for the Raspberry Pi, sadly, since those extensions are exclusive to the special version of Scratch Desktop that comes with the official Raspberry Pi OS.

Thank you for your job, @lyshie !!

@kurotori
Copy link

Thank you for this tutorial, is really helpful. Keep up with the good work.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment