deb-packs/charles/package.sh

169 lines
3.9 KiB
Bash
Raw Permalink Normal View History

2024-01-09 16:17:16 +08:00
#!/bin/bash
origin_app_name="charles-proxy"
app_name="charles"
tmp_dir="/tmp/${app_name}_tmp"
2024-08-22 10:13:42 +08:00
version="4.6.7"
2024-01-09 16:17:16 +08:00
release="v${version}"
replace_name="charles-nj"
patch="Architecture: amd64"
_type="amd64"
2024-01-09 17:47:49 +08:00
_desc=', 内置java-11 runtime'
2024-01-09 16:17:16 +08:00
if [ "$1" == "nj" ]; then
_type="all"
app_name+="-nj"
replace_name="charles"
2024-01-09 17:47:49 +08:00
_desc=""
2024-01-09 16:17:16 +08:00
patch="""Architecture: all
Depends: java11-runtime"""
fi
deb_url="https://www.charlesproxy.com/packages/apt/pool/main/c/charles-proxy/${origin_app_name}_${version}_${_type}.deb"
# 创建临时目录, 用于下载官方包
if [ -d $tmp_dir ]; then
rm -rf $tmp_dir
fi
if [ -d "./unpack" ]; then
sudo rm -rf ./unpack
fi
if [ -f "./${app_name}_${version}.deb" ]; then
rm "./${app_name}_${version}.deb"
fi
mkdir $tmp_dir
# 创建临时待打包目录
echo "创建待打包目录..."
mkdir -p "./unpack/DEBIAN"
mkdir -p "./unpack/usr"
source_dir="${tmp_dir}/${app_name}"
echo "下载官方原包..."
wget $deb_url -O "${tmp_dir}/${app_name}.deb"
2024-01-09 17:47:49 +08:00
# cp ~/Downloads/${origin_app_name}_4.6.5_${_type}.deb "${tmp_dir}/${app_name}.deb"
2024-01-09 16:17:16 +08:00
echo "下载完成, 解包中..."
dpkg-deb -R "${tmp_dir}/${app_name}.deb" "${tmp_dir}/${app_name}"
echo "解包完成, 复制到待打包目录..."
mv "${source_dir}/usr" "./unpack/"
rm -rf $tmp_dir
echo "复制完成, 创建可执行文件及程序桌面入口文件..."
echo """
#!/bin/bash -e
######################################################################
# Charles Proxy startup script
#
# Find Charles lib directory
CHARLES_LIB="/usr/lib/charles-proxy"
GDK_SCALE=1
java_bin=java
if [ -d "\$CHARLES_LIB/jdk" ]; then
export JAVA_HOME="\$CHARLES_LIB/jdk"
java_bin="\$CHARLES_LIB/jdk/bin/java"
fi
# HiDPI
if [[ \$DESKTOP_SESSION ]]; then
case \$DESKTOP_SESSION in
xfce)
GDK_SCALE=\$(xfconf-query -c xsettings -p /Gdk/WindowScalingFactor)
;;
cinnamon)
GDK_SCALE=\$(/usr/bin/gsettings get org.cinnamon.desktop.interface scaling-factor | awk '{print \$2}')
;;
gnome)
GDK_SCALE=\$(/usr/bin/gsettings get org.gnome.desktop.interface scaling-factor | awk '{print \$2}')
;;
esac
elif [[ \$GNOME_DESKTOP_SESSION_ID ]]; then
GDK_SCALE=\$(/usr/bin/gsettings get org.gnome.desktop.interface scaling-factor | awk '{print \$2}')
else
if [ -x /usr/bin/xfconf-query ]; then
GDK_SCALE=\$(xfconf-query -c xsettings -p /Gdk/WindowScalingFactor)
elif [ -x /usr/bin/gsettings ]; then
GDK_SCALE=\$(/usr/bin/gsettings get org.gnome.desktop.interface scaling-factor | awk '{print \$2}')
fi
fi
export GDK_SCALE
# Launch Charles
\$java_bin \\
-Xmx1024M \\
-Dcharles.config="~/.charles.config" \\
-Djava.library.path="\$CHARLES_LIB" \\
-Djdk.gtk.verbose=true \\
-Djdk.gtk.version=3 \\
-jar \$CHARLES_LIB/charles.jar \\
\$*
""" > ./unpack/usr/bin/charles
chmod +x ./unpack/usr/bin/charles
rm ./unpack/usr/bin/charles4
sed -i -e 's/charles4/charles/; s/com-xk72-charles-gui-MainWithClassLoader/Charles/' ./unpack/usr/share/applications/charles-proxy.desktop
echo "文件复制完成..."
echo '计算文件md5中...'
cd ./unpack
find usr/ -type f | xargs -I {} md5sum {} > DEBIAN/md5sums
IFS=$'\t' read -ra size <<< "$(du -d 0)"
echo """
Package: ${app_name}
Version: ${version}
${patch}
Maintainer: Yutent <yutent.io@gmail.com>
Section: non-free/develop
Breaks: ${replace_name}
Replaces: ${replace_name}
Priority: optional
Installed-Size: ${size[0]}
Homepage: https://www.charlesproxy.com/
2024-01-09 17:47:49 +08:00
Description: 一个网络抓包调试工具${_desc}
2024-01-09 16:17:16 +08:00
Charles is an HTTP proxy / HTTP monitor / Reverse Proxy that enables a
developer to view all of the HTTP and SSL / HTTPS traffic between their
machine and the Internet. This includes requests, responses and the HTTP
headers (which contain the cookies and caching information).
""" > DEBIAN/control
echo '计算文件md5完成, 打包中...'
cd ../
sudo chown -R root:root unpack
dpkg-deb -b ./unpack "./${app_name}_${version}.deb"
sudo rm -rf ./unpack
echo "打包完成 :)"