Skip to content

Instantly share code, notes, and snippets.

@lyshie
Last active October 10, 2024 18:46
Show Gist options
  • 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
@omartek
Copy link

omartek commented Jul 25, 2019

I've made .deb for raspberryPI 3. Great, it works! I had to change config-deb.json of course ("arch": "armhf").
bit.ly/scratch30armhf
Thanks a lot.

@Farshidmi
Copy link

Hi ,
Can I use this for i386 (32 bit) Linux Mint ? Which command must be changed?
because I have an old PC :)

Regards

@lyshie
Copy link
Author

lyshie commented Sep 11, 2019

Hi ,
Can I use this for i386 (32 bit) Linux Mint ? Which command must be changed?
because I have an old PC :)

Regards

@Farshidmi
I add a script create-deb-i386.sh to create i386 DEB package.
Here is the screenshot of Linux Mint 19.1 (i686).
Scratch Desktop

@Farshidmi
Copy link

Hi ,
Can I use this for i386 (32 bit) Linux Mint ? Which command must be changed?
because I have an old PC :)
Regards

@Farshidmi
I add a script create-deb-i386.sh to create i386 DEB package.
Here is the screenshot of Linux Mint 19.1 (i686).
Scratch Desktop

Thanks . It works :-)
I think url for json is incorrect.
Best

@lumanga
Copy link

lumanga commented Oct 5, 2019

@lyshie
Dear lyshie, thanks again for your job!
Linux Mint 19.2 MATE 64bit, .DEB created with success. I can install the Scratch program but the ICON to launch Scratch in MENU/EDUCATIONA section (or in other part of menu) IS NOT PRESENT!
My Mint is in ITALIAN LANGUAGE and the EDUCATION in reality, is "ISTRUZIONE" called. Have I to change the " config-deb.json " file

@Lewiscowles1986
Copy link

  • Not all dependencies are documented (asar).
  • Some of the steps are duplicated in the shell scripts.
  • It may build an amd64 (not i386) version on 64-bit computers, same with ARM.

While admirable, I think this might need some work

apt install -yq will silence output and answer yes to questions

All my built packages turned out to be the same size (which is why I'm sure it's not built real i386 or armv7l)

All this said, I was able to alter a few instructions to get this to build for several machines, so thank you.

There must be a better way? I'll follow the instructions again on an i386 vm and a raspberry pi so that I can keep a local repo for my local LUG which runs coder dojo like events

@efa
Copy link

efa commented Dec 27, 2019

the last step for 64bit deb create a file named:
/tmp/scratch-desktop_1.2.1_amd64.deb
instead of
/tmp/scratch-desktop_3.6.0_amd64.deb

@efa
Copy link

efa commented Dec 28, 2019

the command:
npm install electron@4.1.4 --save-dev
show the following WARN:
npm WARN enoent ENOENT: no such file or directory, open '/home/efa/package.json'
npm WARN efa No description
npm WARN efa No repository field.
npm WARN efa No README data
npm WARN efa No license field.
hope do not impact on functionality

@efa
Copy link

efa commented Dec 28, 2019

I have two PC, both with 4 GB of RAM and a 64 bit OS. One has Ubuntu 18.04 and the other has a Debian 9.
On Debian start and work well, on Ubuntu I got the cyan windows with Starting Scratch, then it become a white window forever, and on the console I got an OOM error:
`
efa@02cor2130:~$ scratch-desktop

[8118:1228/163027.861206:FATAL:memory_linux.cc(36)] Out of memory.
`
I think the free memory is enought:
efa@02cor2130:~/dLoad/scratch$ cat /proc/meminfo | grep ^Me
MemTotal: 3839840 kB
MemFree: 1671344 kB
MemAvailable: 2361824 kB
How much is the needed memory by Scratch 3.6 ?

@efa
Copy link

efa commented Dec 30, 2019

solved, it was the overcommit. Probably Scratch 3.6 is one of the bad application that try to allocate much more memory that it use. If the overcommit is enabled it work, if overcommit is disabled for predictability it fail with OOM. Scratch 1.4 was not that bad and run also with overcommit disabled

@Lewiscowles1986
Copy link

Loading a saved scratch workspace seems to lock the UI

@lyshie
Copy link
Author

lyshie commented Mar 17, 2020

Screenshot_20200317_221006

@Lewiscowles1986
Copy link

Hi @lyshie, I'm unsure what that is supposed to show. Of course the file picker works, it's the loading, after accepting which I notice is blank here

I can try a new build this week, see if that fixes

@Razzo1987
Copy link

