Staubgeborener / Klipper-Backup

Klipper-Backup is a script for manual or automated Klipper GitHub backups. It's Lightweight, pragmatic and comfortable.
https://klipperbackup.xyz
295 stars 57 forks source link

authentication failing #2

Closed Rvh91 closed 1 year ago

Rvh91 commented 1 year ago

Hi I'm trying to set this up following the wiki. I'm running into authentication issues. When following the wiki, the configuring the token isn't mentioned until the configuration section. So when doing the first push, it asks me to authenticate, and it does so by asking for my GitHub username and password, which I then provide. However it then tells me authentication via password is no longer possible since 2021 or so.

from the configuration wiki page, it seems as if authentication should be handles by the .env file. However, that one does not exist for me :

pi@mainsail:~/klipper-backup $ ls -la /home/pi/klipper-backup
total 36
drwxr-xr-x  3 pi pi 4096 Jun  5 18:16 .
drwxr-xr-x 17 pi pi 4096 Jun  5 18:15 ..
-rw-r--r--  1 pi pi  908 Jun  5 18:15 .env.example
drwxr-xr-x  8 pi pi 4096 Jun  5 18:16 .git
-rw-r--r--  1 pi pi   17 Jun  5 18:15 .gitignore
-rwxr-xr-x  1 pi pi 2165 Jun  5 18:15 install.sh
-rw-r--r--  1 pi pi  181 Jun  5 18:15 README.md
-rwxr-xr-x  1 pi pi 1254 Jun  5 18:15 script.sh
-rw-r--r--  1 pi pi    5 Jun  5 18:15 version

However, I don't have an .env variable to edit. Also I must admit that I'm not very familiar with linux, so creating files and adding lines to files from the command line is not something that I know how to do without line by line instruction (sorry for that..).

Rvh91 commented 1 year ago

small update. managed to create the .env file. and tried to use the:

git push https://"$github_token"@github.com/"$github_username"/"$github_repository".git

command i found in the script.sh, which I tried to use to push the first commit, where I have substituted "$github_token" for the github token, "$github_username" for my username, and "$github_repository" for my repo name. but it then asks me for a password to: "https://"$github_token"@github.com"

Staubgeborener commented 1 year ago

However, I don't have an .env variable to edit

I think you have not run install.sh like it's described in the wiki (see this and that - the curl method is running install.sh by itself). The install.sh script creates your missing .env file, otherwise you could simply run something like cd ~/klipper-backup && mv .env.example .env to create it by yourself.

So when doing the first push, it asks me to authenticate, and it does so by asking for my GitHub username and password, which I then provide.

Correct.

However it then tells me authentication via password is no longer possible since 2021 or so.

It's a little bit weird, sometimes you can use your GitHub password, sometimes git needs a token. Since 2021 it should actually work only via the token but whatever. So try to use your GitHub username and your token. For the future and how the token works for authentication, I found this small but quite good tutorial.

Please give me feedback if this works so far (and if not what exactly you did and what you got back), then I'll adjust the wiki in further detail.

and adding lines to files from the command line is not something that I know how to do without line by line instruction (sorry for that..).

So let's say you want to edit the .env file with your information:

  1. move into the klipper-backup directory: cd ~/klipper-backup
  2. check if there is a hidden .env file inside this directory: ls -la (if not, pretty sure you didn't do what was described in the wiki)
  3. edit content, for example with nano: nano .env
  4. move with your arrow keys ↑ ← ↓ → to the important lines and copy/paste the important lines inside (often the right mouse button is used to paste in ssh terminals)
  5. Save content and exit nano with ^X (which means CTRL+X) -> (Y)ES -> [Enter]

This is my personal .env file (obviously without token) so you can get a feeling how it should looks like.

small update. managed to create the .env file. and tried to use the: [...]

Don't do this, do the stuff described in the wiki.

Rvh91 commented 1 year ago

Hi, thanks for the elaborate and step by step instructions, much appreciated!

I did follow the moonraker support steps actually (I recall seeing the cyan klipper backup text popping by), but I ran those steps again just to be sure. Tried the authentication again with all possible variants, my password, the token, the token minus the ghp_, none of which worked.

Then regenerated the token, but now with 'workflow' enabled, instead of only 'repo', and that works! probably my lack of experience, but might be worthwhile to add that to the wiki :).

