feat:首次提交

This commit is contained in:
lujinlin 2024-12-17 18:07:41 +08:00
commit c2e191c8bd
37 changed files with 1024 additions and 0 deletions

5
lsy-loader/build.sh Executable file
View File

@ -0,0 +1,5 @@
dpkg-deb --build lsyloader
ver=$(dpkg-deb --show lsyloader.deb|awk '{print $2}')
echo `sha256sum lsyloader.deb` >> "lsyloader$ver.debSign"
mv lsyloader.deb lsyloader$ver.deb
chmod 777 *.deb

11
lsy-loader/install.sh Executable file
View File

@ -0,0 +1,11 @@
cur_dir=$(dirname "$(realpath "$0")")
# sudo dpkg -i lsyloader1.0.0.deb
cp *.deb /tmp/
# deb必须放在/tmp这种有自由权限的目录
# apt会自动处理依赖关系
sudo apt install -y --allow-downgrades "/tmp/lsyloader1.0.0.deb"

View File

@ -0,0 +1,8 @@
Package: lsyloader
Version: 1.0.1
Section: utils
Priority: optional
Architecture: amd64
Maintainer: lsy@mail.com
Depends: systemd (>= 240), libc6 (>= 2.28)
Description: lsy udpate.

View File

@ -0,0 +1,11 @@
#!/bin/bash
#set -e
# Reload systemd configurations
systemctl daemon-reload
# Enable the service to start on boot
systemctl enable lsyloader.service
# Start the service
systemctl start lsyloader.service

View File

@ -0,0 +1,9 @@
#!/bin/bash
#set -e
systemctl disable lsyloader.service >/dev/null 2>&1 || true
rm -f /lib/systemd/system/lsyloader.service
rm -f /data/lsyloader/lsyloader.log
systemctl daemon-reload

View File

@ -0,0 +1,10 @@
#!/bin/bash
#set -e
# Stop the service if running
if systemctl is-active --quiet lsyloader.service; then
systemctl stop lsyloader.service
fi
# Disable the service
systemctl disable lsyloader.service

View File

