Skip to content
This repository has been archived by the owner on Apr 18, 2023. It is now read-only.

Commit

Permalink
ready for release
Browse files Browse the repository at this point in the history
  • Loading branch information
MCUmbrella committed Feb 18, 2022
1 parent 7a14cc9 commit a9aa6fc
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 21 deletions.
9 changes: 8 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,12 @@

## Usage
```shell
$ java -jar AUpdater.jar [configPath] [--test]
java -jar AUpdater.jar [configPath] [--test]
```
- `configPath`: path to the config file. Default is "./aupdater.properties"
- `--test`: check the config file and exit.

## Extra
- The systemd service file is included, and you can use it to start the client automatically.
Remember to check the location of the program and the config file. Change them if necessary.
- The detailed usage of DNSPod API can be found at https://docs.dnspod.cn/api/
43 changes: 23 additions & 20 deletions src/main/java/vip/floatationdevice/aupdater/AUpdater.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ public class AUpdater

// default config file path: "./aupdater.properties"
// can be overridden by command line argument
static String configPath ="aupdater.properties";
static String configPath = "aupdater.properties";

static String
login_token,
Expand Down Expand Up @@ -46,7 +46,7 @@ public class AUpdater
public static void main(String[] args)
{
// override default config path?
switch(args.length)
switch (args.length)
{
case 0:
break;
Expand All @@ -66,14 +66,14 @@ public static void main(String[] args)
loadConfig();
System.out.println("Config loaded");
// just a test?
if(args.length == 2)
if (args.length == 2)
{
if(args[1].equals("--test"))
if (args[1].equals("--test"))
{
System.out.println("=================================================="
+ "\nConfig file test passed:"
+ "\n login_token = " + login_token
+ "\n token_id = "+ token_id
+ "\n token_id = " + token_id
+ "\n domain_id = " + domain_id
+ "\n subdomain_id = " + subdomain_id
+ "\n subdomain_name = " + subdomain_name
Expand All @@ -90,7 +90,7 @@ public static void main(String[] args)
System.exit(1);
}
}
}catch (Exception e)
} catch (Exception e)
{
System.err.println("Error loading config file");
e.printStackTrace();
Expand All @@ -103,11 +103,11 @@ public static void main(String[] args)
System.out.println("Getting previous IP record");
prevIP = getPreviousIP();
System.out.println("Previous IP: " + prevIP);
}catch (Exception e)
} catch (Exception e)
{
System.err.println("Getting previous IP address failed");
e.printStackTrace();
prevIP="0.0.0.0";
prevIP = "0.0.0.0";
}

// run updater loop
Expand All @@ -121,21 +121,21 @@ public static void main(String[] args)
System.out.println("Getting local IP address");
ip = getLocalIP();
System.out.println("Local IP: " + ip);
}catch(Exception e)
} catch (Exception e)
{
System.err.println("Getting local IP address failed");
e.printStackTrace();
ip = prevIP;
System.out.println("Next update scheduled in "+update_interval_minutes_err+" minute(s)");
Thread.sleep((long)update_interval_minutes_err*60*1000);
System.out.println("Next update scheduled in " + update_interval_minutes_err + " minute(s)");
Thread.sleep((long) update_interval_minutes_err * 60 * 1000);
continue;
}

// skip if ip is the same as previous
if(ip.equals(prevIP))
if (ip.equals(prevIP))
{
System.out.println("IP address is the same as previous one\nNext update scheduled in "+update_interval_minutes+" minute(s)");
Thread.sleep((long)update_interval_minutes*60*1000);
System.out.println("IP address is the same as previous one\nNext update scheduled in " + update_interval_minutes + " minute(s)");
Thread.sleep((long) update_interval_minutes * 60 * 1000);
continue;
}

Expand All @@ -145,20 +145,23 @@ public static void main(String[] args)
System.out.println("Updating record");
updateRecord();
System.out.println("Update record success: " + prevIP + " to " + ip);
}catch(Exception e)
} catch (Exception e)
{
System.err.println("Failed to update record");
e.printStackTrace();
System.out.println("Next update scheduled in " + update_interval_minutes_err + " minute(s)");
Thread.sleep((long)update_interval_minutes_err*60*1000);
Thread.sleep((long) update_interval_minutes_err * 60 * 1000);
continue;
}

// update previous ip, sleep for 30 minutes
prevIP=ip;
prevIP = ip;
System.out.println("Next update scheduled in " + update_interval_minutes + " minute(s)");
Thread.sleep((long)update_interval_minutes*60*1000);
}while(true);
}catch (InterruptedException e){e.printStackTrace();}
Thread.sleep((long) update_interval_minutes * 60 * 1000);
} while (true);
} catch (InterruptedException e)
{
e.printStackTrace();
}
}
}

0 comments on commit a9aa6fc

Please sign in to comment.