Compare commits
No commits in common. "361c9759fa321ddc17d74404de9e304e6db71216" and "62618d099a187f44814c4b8b3ce5a65033bdac7d" have entirely different histories.
361c9759fa
...
62618d099a
106
README.md
106
README.md
@ -1,50 +1,96 @@
|
|||||||
# GeoIP Database Updater Script
|
# GeoIP Database Updater Script
|
||||||
|
|
||||||
This guide provides instructions on how to automate the process of checking for
|
This script, automates the process of checking for new releases of GeoIP
|
||||||
new releases of GeoIP databases on GitHub, downloading them if they're not
|
databases on GitHub, downloading them if they're not already present, and
|
||||||
already present, and updating the local database files for use with the
|
updating the local database files for use.
|
||||||
`geoip_updater.sh` script.
|
|
||||||
|
|
||||||
## Prerequisites
|
## Prerequisites
|
||||||
|
|
||||||
Before proceeding, ensure that `wget` and `curl` are installed on your system,
|
Ensure `wget` and `curl` are installed on your system.
|
||||||
as they are required for the script to download files and check URLs.
|
|
||||||
|
|
||||||
## Setup Instructions
|
## Setup Instructions
|
||||||
|
|
||||||
### Using `setup.sh` Script
|
### 1. Create the Destination Directory
|
||||||
|
|
||||||
1. **Execute `setup.sh` as Normal User**:
|
```bash
|
||||||
- Run the setup script as a normal user **without** sudo privileges to perform operations like creating directories, changing permissions, and editing the crontab. It will ask you for the password when needed.
|
sudo mkdir -p /usr/local/share/GeoIP
|
||||||
```bash
|
```
|
||||||
./setup.sh
|
|
||||||
```
|
|
||||||
- This approach ensures that the crontab entries are added to the current user's crontab, not the root's crontab.
|
|
||||||
|
|
||||||
2. **Verify Crontab Entry**:
|
### 2. Create a Group for GeoIP Users
|
||||||
- After running `setup.sh`, verify that the crontab entries have been added correctly by listing the current user's crontab:
|
|
||||||
```bash
|
|
||||||
crontab -l
|
|
||||||
```
|
|
||||||
- You should see three new entries for running `geoip_updater.sh` with specific dates.
|
|
||||||
|
|
||||||
|
Create a group to manage access to the GeoIP data.
|
||||||
|
|
||||||
## Manual Execution
|
```bash
|
||||||
|
sudo groupadd geoipusers
|
||||||
|
```
|
||||||
|
**Note: Log out and back in for the group change to take effect.**
|
||||||
|
|
||||||
After setup, the `geoip_updater.sh` script will run automatically according to the schedule set in the crontab. However, you can also run the script manually at any time by executing:
|
### 3. Set Permissions and Ownership
|
||||||
|
|
||||||
|
Change the group ownership of the `/usr/local/share/GeoIP` directory to
|
||||||
|
`geoipusers`, and set the appropriate permissions.
|
||||||
|
|
||||||
|
```bash
|
||||||
|
sudo chown :geoipusers /usr/local/share/GeoIP
|
||||||
|
sudo chmod 775 /usr/local/share/GeoIP
|
||||||
|
```
|
||||||
|
|
||||||
|
### 4. Add Your User to the GeoIP Users Group
|
||||||
|
|
||||||
|
Add your user account to the `geoipusers` group to allow script execution and
|
||||||
|
access to the GeoIP directory.
|
||||||
|
|
||||||
|
```bash
|
||||||
|
sudo usermod -a -G geoipusers $USER
|
||||||
|
```
|
||||||
|
|
||||||
|
*Note: You may need to log out and log back in for the group changes to take effect.*
|
||||||
|
|
||||||
|
### 5. Install the Script
|
||||||
|
|
||||||
|
Copy the script to a globally accessible location and ensure it is executable:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
sudo cp geoip_updater.sh /usr/local/bin/
|
||||||
|
sudo chown :geoipusers /usr/local/bin/geoip_updater.sh
|
||||||
|
sudo chmod +x /usr/local/bin/geoip_updater.sh
|
||||||
|
```
|
||||||
|
|
||||||
|
### 6. Schedule the Script in Crontab
|
||||||
|
|
||||||
|
Edit your crontab to run the script automatically:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
crontab -e
|
||||||
|
```
|
||||||
|
|
||||||
|
Add the following line to schedule the script to run daily at 2 AM:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
0 2 * * * /usr/local/bin/geoip_updater.sh >> /var/log/geoip_update.log 2>&1
|
||||||
|
```
|
||||||
|
|
||||||
|
### 7. Prepare the Log File
|
||||||
|
|
||||||
|
Make sure the script can write to the log file:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
sudo touch /var/log/geoip_update.log
|
||||||
|
sudo chown :geoipusers /var/log/geoip_update.log
|
||||||
|
sudo chmod 664 /var/log/geoip_update.log
|
||||||
|
```
|
||||||
|
|
||||||
|
## Running the Script
|
||||||
|
|
||||||
|
The script will run as scheduled in the crontab. You can also execute it
|
||||||
|
manually at any time:
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
/usr/local/bin/geoip_updater.sh
|
/usr/local/bin/geoip_updater.sh
|
||||||
```
|
```
|
||||||
|
|
||||||
Optionally, you can specify a date as an argument to manually check and download the database for a specific date:
|
|
||||||
|
|
||||||
```bash
|
|
||||||
/usr/local/bin/geoip_updater.sh YYYY-MM-DD
|
|
||||||
```
|
|
||||||
|
|
||||||
## Troubleshooting
|
## Troubleshooting
|
||||||
|
|
||||||
- If the script does not run as scheduled, ensure that the `crontab` entries are set correctly and that `geoip_updater.sh` is executable.
|
- Ensure the script is executable and the `/var/log/geoip_update.log` file is writable.
|
||||||
- Check the log file `/var/log/geoip_update.log` for any errors or messages output by the script.
|
- Verify the crontab entry if the script does not run as expected.
|
||||||
|
- Check the log file `/var/log/geoip_update.log` for errors if the script fails.
|
||||||
|
@ -61,19 +61,13 @@ download_geoip_package() {
|
|||||||
|
|
||||||
# Extract the MMDB file from the downloaded package
|
# Extract the MMDB file from the downloaded package
|
||||||
extract_mmdb() {
|
extract_mmdb() {
|
||||||
# Ensure extraction occurs in a temporary directory to avoid leaving behind unwanted folders
|
MMDB_PATH=$(tar -tzf "/tmp/${FN}" | grep "${MMDB}" || true)
|
||||||
pushd /tmp >/dev/null
|
|
||||||
MMDB_PATH=$(tar -tzf "${FN}" | grep "${MMDB}" || true)
|
|
||||||
if [ -n "$MMDB_PATH" ]; then
|
if [ -n "$MMDB_PATH" ]; then
|
||||||
tar -xzf "${FN}" "${MMDB_PATH}" && mv "${MMDB_PATH}" "$DEST"
|
tar -xzf "/tmp/${FN}" "${MMDB_PATH}" && mv "$MMDB_PATH" $DEST
|
||||||
else
|
else
|
||||||
echo "Failed to find ${MMDB} in the tarball." >&2
|
echo "Failed to find ${MMDB} in the tarball." >&2
|
||||||
popd >/dev/null
|
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
# Cleanup the temporary directory by removing any extracted directories
|
|
||||||
rm -rf "$(dirname "${MMDB_PATH}")"
|
|
||||||
popd >/dev/null
|
|
||||||
}
|
}
|
||||||
|
|
||||||
# Clean up the temporary files
|
# Clean up the temporary files
|
||||||
|
Loading…
Reference in New Issue
Block a user