@ -0,0 +1,259 @@
#!/bin/bash
jsonIn=""
#### jsonIn=version接口
# {
# "version": "1.0.5",
# "name": "lsyloader",
# "path": "http://192.168.200.128:5212/versionFile?filename=lsyloader1.0.5.deb",
# "sign": "a0d47ccb8edaa029e2c1262a8351674846e4c055c798ad63c55851fa5dff7059"
# }
cur_dir=$(dirname "$(realpath "$0")")
mkdir -p "/tmp/log"
logFile="/tmp/log/lsyloader.log"
maxLogSize=$((1024*1024*3))
versionLocal="1.0.0"
url="https://deb.jxm.cool/deb/version.ini"
# 只处理
pkgNameArrOnly=("lsyupdate")
# 除了这些都处理,一般是自己, pkgNameArrOnly存在时pkgNameArrExcept无效
pkgNameArrExcept=("lsyloader")
pkgName=""
pkgUrl=""
pkgVersion=""
pkgSign=""
outPath="$cur_dir/out.deb"
function initLog() {
[ ! -e "$logFile" ] && return
local size=`ls -al "$logFile" |awk '{print $5}'`
echo $size
[ $size -gt $maxLogSize ] && rm -rf "$logFile"
}
function freshNow() {
nowtime=`date +"%Y-%m-%d %H:%M:%S"`
}
function get_json_value() {
awk -v json="$1" -v key="$2" -v defaultValue="$3" 'BEGIN{
foundKeyCount = 0
while (length(json) > 0) {
# pos = index(json, "\""key"\""); ## 这行更快一些但是如果有value是字符串且刚好与要查找的key相同会被误认为是key而导致值获取错误
pos = match(json, "\""key"\"[ \\t]*?:[ \\t]*");
if (pos == 0) {if (foundKeyCount == 0) {print defaultValue;} exit 0;}
++foundKeyCount;
start = 0; stop = 0; layer = 0;
for (i = pos + length(key) + 1; i <= length(json); ++i) {
lastChar = substr(json, i - 1, 1)
currChar = substr(json, i, 1)
if (start <= 0) {
if (lastChar == ":") {
start = currChar == " " ? i + 1: i;
if (currChar == "{" || currChar == "[") {
layer = 1;
}
}
} else {
if (currChar == "{" || currChar == "[") {
++layer;
}
if (currChar == "}" || currChar == "]") {
--layer;
}
if ((currChar == "," || currChar == "}" || currChar == "]") && layer <= 0) {
stop = currChar == "," ? i : i + 1 + layer;
break;
}
}
}
if (start <= 0 || stop <= 0 || start > length(json) || stop > length(json) || start >= stop) {
if (foundKeyCount == 0) {print defaultValue;} exit 0;
} else {
print substr(json, start, stop - start);
}
json = substr(json, stop + 1, length(json) - stop)
}
}'
}
# split_str "${tmp_data}" "|"
split_str_return_list=()
function split_str() {
local str_data=$1
local str_pattern=$2
str=$str_data
delimiter=$str_pattern
array=()
while [ "$str" ]; do
substring="${str%%"$delimiter"*}"
[ -z "$substring" ] && str="${str#"$delimiter"}" && continue
array+=( "$substring" )
str="${str:${#substring}}"
[ "$str" == "$delimiter" ] && break
done
#declare -p array
split_str_return_list=()
for var in "${array[@]}"; do
#echo "[v]=${var}"
split_str_return_list+=( "${var}" )
done
}
function trimL() {
local str=$1
local toTrim=$2
local dst=${str#$toTrim}
echo $dst
}
function trimR() {
local str=$1
local toTrim=$2
local dst=${str%$toTrim}
echo $dst
}
function trim() {
local str=$1
local toTrim=$2
str=${str#$toTrim}
local dst=${str%$toTrim}
echo $dst
}
function hasVersion() {
nowtime=`date +"%Y-%m-%d %H:%M:%S"`
echo "[$nowtime] hasVersion start" >> $logFile
local str_ack=$jsonIn
nowtime=`date +"%Y-%m-%d %H:%M:%S"`
echo "[$nowtime] hasVersion done,$str_ack" >> $logFile
pkgUrl=$(get_json_value "$str_ack" "path" "")
pkgVersion=$(get_json_value "$str_ack" "version" "-1")
pkgSign=$(get_json_value "$str_ack" "sign" "")
pkgName=$(get_json_value "$str_ack" "name" "")
pkgUrl=$(trim "$pkgUrl" "\"")
pkgSign=$(trim "$pkgSign" "\"")
pkgName=$(trim "$pkgName" "\"")
[ -z "$pkgName" ] && echo "pkgName is empty skip" >> $logFile && return 0
# pkgNameArrOnly
local found=false
for item in "${pkgNameArrOnly[@]}"; do
if [[ "$item" == "$pkgName" ]]; then
found=true
break
fi
done
[ ${#pkgNameArrOnly[@]} -ne 0 ] && [ "$found" == false ] && echo "pkgName not in $pkgNameArrOnly skip" >> $logFile && return 0
# pkgNameArrExcept
for item in "${pkgNameArrExcept[@]}"; do
if [[ "$item" == "$pkgName" ]]; then
echo "pkgName in $pkgNameArrExcept skip" >> $logFile && return 0
fi
done
versionLocal=$(apt show "$pkgName"|grep "Version:"|head -n 1|awk '{print $2}')
[ "$versionLocal" == "" ] && versionLocal="1.0.0"
outPath="$cur_dir/$pkgName.deb"
version=$(trim "$pkgVersion" "\"")
split_str "${version}" "."
len=${#split_str_return_list[@]}
if [ $len -lt 3 ];then
return 0
fi
local v1=${split_str_return_list[0]}
local v2=${split_str_return_list[1]}
local v3=${split_str_return_list[2]}
split_str "${versionLocal}" "."
local lv1=${split_str_return_list[0]}
local lv2=${split_str_return_list[1]}
local lv3=${split_str_return_list[2]}
echo "[$nowtime] pkgVersion=$pkgVersion" >> $logFile
echo "[$nowtime] pkgUrl=$pkgUrl" >> $logFile
echo "[$nowtime] pkgSign=$pkgSign" >> $logFile
echo "[$nowtime] pkgName=$pkgName" >> $logFile
[ -z "$pkgUrl" ] && echo "[$nowtime] pkgurl empty skip" >> $logFile && return 0
[ -z "$pkgSign" ] && echo "[$nowtime] pkgSign empty skip" >> $logFile && return 0
echo "[$nowtime] v=$v1.$v2.$v3" >> $logFile
echo "[$nowtime] lv=$lv1.$lv2.$lv3" >> $logFile
[ "$v1" -gt "$lv1" ] && return 1
[ "$v2" -gt "$lv2" ] && return 1
[ "$v3" -gt "$lv3" ] && return 1
return 0
}
function runInstall() {
nowtime=`date +"%Y-%m-%d %H:%M:%S"`
echo "[$nowtime] start..." >> $logFile
hasVersion
local bUpdate=$?
if [ $bUpdate -eq 0 ]; then
nowtime=`date +"%Y-%m-%d %H:%M:%S"`
echo "[$nowtime] no need to update" >> $logFile
return
fi
echo "[$nowtime] need update" >> $logFile
freshNow
rm -rf "$outPath"
str_ack=`wget -O "$outPath" $pkgUrl`
[ ! -e "$outPath" ] && echo "[$nowtime] $outPath not exist" >> $logFile && return
freshNow
local fileSign=`sha256sum "$outPath"|awk '{print $1}'`
echo "[$nowtime] get sign,fileSign=$fileSign,$outPath" >> $logFile
[ "$fileSign" != "$pkgSign" ] && echo "[$nowtime] $fileSign!=$pkgSign,$outPath skip" >> $logFile && return
chmod +x "$outPath"
echo "[$nowtime] start uninstall $outPath" >> $logFile
bash $cur_dir/uninstall.sh "$pkgName" >> $logFile
echo "[$nowtime] start install $outPath" >> $logFile
apt install -y --allow-downgrades "$outPath" >> $logFile
freshNow
echo "[$nowtime] finish" >> $logFile
}
function main() {
initLog
str_ack=$(
curl --request GET \
--url "$url" \
--header 'content-type: application/json' \
--data ""
)
apps=($(echo "$str_ack" | jq -c '.[]'))
for item in "${apps[@]}"; do
jsonIn=$item
runInstall
sleep 2
done
}
main

View File

@ -0,0 +1,7 @@
#!/bin/bash
cur_dir=$(dirname "$(realpath "$0")")
while true; do
bash "$cur_dir/lsydeb.sh"
sleep 20
done

View File

@ -0,0 +1,10 @@
#!/bin/bash
json_data=$(cat "/home/lyn/work/deb-pkg/lsy-loader/lsyloader/data/lsyloader/version.ini")
apps=($(echo "$json_data" | jq -c '.[]'))
# 输出每个元素
for item in "${apps[@]}"; do
echo "apps: $item"
done

View File

@ -0,0 +1,20 @@
#!/bin/bash
# "$appname"
appname=$1
[ -z "$appname" ] && echo "appname is empty skip" && exit 0
apt remove -y "$appname"
sudo systemctl stop "$appname".service
sudo systemctl disable "$appname".service
sudo dpkg -r "$appname"
sudo dpkg --purge "$appname"
sudo rm -rf /var/lib/dpkg/info/"$appname".*
systemctl disable "$appname".service >/dev/null 2>&1 || true
rm -f /lib/systemd/system/"$appname".service
#rm -f /data/"$appname".log
systemctl daemon-reload
dpkg --remove --force-remove-reinstreq "$appname"

View File

@ -0,0 +1,13 @@
[{
"version": "1.0.1",
"name": "lsyloader",
"path": "http://192.168.200.128:5212/versionFile?filename=lsyloader1.0.1.deb",
"sign": "3973118446a2c81db53803633ca84b287fe80197a707f5d7b8a6cfd712f30c0a"
},
{
"version": "1.0.3",
"name": "lsyupdate",
"path": "http://192.168.200.128:5212/versionFile?filename=lsyupdate1.0.3.deb",
"sign": "b990a391dc7b8fd2bce1f22c80be674a764d725f87bd706a81f6dd1225210010"
}
]

View File

@ -0,0 +1,12 @@
[Unit]
Description=lsy update Service
After=network.target
[Service]
ExecStart=/data/lsyloader/lsyloader.sh
Restart=always
User=root
Group=root
[Install]
WantedBy=multi-user.target

BIN
lsy-loader/lsyloader1.0.0.deb Executable file

Binary file not shown.

View File

@ -0,0 +1 @@
bc41b7e875a1303f8cb4bdf14b5352a56537aaf01dc265e5f929f6b71a8c722f lsyloader.deb

BIN
lsy-loader/lsyloader1.0.1.deb Executable file

Binary file not shown.

View File

@ -0,0 +1 @@
24708d46126cb647a0bd1fdf1b0beb49aee9091558c023ea0eed555005ca0e76 lsyloader.deb

6
lsy-loader/readme.md Normal file
View File

@ -0,0 +1,6 @@
[lsyloader]
only lsyupdate's update
[lsyupdate]
no lsyupdate, all others's update

2
lsy-loader/showVersion.sh Executable file
View File

@ -0,0 +1,2 @@
apt show lsyloader |grep Version

21
lsy-loader/uninstallAll.sh Executable file
View File

@ -0,0 +1,21 @@
#!/bin/bash
# "$appname"
appname=$1
[ -z "$appname" ] && appname="lsyloader"
[ -z "$appname" ] && echo "appname is empty skip" && exit 0
apt remove -y "$appname"
sudo systemctl stop "$appname".service
sudo systemctl disable "$appname".service
sudo dpkg -r "$appname"
sudo dpkg --purge "$appname"
sudo rm -rf /var/lib/dpkg/info/"$appname".*
systemctl disable "$appname".service >/dev/null 2>&1 || true
rm -f /lib/systemd/system/"$appname".service
rm -f /data/"$appname".log
systemctl daemon-reload
dpkg --remove --force-remove-reinstreq "$appname"

5
lsy-update/build.sh Executable file
View File

@ -0,0 +1,5 @@
dpkg-deb --build lsyupdate
ver=$(dpkg-deb --show lsyupdate.deb|awk '{print $2}')
mv lsyupdate.deb lsyupdate$ver.deb
echo `sha256sum "lsyupdate$ver.deb"`>>"lsyupdate$ver.debSign"
chmod 777 *.deb

11
lsy-update/install.sh Executable file
View File

@ -0,0 +1,11 @@
cur_dir=$(dirname "$(realpath "$0")")
# sudo dpkg -i lsyupdate1.0.0.deb
cp *.deb /tmp/
# deb必须放在/tmp这种有自由权限的目录
# apt会自动处理依赖关系
sudo apt install -y --allow-downgrades "/tmp/lsyupdate1.0.0.deb"

217
lsy-update/lsy_update-bak.sh Executable file
View File

@ -0,0 +1,217 @@
#!/bin/bash
#### version接口
# {
# "version": "1.2.3",
# "path": "http://192.168.200.128:5212/versionFile?filename=app1.2.3",
# "sign": "2d28d9af69d48c964abafaff97f6e9958ecf40a9ca6d62a7ae69e00b279c22f2"
# }
mkdir -p "/data"
logFile="/data/lsyudpate.log"
maxLogSize=$((1024*1024*3))
url="http://192.168.200.128:5212/version"
versionLocal="1.0.1"
pkgUrl=""
pkgVersion=""
pkgSign=""
outPath="out.deb"
function initLog() {
[ ! -e "$logFile" ] && return
local size=`ls -al "$logFile" |awk '{print $5}'`
echo $size
[ $size -gt $maxLogSize ] && rm -rf "$logFile"
}
function freshNow() {
nowtime=`date +"%Y-%m-%d %H:%M:%S"`
}
function get_json_value() {
awk -v json="$1" -v key="$2" -v defaultValue="$3" 'BEGIN{
foundKeyCount = 0
while (length(json) > 0) {
# pos = index(json, "\""key"\""); ## 这行更快一些但是如果有value是字符串且刚好与要查找的key相同会被误认为是key而导致值获取错误
pos = match(json, "\""key"\"[ \\t]*?:[ \\t]*");
if (pos == 0) {if (foundKeyCount == 0) {print defaultValue;} exit 0;}
++foundKeyCount;
start = 0; stop = 0; layer = 0;
for (i = pos + length(key) + 1; i <= length(json); ++i) {
lastChar = substr(json, i - 1, 1)
currChar = substr(json, i, 1)
if (start <= 0) {
if (lastChar == ":") {
start = currChar == " " ? i + 1: i;
if (currChar == "{" || currChar == "[") {
layer = 1;
}
}
} else {
if (currChar == "{" || currChar == "[") {
++layer;
}
if (currChar == "}" || currChar == "]") {
--layer;
}
if ((currChar == "," || currChar == "}" || currChar == "]") && layer <= 0) {
stop = currChar == "," ? i : i + 1 + layer;
break;
}
}
}
if (start <= 0 || stop <= 0 || start > length(json) || stop > length(json) || start >= stop) {
if (foundKeyCount == 0) {print defaultValue;} exit 0;
} else {
print substr(json, start, stop - start);
}
json = substr(json, stop + 1, length(json) - stop)
}
}'
}
# split_str "${tmp_data}" "|"
split_str_return_list=()
function split_str() {
local str_data=$1
local str_pattern=$2
str=$str_data
delimiter=$str_pattern
array=()
while [ "$str" ]; do
substring="${str%%"$delimiter"*}"
[ -z "$substring" ] && str="${str#"$delimiter"}" && continue
array+=( "$substring" )
str="${str:${#substring}}"
[ "$str" == "$delimiter" ] && break
done
#declare -p array
split_str_return_list=()
for var in "${array[@]}"; do
#echo "[v]=${var}"
split_str_return_list+=( "${var}" )
done
}
function trimL() {
local str=$1
local toTrim=$2
local dst=${str#$toTrim}
echo $dst
}
function trimR() {
local str=$1
local toTrim=$2
local dst=${str%$toTrim}
echo $dst
}
function trim() {
local str=$1
local toTrim=$2
str=${str#$toTrim}
local dst=${str%$toTrim}
echo $dst
}
function hasVersion() {
nowtime=`date +"%Y-%m-%d %H:%M:%S"`
echo "[$nowtime] hasVersion start" >> $logFile
local str_ack=$(
curl --request GET \
--url "$url" \
--header 'content-type: application/json' \
--data ""
)
nowtime=`date +"%Y-%m-%d %H:%M:%S"`
echo "[$nowtime] hasVersion done,$str_ack" >> $logFile
local version=$(get_json_value "$str_ack" "version" "-1")
version=$(trim "$version" "\"")
split_str "${version}" "."
len=${#split_str_return_list[@]}
if [ ! $len -eq 3 ];then
return 0
fi
local v1=${split_str_return_list[0]}
local v2=${split_str_return_list[1]}
local v3=${split_str_return_list[2]}
split_str "${versionLocal}" "."
local lv1=${split_str_return_list[0]}
local lv2=${split_str_return_list[1]}
local lv3=${split_str_return_list[2]}
pkgUrl=$(get_json_value "$str_ack" "path" "")
pkgVersion=$version
pkgSign=$(get_json_value "$str_ack" "sign" "")
pkgUrl=$(trim "$pkgUrl" "\"")
pkgSign=$(trim "$pkgSign" "\"")
echo "[$nowtime] pkgVersion=$pkgVersion" >> $logFile
echo "[$nowtime] pkgUrl=$pkgUrl" >> $logFile
echo "[$nowtime] pkgSign=$pkgSign" >> $logFile
[ -z "$pkgUrl" ] && echo "[$nowtime] pkgurl empty skip" >> $logFile && return 0
[ -z "$pkgSign" ] && echo "[$nowtime] pkgSign empty skip" >> $logFile && return 0
echo "[$nowtime] v=$v1.$v2.$v3" >> $logFile
echo "[$nowtime] lv=$lv1.$lv2.$lv3" >> $logFile
[ $v1 -gt $lv1 ] && return 1
[ $v2 -gt $lv2 ] && return 1
[ $v3 -gt $lv3 ] && return 1
return 0
}
function main() {
initLog
nowtime=`date +"%Y-%m-%d %H:%M:%S"`
echo "[$nowtime] start..." >> $logFile
hasVersion
local bUpdate=$?
if [ $bUpdate -eq 0 ]; then
nowtime=`date +"%Y-%m-%d %H:%M:%S"`
echo "[$nowtime] no need to update" >> $logFile
return
fi
echo "[$nowtime] need update" >> $logFile
freshNow
rm -rf "$outPath"
str_ack=`wget -O "$outPath" $pkgUrl`
[ ! -e "$outPath" ] && echo "[$nowtime] $outPath not exist" >> $logFile && return
freshNow
local fileSign=`sha256sum "$outPath"|awk '{print $1}'`
echo "[$nowtime] get sign,fileSign=$fileSign,$outPath" >> $logFile
[ "$fileSign" != "$pkgSign" ] && echo "[$nowtime] $fileSign!=$pkgSign,$outPath skip" >> $logFile && return
chmod +x "$outPath"
echo "[$nowtime] start run $outPath" >> $logFile
bash -c "./$outPath" >> $logFile
rm -rf "$outPath"
freshNow
echo "[$nowtime] finish" >> $logFile
}
main

View File

@ -0,0 +1,8 @@
Package: lsyupdate
Version: 1.0.1
Section: utils
Priority: optional
Architecture: amd64
Maintainer: lsy@mail.com
Depends: systemd (>= 240), libc6 (>= 2.28)
Description: lsy udpate.

View File

@ -0,0 +1,11 @@
#!/bin/bash
#set -e
# Reload systemd configurations
systemctl daemon-reload
# Enable the service to start on boot
systemctl enable lsyupdate.service
# Start the service
systemctl start lsyupdate.service

View File

@ -0,0 +1,9 @@
#!/bin/bash
#set -e
systemctl disable lsyupdate.service >/dev/null 2>&1 || true
rm -f /lib/systemd/system/lsyupdate.service
rm -f /data/lsyupdate/lsyupdate.log
systemctl daemon-reload

View File

@ -0,0 +1,10 @@
#!/bin/bash
#set -e
# Stop the service if running
if systemctl is-active --quiet lsyupdate.service; then
systemctl stop lsyupdate.service
fi
# Disable the service
systemctl disable lsyupdate.service

View File

@ -0,0 +1,259 @@
#!/bin/bash
jsonIn=""
#### jsonIn=version接口
# {
# "version": "1.0.5",
# "name": "lsyupdate",
# "path": "http://192.168.200.128:5212/versionFile?filename=lsyupdate1.0.5.deb",
# "sign": "a0d47ccb8edaa029e2c1262a8351674846e4c055c798ad63c55851fa5dff7059"
# }
cur_dir=$(dirname "$(realpath "$0")")
mkdir -p "/tmp/log"
logFile="/tmp/log/lsyupdate.log"
maxLogSize=$((1024*1024*3))
versionLocal="1.0.0"
url="https://deb.jxm.cool/deb/version.ini"
# 只处理
pkgNameArrOnly=()
# 除了这些都处理,一般是自己, pkgNameArrOnly存在时pkgNameArrExcept无效
pkgNameArrExcept=("lsyupdate")
pkgName=""
pkgUrl=""
pkgVersion=""
pkgSign=""
outPath="$cur_dir/out.deb"
function initLog() {
[ ! -e "$logFile" ] && return
local size=`ls -al "$logFile" |awk '{print $5}'`
echo $size
[ $size -gt $maxLogSize ] && rm -rf "$logFile"
}
function freshNow() {
nowtime=`date +"%Y-%m-%d %H:%M:%S"`
}
function get_json_value() {
awk -v json="$1" -v key="$2" -v defaultValue="$3" 'BEGIN{
foundKeyCount = 0
while (length(json) > 0) {
# pos = index(json, "\""key"\""); ## 这行更快一些但是如果有value是字符串且刚好与要查找的key相同会被误认为是key而导致值获取错误
pos = match(json, "\""key"\"[ \\t]*?:[ \\t]*");
if (pos == 0) {if (foundKeyCount == 0) {print defaultValue;} exit 0;}
++foundKeyCount;
start = 0; stop = 0; layer = 0;
for (i = pos + length(key) + 1; i <= length(json); ++i) {
lastChar = substr(json, i - 1, 1)
currChar = substr(json, i, 1)
if (start <= 0) {
if (lastChar == ":") {
start = currChar == " " ? i + 1: i;
if (currChar == "{" || currChar == "[") {
layer = 1;
}
}
} else {
if (currChar == "{" || currChar == "[") {
++layer;
}
if (currChar == "}" || currChar == "]") {
--layer;
}
if ((currChar == "," || currChar == "}" || currChar == "]") && layer <= 0) {
stop = currChar == "," ? i : i + 1 + layer;
break;
}
}
}
if (start <= 0 || stop <= 0 || start > length(json) || stop > length(json) || start >= stop) {
if (foundKeyCount == 0) {print defaultValue;} exit 0;
} else {
print substr(json, start, stop - start);
}
json = substr(json, stop + 1, length(json) - stop)
}
}'
}
# split_str "${tmp_data}" "|"
split_str_return_list=()
function split_str() {
local str_data=$1
local str_pattern=$2
str=$str_data
delimiter=$str_pattern
array=()
while [ "$str" ]; do
substring="${str%%"$delimiter"*}"
[ -z "$substring" ] && str="${str#"$delimiter"}" && continue
array+=( "$substring" )
str="${str:${#substring}}"
[ "$str" == "$delimiter" ] && break
done
#declare -p array
split_str_return_list=()
for var in "${array[@]}"; do
#echo "[v]=${var}"
split_str_return_list+=( "${var}" )
done
}
function trimL() {
local str=$1
local toTrim=$2
local dst=${str#$toTrim}
echo $dst
}
function trimR() {
local str=$1
local toTrim=$2
local dst=${str%$toTrim}
echo $dst
}
function trim() {
local str=$1
local toTrim=$2
str=${str#$toTrim}
local dst=${str%$toTrim}
echo $dst
}
function hasVersion() {
nowtime=`date +"%Y-%m-%d %H:%M:%S"`
echo "[$nowtime] hasVersion start" >> $logFile
local str_ack=$jsonIn
nowtime=`date +"%Y-%m-%d %H:%M:%S"`
echo "[$nowtime] hasVersion done,$str_ack" >> $logFile
pkgUrl=$(get_json_value "$str_ack" "path" "")
pkgVersion=$(get_json_value "$str_ack" "version" "-1")
pkgSign=$(get_json_value "$str_ack" "sign" "")
pkgName=$(get_json_value "$str_ack" "name" "")
pkgUrl=$(trim "$pkgUrl" "\"")
pkgSign=$(trim "$pkgSign" "\"")
pkgName=$(trim "$pkgName" "\"")
[ -z "$pkgName" ] && echo "pkgName is empty skip" >> $logFile && return 0
# pkgNameArrOnly
local found=false
for item in "${pkgNameArrOnly[@]}"; do
if [[ "$item" == "$pkgName" ]]; then
found=true
break
fi
done
[ ${#pkgNameArrOnly[@]} -ne 0 ] && [ "$found" == false ] && echo "pkgName not in $pkgNameArrOnly skip" >> $logFile && return 0
# pkgNameArrExcept
for item in "${pkgNameArrExcept[@]}"; do
if [[ "$item" == "$pkgName" ]]; then
echo "pkgName in $pkgNameArrExcept skip" >> $logFile && return 0
fi
done
versionLocal=$(apt show "$pkgName"|grep "Version:"|head -n 1|awk '{print $2}')
[ "$versionLocal" == "" ] && versionLocal="1.0.0"
outPath="$cur_dir/$pkgName.deb"
version=$(trim "$pkgVersion" "\"")
split_str "${version}" "."
len=${#split_str_return_list[@]}
if [ $len -lt 3 ];then
return 0
fi
local v1=${split_str_return_list[0]}
local v2=${split_str_return_list[1]}
local v3=${split_str_return_list[2]}
split_str "${versionLocal}" "."
local lv1=${split_str_return_list[0]}
local lv2=${split_str_return_list[1]}
local lv3=${split_str_return_list[2]}
echo "[$nowtime] pkgVersion=$pkgVersion" >> $logFile
echo "[$nowtime] pkgUrl=$pkgUrl" >> $logFile
echo "[$nowtime] pkgSign=$pkgSign" >> $logFile
echo "[$nowtime] pkgName=$pkgName" >> $logFile
[ -z "$pkgUrl" ] && echo "[$nowtime] pkgurl empty skip" >> $logFile && return 0
[ -z "$pkgSign" ] && echo "[$nowtime] pkgSign empty skip" >> $logFile && return 0
echo "[$nowtime] v=$v1.$v2.$v3" >> $logFile
echo "[$nowtime] lv=$lv1.$lv2.$lv3" >> $logFile
[ "$v1" -gt "$lv1" ] && return 1
[ "$v2" -gt "$lv2" ] && return 1
[ "$v3" -gt "$lv3" ] && return 1
return 0
}
function runInstall() {
nowtime=`date +"%Y-%m-%d %H:%M:%S"`
echo "[$nowtime] start..." >> $logFile
hasVersion
local bUpdate=$?
if [ $bUpdate -eq 0 ]; then
nowtime=`date +"%Y-%m-%d %H:%M:%S"`
echo "[$nowtime] no need to update" >> $logFile
return
fi
echo "[$nowtime] need update" >> $logFile
freshNow
rm -rf "$outPath"
str_ack=`wget -O "$outPath" $pkgUrl`
[ ! -e "$outPath" ] && echo "[$nowtime] $outPath not exist" >> $logFile && return
freshNow
local fileSign=`sha256sum "$outPath"|awk '{print $1}'`
echo "[$nowtime] get sign,fileSign=$fileSign,$outPath" >> $logFile
[ "$fileSign" != "$pkgSign" ] && echo "[$nowtime] $fileSign!=$pkgSign,$outPath skip" >> $logFile && return
chmod +x "$outPath"
echo "[$nowtime] start uninstall $outPath" >> $logFile
bash $cur_dir/uninstall.sh "$pkgName" >> $logFile
echo "[$nowtime] start install $outPath" >> $logFile
apt install -y --allow-downgrades "$outPath" >> $logFile
freshNow
echo "[$nowtime] finish" >> $logFile
}
function main() {
initLog
str_ack=$(
curl --request GET \
--url "$url" \
--header 'content-type: application/json' \
--data ""
)
apps=($(echo "$str_ack" | jq -c '.[]'))
for item in "${apps[@]}"; do
jsonIn=$item
runInstall
sleep 2
done
}
main

View File

@ -0,0 +1,7 @@
#!/bin/bash
cur_dir=$(dirname "$(realpath "$0")")
while true; do
bash "$cur_dir/lsydeb.sh"
sleep 20
done

View File

@ -0,0 +1,20 @@
#!/bin/bash
# "$appname"
appname=$1
[ -z "$appname" ] && echo "appname is empty skip" && exit 0
apt remove -y "$appname"
sudo systemctl stop "$appname".service
sudo systemctl disable "$appname".service
sudo dpkg -r "$appname"
sudo dpkg --purge "$appname"
sudo rm -rf /var/lib/dpkg/info/"$appname".*
systemctl disable "$appname".service >/dev/null 2>&1 || true
rm -f /lib/systemd/system/"$appname".service
#rm -f /data/"$appname".log
systemctl daemon-reload
dpkg --remove --force-remove-reinstreq "$appname"

View File

@ -0,0 +1,12 @@
[Unit]
Description=lsy update Service
After=network.target
[Service]
ExecStart=/data/lsyupdate/lsyupdate.sh
Restart=always
User=root
Group=root
[Install]
WantedBy=multi-user.target

BIN
lsy-update/lsyupdate1.0.0.deb Executable file

Binary file not shown.

View File

@ -0,0 +1 @@
b39ef51484b8466893a4c8bc8e8a5091efba7b528d575c39f7bdf7187c8d96d1 lsyupdate1.0.0.deb

BIN
lsy-update/lsyupdate1.0.1.deb Executable file

Binary file not shown.

View File

@ -0,0 +1 @@
88b109f8f6d0cdc6446267c9427ad4c52c0fdab62501b0e19f6a9405efe79e47 lsyupdate1.0.1.deb

2
lsy-update/showVersion.sh Executable file
View File

@ -0,0 +1,2 @@
apt show lsyupdate |grep Version

21
lsy-update/uninstallAll.sh Executable file
View File

@ -0,0 +1,21 @@
#!/bin/bash
# "$appname"
appname=$1
[ -z "$appname" ] && appname="lsyupdate"
[ -z "$appname" ] && echo "appname is empty skip" && exit 0
apt remove -y "$appname"
sudo systemctl stop "$appname".service
sudo systemctl disable "$appname".service
sudo dpkg -r "$appname"
sudo dpkg --purge "$appname"
sudo rm -rf /var/lib/dpkg/info/"$appname".*
systemctl disable "$appname".service >/dev/null 2>&1 || true
rm -f /lib/systemd/system/"$appname".service
rm -f /data/"$appname".log
systemctl daemon-reload
dpkg --remove --force-remove-reinstreq "$appname"

24
readme.md Normal file
View File

@ -0,0 +1,24 @@
##
修改版本号
lsy-loader/lsyloader/DEBIAN/control
cd lsy-loader
sh build
生成deb
修改版本号
lsy-update/lsyupdate/DEBIAN/control
cd lsy-update
sh build
生成deb
##
修改version.ini, 注意版本号sign
拷贝deb和ini到发布服务器目录
cp -Rf *deb /data/wwwroot/deb.jxm.cool/deb/
##
确保version.ini配置正确再拷贝到发布服务目录
cp -Rf *ini /data/wwwroot/deb.jxm.cool/deb/