There is an error in the scratch-desktop.md
when you wrote ./scratch-desktop/scratch-desktop i think it is /tmp/scratch-desktop/scratch-desktop

@lyshie
Copy link
Author

lyshie commented May 3, 2020

There is an error in the scratch-desktop.md
when you wrote ./scratch-desktop/scratch-desktop i think it is /tmp/scratch-desktop/scratch-desktop

Thanks for your advice.

@lesar
Copy link

lesar commented Jun 15, 2020

SOLVED

Mine arch is:
uname -m

aarch64

and I have some problem installing it (scratch)

I put aarch64 in /tmp/config-deb.json then make the package and no errors are show.

but when I try to install:

Wrong architecture 'aarch64' -- Run dpkg --add-architecture to add it and update afterwards

so I do:
sudo dpkg --add-architecture aarch64

and it show an error

pkg-config-dpkghook: Avviso: Architecture aarch64 not defined in architecture tables, ignored

can anyone help me?
best regards.
P.S. sudo dpkg --add-architecture aarch64 is a bad idea: I remove it

I solved by myself.
I put in /tmp/config-deb.json arm64 instead aarch64
remove all file build on previous try
download the last exe
and all go right

@HackEduca
Copy link

Hello, I am receiving the following error:

Creating package (this may take a while) { [Error: ENOENT: no such file or directory, open '/tmp/scratch-desktop/version'] errno: -2, code: 'ENOENT', syscall: 'open', path: '/tmp/scratch-desktop/version' } 'Error: ENOENT: no such file or directory, open '/tmp/scratch-desktop/version'' gdebi error, file not found: /tmp/scratch-desktop_3.12.0_amd64.deb

Appreciate any help on this regards.

xxx-VirtualBox:~$ uname -a Linux sobreira-VirtualBox 5.4.0-47-generic #51-Ubuntu SMP Fri Sep 4 19:50:52 UTC 2020 x86_64 x86_64 x86_64 GNU/Linux

Thanks!

@Mobslayer92
Copy link

Mobslayer92 commented Oct 7, 2020

When running "/tmp/scratch-desktop/scratch-desktop" I get the following error: [17853:1007/172314.266423:FATAL:setuid_sandbox_host.cc(158)] The SUID sandbox helper binary was found, but is not configured correctly. Rather than run without sandboxing I'm aborting now. You need to make sure that /tmp/scratch-desktop/chrome-sandbox is owned by root and has mode 4755.
Trace/breakpoint trap

Edit
Worked when I used the create-deb-1386 after changing "sudo gdebi /tmp/scratch-desktop_3.12.0_i386.deb" with "sudo gdebi /tmp/scratch-desktop_3.15.0_i386.deb

@Farshidmi
Copy link

Hello, I am receiving the following error:

Creating package (this may take a while) { [Error: ENOENT: no such file or directory, open '/tmp/scratch-desktop/version'] errno: -2, code: 'ENOENT', syscall: 'open', path: '/tmp/scratch-desktop/version' } 'Error: ENOENT: no such file or directory, open '/tmp/scratch-desktop/version'' gdebi error, file not found: /tmp/scratch-desktop_3.12.0_amd64.deb

Appreciate any help on this regards.

xxx-VirtualBox:~$ uname -a Linux sobreira-VirtualBox 5.4.0-47-generic #51-Ubuntu SMP Fri Sep 4 19:50:52 UTC 2020 x86_64 x86_64 x86_64 GNU/Linux

Thanks!

Hi
I have same problem.

@real-nickel
Copy link

For the file create-deb-raspbian.sh, it should have the line 'sudo dpkg --add-architecture amd64'.

@real-nickel
Copy link

It didn't work anyway

@lumanga
Copy link

lumanga commented Mar 29, 2021

Dear Sirs,
After one year, I try to remake a new SCRATCH64bit.DEB for Linux.
From LINUX MINT 20.1 (Ubuntu 20.1) 64bit., I used the .sh script file I used in the past...
I just changed the version of scratch, but the command:

wget -O /tmp/scratch-desktop.exe 'https://downloads.scratch.mit.edu/desktop/Scratch%20Desktop%20Setup%VERSIONNUMBER.exe'

Is no more valid. So **I downloaded manually the .exe and and put in /temp the "scratch-desktop.exe" file. the .DEB was created, about 207Mbyte. the installation of .deb works, the menu icon is created but Scatch doesn't start!

From terminal:

