-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpowershell_script.ps1
More file actions
48 lines (41 loc) · 1.59 KB
/
Copy pathpowershell_script.ps1
File metadata and controls
48 lines (41 loc) · 1.59 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
# Script Parameters
$repoUrl = "git@github.com:your_name/IPv6AddressUpdater.git" # Your Gitee repository URL
$localRepoPath = "C:\Users\your_name\IPv6AddressUpdater" # Local repository path
$ipv6FilePath = "ipv6_address.txt" # Filename to store the IPv6 address
# Function: Get the current IPv6 address
function Get-IPv6Address {
ipconfig | Select-String -Pattern "(([0-9a-fA-F]{1,4}:){7}[0-9a-fA-F]{1,4})" | ForEach-Object { $_.Matches.Groups[0].Value }
}
# Function: Push to Gitee
function Push-To-Gitee($localRepoPath, $ipv6FilePath, $repoUrl, $currentIPv6) {
# Switch to the local repository path
Push-Location $localRepoPath
# Ensure the local repository is initialized and has the remote set
if (-not (Test-Path ".git")) {
git init
git remote add origin $repoUrl
}
# Fetch the latest remote repository info
git fetch origin master
git reset --hard origin/master
# Check if the IPv6 address has changed
$lastIPv6 = Get-Content -Path $ipv6FilePath -ErrorAction SilentlyContinue
if ($lastIPv6 -ne $currentIPv6) {
# IPv6 address has changed, update the file and push
$currentIPv6 | Out-File -FilePath $ipv6FilePath
git add $ipv6FilePath
git commit -m "Update IPv6 address"
git push -u origin master
} else {
Write-Host "IPv6 address has not changed."
}
# Switch back to the previous path
Pop-Location
}
# Main Logic
$currentIPv6 = Get-IPv6Address
if ($currentIPv6) {
Push-To-Gitee $localRepoPath $ipv6FilePath $repoUrl $currentIPv6
} else {
Write-Host "No IPv6 address found."
}