david/synchole
david
/
synchole
Archived
1
0
Fork 0

added uninstall instructions to README.md and added a cron check

This commit is contained in:
david 2019-11-09 02:43:46 +01:00
parent 1f8ff1e5b3
commit 00a7209d0f
2 changed files with 57 additions and 20 deletions

View File

@ -23,13 +23,13 @@ sudo ln -s /etc/pihole/regex.list .
``` ```
sudo apt-get update sudo apt-get update
sudo apt-get install wget sudo apt-get install wget
sudo wget https://socialg.it/david/synchole/raw/master/synchole.sh -O /usr/bin/synchole.sh sudo wget https://socialg.it/david/synchole/raw/master/synchole.sh -O /usr/bin/synchole
sudo chmod +x /usr/bin/synchole.sh sudo chmod +x /usr/bin/synchole
``` ```
5. Configure the synchole script to your liking. 5. Configure the synchole script to your liking.
``` ```
sudo vim /usr/bin/synchole.sh sudo vim /usr/bin/synchole
``` ```
The config section is at the top of the script. The config section is at the top of the script.
@ -37,7 +37,7 @@ The config section is at the top of the script.
``` ```
sudo crontab -e sudo crontab -e
``` ```
Example cronjob: `*/5 * * * * /opt/synchole/synchole.sh -q` (this runs synchole every 5 minutes) Example cronjob: `*/5 * * * * /usr/bin/synchole` (this runs synchole every 5 minutes)
8. Repeat steps 3 through 6 for additional `SLAVE` servers. 8. Repeat steps 3 through 6 for additional `SLAVE` servers.
@ -50,8 +50,18 @@ Example cronjob: `*/5 * * * * /opt/synchole/synchole.sh -q` (this runs synchole
2. Run the following commands (again) on the `SLAVE` server. 2. Run the following commands (again) on the `SLAVE` server.
``` ```
sudo wget https://socialg.it/david/synchole/raw/master/synchole.sh -O /usr/bin/synchole.sh sudo wget https://socialg.it/david/synchole/raw/master/synchole.sh -O /usr/bin/synchole
sudo chmod +x /usr/bin/synchole.sh sudo chmod +x /usr/bin/synchole
```
## Uninstall
1. To uninstall synchole login via SSH to the `SLAVE` server.
2. Run the following commands on the `SLAVE` server.
```
sudo rm /usr/bin/synchole
sudo rm -r /var/www/html/synchole
``` ```

View File

@ -25,6 +25,13 @@ DEPENDENCIES="wget"
# **** functions **** # **** functions ****
## check if script is run by cron
amicron() {
if [ -t 1 ]; then
return 1
fi
}
## check for elevated privileges ## check for elevated privileges
amiroot() { amiroot() {
if [ $(whoami) != "root" ]; then if [ $(whoami) != "root" ]; then
@ -49,24 +56,32 @@ log() {
level="\033[33m!\033[0m" level="\033[33m!\033[0m"
;; ;;
"debug") "debug")
if [ $DEBUG -eq 1 ]; then if [ $DEBUG -eq 1 ] && [ $CRON -eq 0 ]; then
level="\033[2md\033[0m" level="\033[2md\033[0m"
else else
return 0 return 0
fi fi
;; ;;
"success") "success")
level="\033[32m✓\033[0m" if [ $CRON -eq 0 ]; then
level="\033[32m✓\033[0m"
else
return 0
fi
;; ;;
"info") "info")
level="i" if [ $CRON -eq 0 ]; then
level="i"
else
return 0
fi
;; ;;
*) *)
level="\033[31mLoglevel unknown. Programming error? ($*)\033[0m" level="\033[31mLoglevel unknown. Programming error? ($1)\033[0m"
;; ;;
esac esac
sleep 0.5; echo -e "[$level] $2" sleep 0.5; echo -e "[$NAME]-[$level] ${@:2}"
} }
## backup single list file to $BACKUP_PATH ## backup single list file to $BACKUP_PATH
@ -143,7 +158,16 @@ download_list() {
# **** start of script **** # **** start of script ****
log debug "Starting synchole"
## preflight checks ## preflight checks
log debug "Running preflight checks"
if amicron; then
CRON=1
else
CRON=0
fi
if ! amiroot; then if ! amiroot; then
log error "You must be root" log error "You must be root"
exit 1 exit 1
@ -161,7 +185,7 @@ for DEPENDENCY in $DEPENDENCIES; do
fi fi
done done
log success "Preflight checks passed" log success "Preflight checks passed successfully"
## generate $BACKUP_PATH and $DOWNLOAD_PATH if not available ## generate $BACKUP_PATH and $DOWNLOAD_PATH if not available
if ! create_path $DOWNLOAD_PATH; then if ! create_path $DOWNLOAD_PATH; then
@ -177,12 +201,12 @@ fi
## download remote files from MASTER and backup local lists ## download remote files from MASTER and backup local lists
CHANGES=0 CHANGES=0
for LIST in $LISTS; do for LIST in $LISTS; do
log info "Downloading $LIST." log debug "Downloading $LIST from $MASTER"
if ! download_list $LIST; then if ! download_list $LIST; then
log error "Something went wrong while downloading $LIST" log error "Something went wrong while downloading $LIST"
exit 1 exit 1
else else
log success "Successfully downloaded $LIST." log success "Successfully downloaded $LIST"
fi fi
#TODO: don't install new list if to many changes or #TODO: don't install new list if to many changes or
@ -190,24 +214,24 @@ for LIST in $LISTS; do
# maybe check if wget actually downloaded a file or were we redirected # maybe check if wget actually downloaded a file or were we redirected
diff $DOWNLOAD_PATH/$LIST $LISTS_PATH/$LIST diff $DOWNLOAD_PATH/$LIST $LISTS_PATH/$LIST
if [ $? -ne 0 ]; then if [ $? -ne 0 ]; then
log info "Backing up $LIST." log debug "Backing up $LIST"
if [ -r $LISTS_PATH/$LIST ]; then if [ -r $LISTS_PATH/$LIST ]; then
if ! backup_list $LIST; then if ! backup_list $LIST; then
log error "Something went wrong while backing up $LIST. Exiting." log error "Something went wrong while backing up $LIST"
exit 1 exit 1
else else
log success "Successfully backed up $LIST." log debug "Successfully backed up $LIST"
fi fi
else else
log warn "$LIST not found. Skipping." log debug "$LIST not found, skipping"
fi fi
log info "Installing $LIST." log debug "Installing $LIST."
if ! install_list $LIST; then if ! install_list $LIST; then
log error "Something went wrong while installing $LIST" log error "Something went wrong while installing $LIST"
exit 1 exit 1
else else
log success "Successfully installed $LIST" log success "Successfully installed new $LIST"
CHANGES=1 CHANGES=1
fi fi
else else
@ -217,6 +241,7 @@ done
## run updateGravity ## run updateGravity
if [ $CHANGES -eq 1 ]; then if [ $CHANGES -eq 1 ]; then
log debug "Updating gravity"
if ! update_gravity; then if ! update_gravity; then
log error "Something went wrong while updating gravity" log error "Something went wrong while updating gravity"
exit 1 exit 1
@ -227,6 +252,8 @@ else
log debug "No files have been changed, skipping gravity update" log debug "No files have been changed, skipping gravity update"
fi fi
#TODO: sync hosts and restartdns on changes
exit 0 exit 0
# **** end of script **** # **** end of script ****