Skip to content

Commit

Permalink
Merge pull request #25 from Raabi91/development
Browse files Browse the repository at this point in the history
switch to virtualenv
  • Loading branch information
Raabi91 authored Apr 3, 2021
2 parents 65f1db3 + 0f573d6 commit 3b3e71e
Show file tree
Hide file tree
Showing 9 changed files with 158 additions and 102 deletions.
6 changes: 6 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
multi_config.sh
state_config.txt
time_config.txt
websocket_state.txt
picture/
!picture/read.md
27 changes: 9 additions & 18 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,24 +4,15 @@ A Script/Programm to send the printer State before, during and after a print via

---

## Update_Mangager now Suppoertet

if you wan´t to use the updatet manager from moonraker for update moonraker-telegram, then you need to reinstall moonraker telegram

here is the how to:

1. save your telegram_config.sh on your pc (copy & paste)
2. Go into ssh an remove the moonraker-telegram folder
´´´
rm -rf moonraker-telegram
´´´
3. do a new [Installation](https://github.com/Raabi91/moonraker-telegram/blob/main/docs/Installation.md)
4. Add the the update manager config to your moonraker config you will find it in the [FAQ](https://github.com/Raabi91/moonraker-telegram/blob/main/docs/FAQ.md)
5. restore your telegram_config.sh
6. restart moonraker-telegram
´´´
sudo systemctl restart moonraker-telegram
´´´
## switching to virtualenv

i am switch python to virtualenv (for better support at moonraker update manager) so you have to adjust now once the moonraker updatet manager because something has changed

https://github.com/Raabi91/moonraker-telegram/blob/master/docs/FAQ.md#how-to-set-up-updatet-manager-from-moonraker

and you have to run the install.sh script once or do an update via ssh.

https://github.com/Raabi91/moonraker-telegram/blob/master/docs/FAQ.md#how-upgrade-the-script-in-ssh

---

Expand Down
20 changes: 19 additions & 1 deletion docs/FAQ.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,31 @@ add this
type: git_repo
path: /home/pi/moonraker-telegram
origin: https://github.com/Raabi91/moonraker-telegram.git
env: /usr/lib/python3/
env: /home/pi/.moonraker-telegram-env/bin/python
requirements: scripts/moonraker-telegram-requirements.txt
install_script: scripts/install.sh
```

too your moonraker config

## Update_Mangager shows drity or false

if the update manager shows an error you have to do the following

here is the how to:

1. save your telegram_config.sh on your pc (copy & paste)
2. Go into ssh an remove the moonraker-telegram folder
´´´
rm -rf moonraker-telegram
´´´
3. do a new [Installation](https://github.com/Raabi91/moonraker-telegram/blob/main/docs/Installation.md)
4. restore your telegram_config.sh when is not correct
5. restart moonraker-telegram
´´´
sudo systemctl restart moonraker-telegram
´´´

## How Upgrade the script in SSH

if you use multiple bots. you must first go in the folder you created
Expand Down
31 changes: 20 additions & 11 deletions docs/Installation.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,19 +6,21 @@
2. Click Start to begin a conversation with @BotFather
3. Send /newbot to @BotFather. @BotFather will respond:
4. Send your bot’s name to @BotFather. Your bot’s name can be anything.

```
Note that this is not your bot’s Telegram @username. You will create the username in step 5.
```

5. Send your bot’s username to @BotFather. BotFather will respond:
6. Begin a conversation with your bot. Click on the t.me/<bot-username> link in @BotFather’s response and click Start at the bottom of your Telegram application. Your newly-created bot will appear in the chat list on the left side of the application.


## Get a Telegram API access token

Telegram’s @BotFather bot sent you an API access token when you created your bot. See the @BotFather response in step 5 of the previous section for where to find your token. If you can’t find the API access token, create a new token with the following steps below.

1. Send /token to @BotFather
2. Select the relevant bot at the bottom of your Telegram application. @BotFather responds with a new API access token:

```
You can use this token to access HTTP API:
<API-access-token>
Expand All @@ -29,27 +31,30 @@ For a description of the Bot API, see this page: https://core.telegram.org/bots/
## Get your Telegram chat ID

1. Paste the following link in your browser. Replace <API-access-token> with the API access token that you identified or created in the previous section:

```
https://api.telegram.org/bot<API-access-token>/getUpdates?offset=0
```

2. Send a message to your bot in the Telegram application. The message text can be anything. Your chat history must include at least one message to get your chat ID.
3. Refresh your browser.

4. Identify the numerical chat ID by finding the id inside the chat JSON object. In the example below, the chat ID is 123456789.

```
{
{
"ok":true,
"result":[
{
"result":[
{
"update_id":XXXXXXXXX,
"message":{
"message":{
"message_id":2,
"from":{
"from":{
"id":123456789,
"first_name":"Mushroom",
"last_name":"Kap"
},
"chat":{
"chat":{
"id":123456789,
"first_name":"Mushroom",
"last_name":"Kap",
Expand All @@ -70,24 +75,27 @@ First of all check you have added [display_status] to your Mainsail/Fluidd Confi
Download an install the plugin

If that's the first time you use it (or if you deleted the folder) do this :

```
cd ~
git clone https://github.com/Raabi91/moonraker-telegram
cd moonraker-telegram
```

then install the script with

```
./scripts/install.sh
```

during installation you will be asked for the config path of Moonraker. Enter the full path here. if you have only one instance of moonraker, default is :

```
/home/pi/klipper_config
```

You will also be asked for multiple installations.
If you have only one installation, you just have to confirm with enter.
You will also be asked for multiple installations.
If you have only one installation, you just have to confirm with enter.
if you want to have multiple installations, have a look at the [FAQ](https://github.com/Raabi91/moonraker-telegram/blob/main/docs/FAQ.md).

Then edit your config (telegram_config.sh) using the Mainsail or Fluidd web interface, edit the variables between the "".
Expand All @@ -99,14 +107,15 @@ Then add this to Moonraker configuration file for the Update Manager (default :
type: git_repo
path: /home/pi/moonraker-telegram
origin: https://github.com/Raabi91/moonraker-telegram.git
env: /usr/lib/python3/
env: /home/pi/.moonraker-telegram-env/bin/python
requirements: scripts/moonraker-telegram-requirements.txt
install_script: scripts/install.sh
```

When you are done restart monraker-telegram with

```
sudo systemctl restart moonraker-telegram
```

(I also suggest a full reboot if needed).
(I also suggest a full reboot if needed).
6 changes: 5 additions & 1 deletion docs/changelog.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
26.03.2021
01.04.2021

- switch python to to virtualenv

26.03.2021

- add /print command
- add placeholders for extruder temperature
Expand Down
149 changes: 90 additions & 59 deletions scripts/install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,82 +2,113 @@

MYDIR=`dirname $0`
DIR="`cd $MYDIR/../; pwd`"
MTENV="${HOME}/.moonraker-telegram-env"

echo "========= moonraker-telegram - Installation Script ==========="
install_packages()
{
echo "========= moonraker-telegram - Installation Script ==========="

PKGLIST="python3 python3-pip python3-setuptools python3-virtualenv"
PKGLIST="${PKGLIST} bc"

sudo apt-get install --yes ${PKGLIST}

pip3 install wheel websocket_client requests telepot
}

create_virtualenv()
{
echo "Creating virtual environment"
[ ! -d ${MTENV} ] && virtualenv -p /usr/bin/python3 ${MTENV}

sudo apt-get install bc python3 python3-pip python3-setuptools
pip3 install wheel websocket_client requests telepot
${MTENV}/bin/pip install -r $DIR/scripts/moonraker-telegram-requirements.txt
}

install_config()
{
echo -e "\n========= Check for config ==========="

if ! grep -q "config_dir=" $DIR/multi_config.sh
then
echo -e "========= pleas input your settings description on github ==========="
echo -e "please enter your moonraker config path"
echo -e "and press enter (like /home/pi/klipper_config):"
read CONFIG
echo "# moonraker config path" >> $DIR/multi_config.sh
echo "config_dir=$CONFIG" >> $DIR/multi_config.sh
fi
if ! grep -q "multi_instanz=" $DIR/multi_config.sh
if ! grep -q "config_dir=" $DIR/multi_config.sh
then
echo -e "========= pleas input your settings description on github ==========="
echo -e "please enter your moonraker config path"
echo -e "and press enter (like /home/pi/klipper_config):"
read CONFIG
echo "# moonraker config path" >> $DIR/multi_config.sh
echo "config_dir=$CONFIG" >> $DIR/multi_config.sh
fi
if ! grep -q "multi_instanz=" $DIR/multi_config.sh
then
echo "if you want to use multiple instances on one pi, enter an identifier here. this is needed to create the sytemd service"
echo "If you only use it once per hardware, simply press enter."
read INSTANZ
echo "# if you want to use multiple instances on one pi, enter an identifier here. this is needed to create the sytemd service." >> $DIR/multi_config.sh
echo "multi_instanz="moonraker-telegram$INSTANZ"" >> $DIR/multi_config.sh
fi

. $DIR/multi_config.sh

if ! [ -e $config_dir/telegram_config.sh ]
then
sudo cp $DIR/example_config.sh $config_dir/telegram_config.sh
sudo chmod 777 $config_dir/telegram_config.sh
fi

if [ -L $config_dir/telegram_config.sh ]
then
sudo rm $config_dir/telegram_config.sh
sudo cp $DIR/telegram_config.sh $config_dir/telegram_config.sh
sudo rm $DIR/telegram_config.sh
sudo chmod 777 $config_dir/telegram_config.sh
fi

. $config_dir/telegram_config.sh

echo -e "\n========= set permissions ==========="
sleep 1
sudo chmod 777 $config_dir/telegram_config.sh

echo -e "\n========= install systemd ==========="
echo "if you want to use multiple instances on one pi, enter an identifier here. this is needed to create the sytemd service"
echo "If you only use it once per hardware, simply press enter."
read INSTANZ
echo "# if you want to use multiple instances on one pi, enter an identifier here. this is needed to create the sytemd service." >> $DIR/multi_config.sh
echo "multi_instanz="moonraker-telegram$INSTANZ"" >> $DIR/multi_config.sh
fi

SCRIPTPATH="$( cd "$(dirname "$0")" >/dev/null 2>&1 ; pwd -P )"
MTPATH=$(sed 's/\/scripts//g' <<< $SCRIPTPATH)
. $DIR/multi_config.sh

SERVICE=$(<$SCRIPTPATH/moonraker-telegram.service)
MTPATH_ESC=$(sed "s/\//\\\\\//g" <<< $MTPATH)
SERVICE=$(sed "s/MT_DESC/$multi_instanz/g" <<< $SERVICE)
SERVICE=$(sed "s/MT_USER/$USER/g" <<< $SERVICE)
SERVICE=$(sed "s/MT_DIR/$MTPATH_ESC/g" <<< $SERVICE)
if ! [ -e $config_dir/telegram_config.sh ]
then
sudo cp $DIR/example_config.sh $config_dir/telegram_config.sh
sudo chmod 777 $config_dir/telegram_config.sh
fi

echo "$SERVICE" | sudo tee /etc/systemd/system/$multi_instanz.service > /dev/null
sudo systemctl daemon-reload
sudo systemctl enable $multi_instanz
if [ -L $config_dir/telegram_config.sh ]
then
sudo rm $config_dir/telegram_config.sh
sudo cp $DIR/telegram_config.sh $config_dir/telegram_config.sh
sudo rm $DIR/telegram_config.sh
sudo chmod 777 $config_dir/telegram_config.sh
fi

if crontab -l | grep -i /home/pi; then
crontab -u pi -l | grep -v "$DIR" | crontab -u pi -
. $config_dir/telegram_config.sh

echo -e "\n========= set permissions ==========="
sleep 1
(crontab -u pi -l ; echo "") | crontab -u pi -
fi

chmod 777 $config_dir/telegram_config.sh
}

install_systemd_service()
{
echo -e "\n========= install systemd ==========="

SCRIPTPATH="$( cd "$(dirname "$0")" >/dev/null 2>&1 ; pwd -P )"
MTPATH=$(sed 's/\/scripts//g' <<< $SCRIPTPATH)

SERVICE=$(<$SCRIPTPATH/moonraker-telegram.service)
MTPATH_ESC=$(sed "s/\//\\\\\//g" <<< $MTPATH)
SERVICE=$(sed "s/MT_DESC/$multi_instanz/g" <<< $SERVICE)
SERVICE=$(sed "s/MT_USER/$USER/g" <<< $SERVICE)
SERVICE=$(sed "s/MT_DIR/$MTPATH_ESC/g" <<< $SERVICE)

echo "$SERVICE" | sudo tee /etc/systemd/system/$multi_instanz.service > /dev/null
sudo systemctl daemon-reload
sudo systemctl enable $multi_instanz

if crontab -l | grep -i /home/pi; then
crontab -u pi -l | grep -v "$DIR" | crontab -u pi -
sleep 1
(crontab -u pi -l ; echo "") | crontab -u pi -
fi
}

start_moonraker-telegram() {
echo -e "\n========= start systemd for $multi_instanz ==========="

sudo systemctl stop $multi_instanz
sudo systemctl start $multi_instanz

}

install_packages
create_virtualenv
install_config
install_systemd_service
start_moonraker-telegram

echo -e "\n========= installation end ==========="
echo "========= open and edit your config with ==========="
echo "========= mainsail or fluidd and edit the telegram_config.sh ==========="

exit 1
exit 1
Empty file modified scripts/list_files.sh
100644 → 100755
Empty file.
2 changes: 1 addition & 1 deletion scripts/moonraker-telegram-requirements.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# Python dependencies for Moonraker-telegram
wheel==0.32.3
websocket_client==0.57.0
websocket_client==0.58.0
requests==2.21.0
telepot==12.7
Loading

0 comments on commit 3b3e71e

Please sign in to comment.