# Auto-Update

#### Aptoide:

update-script:

`/usr/local/bin/update_packages.sh`

```bash
sudo bash -c 'echo -e "#!/bin/bash\n\napt update\napt upgrade -y\napt autoremove -y\napt autoclean -y" > /usr/local/bin/update_packages.sh' && sudo chmod +x /usr/local/bin/update_packages.sh
```

```bash
#!/bin/bash

apt update
apt upgrade -y
apt autoremove -y
apt autoclean -y
```

crateapt-updater.service

```bash
sudo bash -c 'echo -e "[Unit]\nDescription=Update all apt packages\n\n[Service]\nType=oneshot\nExecStart=/usr/local/bin/update_packages.sh\n\n[Install]\nWantedBy=multi-user.target" > /etc/systemd/system/update_packages.service'
```

```ini
[Unit]
Description=Update all apt packages

[Service]
Type=oneshot
ExecStart=/usr/local/bin/update_packages.sh

[Install]
WantedBy=multi-user.target
```

#### Flatapak:

create flatpak-updater.service

```bash
sudo bash -c 'echo -e "[Unit]\nDescription=Update all flatpak apps and runtimes\n\n[Service]\nType=oneshot\nExecStart=/usr/bin/flatpak update -y\n\n[Install]\nWantedBy=multi-user.target" > /etc/systemd/system/flatpak_updater.service'
```

```ini
[Unit]
Description=Update all flatpak apps and runtimes

[Service]
Type=oneshot
ExecStart=/usr/bin/flatpak update -y

[Install]
WantedBy=multi-user.target
```

#### Timer:

create apt-updater.timer

```bash
sudo bash -c 'echo -e "[Unit]\nDescription=Run update_packages daily\n\n[Timer]\nOnBootSec=5min\nOnUnitActiveSec=24h\nPersistent=true\n\n[Install]\nWantedBy=timers.target" > /etc/systemd/system/update_packages.timer'
```

```ini
[Unit]
Description=Run update_packages daily

[Timer]
OnBootSec=5min
OnUnitActiveSec=24h
Persistent=true

[Install]
WantedBy=timers.target
```

#### Timer - Server:

```bash
sudo bash -c 'echo -e "[Unit]\nDescription=Run update_packages daily\n\n[Timer]\nOnBootSec=5min\nOnCalendar=*-*-* 02:00:00\nPersistent=true\n\n[Install]\nWantedBy=timers.target" > /etc/systemd/system/update_packages.timer'

```

```ini
[Unit]
Description=Run update_packages daily

[Timer]
OnBootSec=5min
OnCalendar=*-*-* 02:00:00
Persistent=true

[Install]
WantedBy=timers.target
```

create flatpak-updater.timer

```bash
sudo bash -c 'echo -e "[Unit]\nDescription=Run flatpak_updater daily\n\n[Timer]\nOnBootSec=5min\nOnUnitActiveSec=24h\nPersistent=true\n\n[Install]\nWantedBy=timers.target" > /etc/systemd/system/flatpak_updater.timer'
```

```ini
[Unit]
Description=Run flatpak-updater daily

[Timer]
OnBootSec=5min
OnUnitActiveSec=24h
Persistent=true

[Install]
WantedBy=timers.target
```

####   


#### Aktivierung:

```bash
sudo systemctl daemon-reload
sudo systemctl enable --now flatpak_updater.timer
sudo systemctl enable --now update_packages.timer
```

check:

```bash
sudo systemctl list-timers --all
```