промежуточный коммит
This commit is contained in:
parent
b6489a5838
commit
5d711a49cb
45
app/pom.xml
45
app/pom.xml
|
|
@ -36,7 +36,7 @@
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>com.hierynomus</groupId>
|
<groupId>com.hierynomus</groupId>
|
||||||
<artifactId>sshj</artifactId>
|
<artifactId>sshj</artifactId>
|
||||||
<version>0.39.0</version>
|
<version>0.40.0</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
<!-- https://mvnrepository.com/artifact/org.eclipse.jetty/jetty-server -->
|
<!-- https://mvnrepository.com/artifact/org.eclipse.jetty/jetty-server -->
|
||||||
|
|
@ -49,6 +49,45 @@
|
||||||
|
|
||||||
<build>
|
<build>
|
||||||
<plugins>
|
<plugins>
|
||||||
|
<plugin>
|
||||||
|
<groupId>org.apache.maven.plugins</groupId>
|
||||||
|
<artifactId>maven-shade-plugin</artifactId>
|
||||||
|
<version>1.4</version>
|
||||||
|
<executions>
|
||||||
|
<execution>
|
||||||
|
<phase>package</phase>
|
||||||
|
<goals>
|
||||||
|
<goal>shade</goal>
|
||||||
|
</goals>
|
||||||
|
</execution>
|
||||||
|
</executions>
|
||||||
|
<configuration>
|
||||||
|
<filters>
|
||||||
|
<filter>
|
||||||
|
<artifact>*:*</artifact>
|
||||||
|
<excludes>
|
||||||
|
<exclude>module-info.class</exclude>
|
||||||
|
<exclude>JDOMAbout*class</exclude>
|
||||||
|
<exclude>META-INF/*.SF</exclude>
|
||||||
|
<exclude>META-INF/*.DSA</exclude>
|
||||||
|
<exclude>META-INF/*.RSA</exclude>
|
||||||
|
</excludes>
|
||||||
|
</filter>
|
||||||
|
</filters>
|
||||||
|
<transformers>
|
||||||
|
<transformer
|
||||||
|
implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
|
||||||
|
<manifestEntries>
|
||||||
|
<Main-Class>ru.kirillius.pf.sdn.App</Main-Class>
|
||||||
|
</manifestEntries>
|
||||||
|
</transformer>
|
||||||
|
</transformers>
|
||||||
|
<shadedArtifactAttached>true
|
||||||
|
</shadedArtifactAttached> <!-- Make the shaded artifact not the main one -->
|
||||||
|
<shadedClassifierName>shaded</shadedClassifierName> <!-- set the suffix to the shaded jar -->
|
||||||
|
</configuration>
|
||||||
|
</plugin>
|
||||||
|
|
||||||
<plugin>
|
<plugin>
|
||||||
<groupId>org.codehaus.mojo</groupId>
|
<groupId>org.codehaus.mojo</groupId>
|
||||||
<artifactId>exec-maven-plugin</artifactId>
|
<artifactId>exec-maven-plugin</artifactId>
|
||||||
|
|
@ -69,6 +108,10 @@
|
||||||
</execution>
|
</execution>
|
||||||
</executions>
|
</executions>
|
||||||
</plugin>
|
</plugin>
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
</plugins>
|
</plugins>
|
||||||
</build>
|
</build>
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,155 @@
|
||||||
|
#!/bin/sh
|
||||||
|
|
||||||
|
# Пути по умолчанию
|
||||||
|
DEFAULT_CFGPATH="/etc/pfsdn.json"
|
||||||
|
DEFAULT_LIBRARY="/var/lib/pfsdn"
|
||||||
|
DEFAULT_REPO_URL="https://repo.kirillius.ru/apps/pf/"
|
||||||
|
|
||||||
|
# Функция для извлечения значений из аргументов
|
||||||
|
get_arg_value() {
|
||||||
|
local arg_name="$1"
|
||||||
|
local default_value="$2"
|
||||||
|
local value="$default_value"
|
||||||
|
|
||||||
|
# Ищем аргумент в формате -arg=value или --arg=value
|
||||||
|
for arg in "${@:3}"; do
|
||||||
|
case "$arg" in
|
||||||
|
-$arg_name=*|--$arg_name=*)
|
||||||
|
value="${arg#*=}"
|
||||||
|
break
|
||||||
|
;;
|
||||||
|
esac
|
||||||
|
done
|
||||||
|
echo "$value"
|
||||||
|
}
|
||||||
|
|
||||||
|
# Получаем пути из аргументов или используем значения по умолчанию
|
||||||
|
CFGPATH=$(get_arg_value "c" "$DEFAULT_CFGPATH" "$@")
|
||||||
|
LIBRARY=$(get_arg_value "l" "$DEFAULT_LIBRARY" "$@")
|
||||||
|
REPO_URL=$(get_arg_value "r" "$DEFAULT_REPO_URL" "$@")
|
||||||
|
|
||||||
|
# Выводим рабочие каталоги
|
||||||
|
echo "Config path: $CFGPATH"
|
||||||
|
echo "Library path: $LIBRARY"
|
||||||
|
echo "Repository URL: $REPO_URL"
|
||||||
|
|
||||||
|
# Проверяем наличие Java в системе и версию
|
||||||
|
if ! command -v java >/dev/null 2>&1; then
|
||||||
|
echo "Java not found. Please install java, openjdk or JRE" >&2
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Проверяем версию Java (должна быть >= 21)
|
||||||
|
check_java_version() {
|
||||||
|
local java_version
|
||||||
|
java_version=$(java -version 2>&1 | head -n 1 | sed 's/.*"\([0-9]*\)\.[0-9]*\.[0-9]*".*/\1/')
|
||||||
|
|
||||||
|
if [ -z "$java_version" ] || [ "$java_version" -lt 21 ]; then
|
||||||
|
echo "Java version 21 or higher is required. Found version: $java_version" >&2
|
||||||
|
return 1
|
||||||
|
fi
|
||||||
|
echo "Java version check passed: $java_version"
|
||||||
|
return 0
|
||||||
|
}
|
||||||
|
|
||||||
|
if ! check_java_version; then
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Проверяем и создаем директорию LIBRARY если не существует
|
||||||
|
if [ ! -d "$LIBRARY" ]; then
|
||||||
|
echo "Library directory not found: $LIBRARY"
|
||||||
|
echo "Creating directory: $LIBRARY"
|
||||||
|
if ! mkdir -p "$LIBRARY"; then
|
||||||
|
echo "Failed to create library directory: $LIBRARY" >&2
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
echo "Directory created successfully"
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Функция для поиска последней версии в директории
|
||||||
|
find_local_version() {
|
||||||
|
find "$LIBRARY" -maxdepth 1 -name "*.pfapp" -type f | grep -E '[0-9]+\.[0-9]+\.[0-9]+\.[0-9]+\.pfapp' | sort -V | tail -n 1
|
||||||
|
}
|
||||||
|
|
||||||
|
# Функция для скачивания версии с веб-страницы
|
||||||
|
download_latest_version() {
|
||||||
|
local repo_url="$REPO_URL"
|
||||||
|
echo "Searching for latest version on $repo_url..."
|
||||||
|
|
||||||
|
# Получаем HTML страницу и извлекаем ссылки на .pfapp файлы
|
||||||
|
local latest_file=$(curl -s "$repo_url" | grep -oE 'href="[0-9]+\.[0-9]+\.[0-9]+\.[0-9]+\.pfapp"' | sed 's/href="//g' | sed 's/"//g' | sort -V | tail -n 1)
|
||||||
|
|
||||||
|
if [ -z "$latest_file" ]; then
|
||||||
|
echo "No .pfapp files found on the repository" >&2
|
||||||
|
return 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
local download_url="${repo_url}${latest_file}"
|
||||||
|
local local_path="$LIBRARY/$latest_file"
|
||||||
|
|
||||||
|
echo "Downloading version: $latest_file"
|
||||||
|
echo "From: $download_url"
|
||||||
|
echo "To: $local_path"
|
||||||
|
|
||||||
|
# Скачиваем файл
|
||||||
|
if curl -s -o "$local_path" "$download_url"; then
|
||||||
|
echo "Successfully downloaded $latest_file"
|
||||||
|
# Возвращаем ТОЛЬКО путь к файлу, без дополнительных сообщений
|
||||||
|
echo "$local_path"
|
||||||
|
else
|
||||||
|
echo "Failed to download $latest_file" >&2
|
||||||
|
return 1
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
# Находим последнюю версию файла
|
||||||
|
VER_FILE=$(find_local_version)
|
||||||
|
|
||||||
|
# Если не нашли файлы локально, скачиваем с веб-страницы
|
||||||
|
if [ -z "$VER_FILE" ]; then
|
||||||
|
echo "No local .pfapp files found, downloading from repository..."
|
||||||
|
# Сохраняем вывод функции в временную переменную, чтобы показать сообщения
|
||||||
|
DOWNLOAD_OUTPUT=$(download_latest_version)
|
||||||
|
if [ $? -ne 0 ]; then
|
||||||
|
echo "Failed to download application file" >&2
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
# Извлекаем последнюю строку (путь к файлу) из вывода
|
||||||
|
VER_FILE=$(echo "$DOWNLOAD_OUTPUT" | tail -n 1)
|
||||||
|
|
||||||
|
# Выводим все сообщения кроме последней строки
|
||||||
|
echo "$DOWNLOAD_OUTPUT" | head -n -1
|
||||||
|
else
|
||||||
|
# Выводим информацию о найденной локальной версии
|
||||||
|
VER=$(basename "$VER_FILE")
|
||||||
|
VER="${VER%.pfapp}"
|
||||||
|
echo "Using local version: $VER"
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Извлекаем только имя файла (без пути)
|
||||||
|
VER=$(basename "$VER_FILE")
|
||||||
|
|
||||||
|
# Убираем расширение .pfapp чтобы получить чистую версию
|
||||||
|
VER="${VER%.pfapp}"
|
||||||
|
|
||||||
|
# Выводим финальную информацию о версии
|
||||||
|
echo "Starting application version: $VER"
|
||||||
|
|
||||||
|
# Функция для запуска Java
|
||||||
|
run_java() {
|
||||||
|
java -jar "$LIBRARY/$VER.pfapp" -c="$CFGPATH" -l="$LIBRARY" -r="$REPO_URL"
|
||||||
|
}
|
||||||
|
|
||||||
|
# Запускаем Java с возможностью перезапуска при коде возврата 303
|
||||||
|
while true; do
|
||||||
|
run_java
|
||||||
|
EXIT_CODE=$?
|
||||||
|
|
||||||
|
if [ $EXIT_CODE -eq 303 ]; then
|
||||||
|
echo "Restarting application (exit code 303)..."
|
||||||
|
continue
|
||||||
|
else
|
||||||
|
exit $EXIT_CODE
|
||||||
|
fi
|
||||||
|
done
|
||||||
|
|
@ -52,11 +52,34 @@
|
||||||
</manifestEntries>
|
</manifestEntries>
|
||||||
</transformer>
|
</transformer>
|
||||||
</transformers>
|
</transformers>
|
||||||
<shadedArtifactAttached>true</shadedArtifactAttached> <!-- Make the shaded artifact not the main one -->
|
<shadedArtifactAttached>true
|
||||||
|
</shadedArtifactAttached> <!-- Make the shaded artifact not the main one -->
|
||||||
<shadedClassifierName>shaded</shadedClassifierName> <!-- set the suffix to the shaded jar -->
|
<shadedClassifierName>shaded</shadedClassifierName> <!-- set the suffix to the shaded jar -->
|
||||||
</configuration>
|
</configuration>
|
||||||
</plugin>
|
</plugin>
|
||||||
|
|
||||||
|
<plugin>
|
||||||
|
<groupId>org.apache.maven.plugins</groupId>
|
||||||
|
<artifactId>maven-antrun-plugin</artifactId>
|
||||||
|
<version>3.1.0</version>
|
||||||
|
<executions>
|
||||||
|
<execution>
|
||||||
|
<phase>package</phase>
|
||||||
|
<goals>
|
||||||
|
<goal>run</goal>
|
||||||
|
</goals>
|
||||||
|
<configuration>
|
||||||
|
<target>
|
||||||
|
<concat destfile="target/ovpn-pfsdn-bind" append="true" binary="true">
|
||||||
|
<fileset file="../unix-wrapper.sh"/>
|
||||||
|
<fileset file="target/ovpn-connector-${project.version}-shaded.jar"/>
|
||||||
|
</concat>
|
||||||
|
<chmod file="target/ovpn-pfsdn-bind" perm="755"/>
|
||||||
|
</target>
|
||||||
|
</configuration>
|
||||||
|
</execution>
|
||||||
|
</executions>
|
||||||
|
</plugin>
|
||||||
|
|
||||||
</plugins>
|
</plugins>
|
||||||
</build>
|
</build>
|
||||||
|
|
|
||||||
59
pom.xml
59
pom.xml
|
|
@ -22,6 +22,62 @@
|
||||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||||
</properties>
|
</properties>
|
||||||
|
|
||||||
|
<!-- в root/pom.xml -->
|
||||||
|
<profiles>
|
||||||
|
<profile>
|
||||||
|
<id>assembly</id>
|
||||||
|
<activation>
|
||||||
|
<property>
|
||||||
|
<name>project.packaging</name>
|
||||||
|
<value>pom</value>
|
||||||
|
</property>
|
||||||
|
</activation>
|
||||||
|
<build>
|
||||||
|
<plugins>
|
||||||
|
<plugin>
|
||||||
|
<groupId>org.apache.maven.plugins</groupId>
|
||||||
|
<artifactId>maven-antrun-plugin</artifactId>
|
||||||
|
<version>3.1.0</version>
|
||||||
|
<executions>
|
||||||
|
<execution>
|
||||||
|
<id>post-build-assembly</id>
|
||||||
|
<phase>verify</phase> <!-- выполнится после сборки всех модулей -->
|
||||||
|
<goals>
|
||||||
|
<goal>run</goal>
|
||||||
|
</goals>
|
||||||
|
<configuration>
|
||||||
|
<target>
|
||||||
|
<!-- 1. Создать папку target (для root) -->
|
||||||
|
<mkdir dir="${project.build.directory}"/>
|
||||||
|
|
||||||
|
<!-- 2. Копировать app/target/app-$VERSION-shaded.jar -> target/$VERSION.pfapp -->
|
||||||
|
<copy file="${basedir}/app/target/app-${project.version}-shaded.jar"
|
||||||
|
tofile="${project.build.directory}/${project.version}.pfapp"
|
||||||
|
overwrite="true"/>
|
||||||
|
|
||||||
|
<!-- 3. Копировать launcher.sh -> target/pfsdnd и сделать исполняемым -->
|
||||||
|
<copy file="${basedir}/launcher.sh"
|
||||||
|
tofile="${project.build.directory}/pfsdnd"
|
||||||
|
overwrite="true"/>
|
||||||
|
<!-- Делаем файл исполняемым (для Unix/Linux) -->
|
||||||
|
<chmod file="${project.build.directory}/pfsdnd" perm="755"/>
|
||||||
|
|
||||||
|
<!-- 4. Копировать ovpn-connector/target/ovpn-pfsdn-bind -> target/ -->
|
||||||
|
<copy file="${basedir}/ovpn-connector/target/ovpn-pfsdn-bind"
|
||||||
|
tofile="${project.build.directory}/ovpn-pfsdn-bind"
|
||||||
|
overwrite="true"/>
|
||||||
|
<!-- Также делаем исполняемым -->
|
||||||
|
<chmod file="${project.build.directory}/ovpn-pfsdn-bind" perm="755"/>
|
||||||
|
</target>
|
||||||
|
</configuration>
|
||||||
|
</execution>
|
||||||
|
</executions>
|
||||||
|
</plugin>
|
||||||
|
</plugins>
|
||||||
|
</build>
|
||||||
|
</profile>
|
||||||
|
</profiles>
|
||||||
|
|
||||||
<build>
|
<build>
|
||||||
<plugins>
|
<plugins>
|
||||||
<plugin>
|
<plugin>
|
||||||
|
|
@ -41,6 +97,8 @@
|
||||||
</annotationProcessorPaths>
|
</annotationProcessorPaths>
|
||||||
</configuration>
|
</configuration>
|
||||||
</plugin>
|
</plugin>
|
||||||
|
|
||||||
|
|
||||||
</plugins>
|
</plugins>
|
||||||
</build>
|
</build>
|
||||||
|
|
||||||
|
|
@ -96,4 +154,5 @@
|
||||||
|
|
||||||
</dependencies>
|
</dependencies>
|
||||||
|
|
||||||
|
|
||||||
</project>
|
</project>
|
||||||
|
|
@ -0,0 +1,17 @@
|
||||||
|
#!/bin/sh
|
||||||
|
|
||||||
|
# Проверяем наличие Java в системе
|
||||||
|
if ! which java >/dev/null 2>&1; then
|
||||||
|
echo "Java not found. Please install java, openjdk or JRE" >&2
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Получаем полный путь к текущему скрипту
|
||||||
|
SCRIPT_PATH="$0"
|
||||||
|
|
||||||
|
# Запускаем Java с текущим скриптом как параметром и всеми переданными аргументами
|
||||||
|
java -jar "$SCRIPT_PATH" $@
|
||||||
|
|
||||||
|
exit
|
||||||
|
|
||||||
|
|
||||||
Loading…
Reference in New Issue