`
linux@Mint201:~$ scratch-desktop
internal/modules/cjs/loader.js:586
throw err;
^

Error: Cannot find module '/usr/lib/scratch-desktop/resources/electron.asar/browser/init.js'
at Function.Module._resolveFilename (internal/modules/cjs/loader.js:584:15)
at Function.Module._load (internal/modules/cjs/loader.js:510:25)
at Function.Module.runMain (internal/modules/cjs/loader.js:746:12)
at startup (internal/bootstrap/node.js:282:19)
at bootstrapNodeJSCore (internal/bootstrap/node.js:759:3)
`

@bert003
Copy link

bert003 commented Jul 11, 2021

I managed to run the latest version of Scratch on the latest Debian Buster by doing the following:

  1. When I followed the deb (amd64) instructions, I get a chrome-sandbox error. This should be fixed by executing: chmod 4755 chrome-sandbox as root.
  2. Then after this, I got stuck with the Scratch is loading... screen. After A LOT of investigation, I solved the problem as follows:
  • Go to directory resources/app
  • vim main.js
  • find nodeIntegration: true
  • after true add: ,\n contextIsolation: false\n
  • save and run scratch-desktop

Hope this helps someone!

@bidaian
Copy link

bidaian commented Aug 8, 2021

Thanks a lot @bert003! In my case, to modify the file I had to first unpack the app.asar file (also in resources/). I did

  • npm install asar
  • asar extract app.asar modif
  • edit the file modif/main.js
  • asar pack modif app.asar

And then it works.

@jolly-jump
Copy link

Thanks a lot @bert003 and @bidaian
I'll bring this to arch.

@lumanga
Copy link

lumanga commented Jan 22, 2022

Dear Sirs,

I have followed the procedure and I obtained a working .deb installation file using the latest verison "Scratch-desktop v3.26.0"
After installed into Linux Mint 20.3 MATE 64bit, I have the ""SCRATCH IS LOADING" screen..
Then I try to modify the main.js
I had problem installing via terminal, of "npm install asar", so I used SNAP to install asar...

sudo rm /etc/apt/preferences.d/nosnap.pref && sudo apt update && sudo snap install asar --classic

after that,
cd /lib/scratch-desktop/resources sudo asar extract app.asar modif cd modif sudo nano main.js (and into the line "nodeIntegration: true" I changed it nto: "true,\n contextIsolation: false\n") cd .. sudo asar pack modif app.asar
Now If I launch Scratch, NO screen appear, anche the program close without showimg the Scratch windows (this is differemt from the starting issue with freezing screen "SCRATCH IS LOADING" )

Try to start Scratch via terminal, I obtain:

linux@Mint:/lib/scratch-desktop/resources$ /usr/lib/scratch-desktop/electron "/usr/lib/scratch-desktop/Scratch-desktop"
A JavaScript error occurred in the main process Uncaught Exception: SyntaxError: Unexpected identifier at Object.call (/usr/lib/scratch-desktop/resources/app.asar/main.js:1323:181) at e (/usr/lib/scratch-desktop/resources/app.asar/webpack:/webpack/bootstrap:25:22) at Object.call (/usr/lib/scratch-desktop/resources/app.asar/main.js:1328:97) at __webpack_require__ (/usr/lib/scratch-desktop/resources/app.asar/webpack:/webpack/bootstrap:25:22) at module.exports../node_modules/ajv/lib/ajv.js (/usr/lib/scratch-desktop/resources/app.asar/webpack:/webpack/bootstrap:96:10) at Object.<anonymous> (/usr/lib/scratch-desktop/resources/app.asar/main.js:1:1052) at Module._compile (node:internal/modules/cjs/loader:1116:14) at Object.Module._extensions..js (node:internal/modules/cjs/loader:1169:10) at Module.load (node:internal/modules/cjs/loader:988:32) at Module._load (node:internal/modules/cjs/loader:829:12) libva error: vaGetDriverNameByIndex() failed with unknown libva error, driver_name = (null) [2870:0122/203824.204885:ERROR:viz_main_impl.cc(161)] Exiting GPU process due to errors during initialization libva error: vaGetDriverNameByIndex() failed with unknown libva error, driver_name = (null) [2886:0122/203824.280940:ERROR:sandbox_linux.cc(376)] InitializeSandbox() called with multiple threads in process gpu-process.

Seems that the ASAR procedure to modify the file main.js has broke someting...Is it possible to solve this problem?
Many thanks in advance for your job!

@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.

@hueychen27
Copy link

In create-deb.sh, the last line should be sudo gdebi /tmp/scratch-desktop_3.29.1_amd64.deb, not sudo gdebi /tmp/scratch-desktop_3.12.0_amd64.deb

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