Now I managed to complete the rest, and I have my backup on the repository! Again, thanks a lot for the work and assistance!

Rvh91 commented 1 year ago

Alright.. new issue.. in mainsail, under the update section, klipper backup was noted as 'dirty', so I used the soft recover, which failed. I then did a hard recover, which I guess then wiped everything in the folder? So I went through the installation again, tried to edit the .env, which shows:

github_token=ghp_*****
github_username=Rvh91
github_repository=klipper_config

path_printercfg=/home/pi/klipper_config/printer.cfg
path_mainsailcfg=/home/pi/klipper_config/mainsail.cfg
path_moonrakercfg=/home/pi/klipper_config/moonraker.conf
path_timelapsecfg=/home/pi/klipper_config/timelapse.cfg
path_telegramcfg=/home/pi/klipper_config/telegram.conf
path_crowsnestcfg=/home/pi/klipper_config/crowsnest.conf
path_adxlcfg=/home/pi/klipper_config/adxl.cfg
path_pacalcfg=/home/pi/klipper_config/pa_cal.cfg
path_getprobelimitcfg=/home/pi/klipper_config/GET_PROBE_LIMITS.cfg
path_savedvariablescfg=/home/pi/klipper_config/saved_variables.cfg
path_pa_flow_calibratecfg=/home/pi/klipper_config/pa_flow_calibrate.cfg
path_soundscfg=/home/pi/klipper_config/sounds.cfg
path_macroscfg=/home/pi/klipper_config/macros.cfg

backup_folder=klipper

However, when I now try to run the script, i get the following error from git:

 ! [rejected]        main -> main (fetch first)
error: failed to push some refs to 'https://github.com/Rvh91/klipper_config.git'

which I don't really know how to fix.

As a final remark, shouldn't the repository_name in the ecron describered here instead be klipper-backup in this case?

Staubgeborener commented 1 year ago

Yeah, the cronjob should be @reboot /home/pi/klipper-backup/script.sh, I will change this tomorrow in the wiki.

About your fetch issue, you can do something like git fetch origin or (I think the better way?) git pull origin master - the content in your GitHub repository is different from your local one.

I would suggest to remove the klipper-backup with a sudo rm -r ~/klipper-backup and also delete and re-create the repository in GitHub and start from scratch.

Rvh91 commented 1 year ago

Thanks for the advise. I am running it again. I wanted to let you know that the .env file is really missing. there is a .env.example however.:

pi@mainsail:~/klipper-backup $ ls -la
total 36
drwxr-xr-x  3 pi pi 4096 Jun 10 13:18 .
drwxr-xr-x 17 pi pi 4096 Jun 10 13:07 ..
-rw-r--r--  1 pi pi  908 Jun 10 13:07 .env.example
drwxr-xr-x  8 pi pi 4096 Jun 10 13:18 .git
-rw-r--r--  1 pi pi   17 Jun 10 13:07 .gitignore
-rwxr-xr-x  1 pi pi 2165 Jun 10 13:07 install.sh
-rw-r--r--  1 pi pi  181 Jun 10 13:07 README.md
-rwxr-xr-x  1 pi pi 1254 Jun 10 13:07 script.sh
-rw-r--r--  1 pi pi    5 Jun 10 13:07 version
pi@mainsail:~/klipper-backup $
Staubgeborener commented 1 year ago

Thanks, that was my fault. The install.sh scripts needs a klipper-backup-main folder in order to work correctly. This is why this installation is working, but the moonraker related installation didn't create the .env file.

I changed the wiki again.

This is the way to go:

cd ~
git clone https://github.com/Staubgeborener/klipper-backup klipper-backup-main
chmod +x ./klipper-backup-main/*.sh && ./klipper-backup-main/install.sh
Rvh91 commented 1 year ago

Thanks! I got it setup now. However, in moonraker update manager, I'm still getting the 'invalid' flag. Meaning I cannot update. Do you have any idea what could be causing that?

Staubgeborener commented 1 year ago

@Rvh91 I know what cause this error: https://github.com/Staubgeborener/klipper-backup/issues/4#issuecomment-1590680600 I need to fix this someday. Nevertheless, you can use the script right now without any impairments.

I will close this issue as your problem is solved. Keep an eye on the other thread for updates about this dirty moonraker flag issue.