Skip to content

Commit

Permalink
chore: Add a "" symbol to the variable
Browse files Browse the repository at this point in the history
给shell变量添加"" 符号避免参数解析错误

Log: add "" symbol
  • Loading branch information
chenchongbiao authored and dengbo11 committed Sep 27, 2024
1 parent fe98749 commit 20864c9
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 29 deletions.
26 changes: 13 additions & 13 deletions cmd/ll-pica-flatpak/ll-pica-flatpak
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@ export LL_PICA_FLATPAK_PATH="$(realpath --no-symlinks "$(dirname "${BASH_SOURCE[
export LL_PICA_FLATPAK_CONFIG_FILE="$HOME/.pica/ll-pica-flatpak-config.json"
export LL_PICA_FLATPAK_REFS_FILE="$HOME/.pica/ll-pica-flatpak-refs.txt" # 存放 flathub 仓库 refs 的文件

mkdir -p $HOME/.pica
mkdir -p "$HOME"/.pica

if [[ ! -e $LL_PICA_FLATPAK_CONFIG_FILE ]];
then
tee $LL_PICA_FLATPAK_CONFIG_FILE <<EOF
tee "$LL_PICA_FLATPAK_CONFIG_FILE" <<EOF
{
"flathub": {
"url": "https://dl.flathub.org/repo/"
Expand Down Expand Up @@ -41,13 +41,13 @@ function main() {
while true
do
case "$1" in
--base) test -z $2 || BASE=$2; shift 2;;
--base-version) test -z $2 || BASE_VERSION=$2; shift 2;;
--base) test -z "$2" || BASE="$2"; shift 2;;
--base-version) test -z "$2" || BASE_VERSION="$2"; shift 2;;
# # 转换为玲珑的版本,规则是按'.'和'-'分割取前三位,不足三位补0,再末尾补充输入的打包版本号,如 5.15-23.08 生成 5.15.23.0
--version) test -z $2 || VERSION="$(echo "$2.0.0.0" | awk -F'[-.]' 'BEGIN {OFS="."} {print $1,$2,$3}').0"; shift 2;;
--build) test -z $2 || BUILD=true; shift 1;;
--layer) test -z $2 || LAYER=true; shift 1;;
-h|--help) test -z $2 || "${LL_PICA_FLATPAK_PATH}/ll-pica-flatpak-utils" help; shift 1; exit 0;;
--version) test -z "$2" || VERSION="$(echo "$2.0.0.0" | awk -F'[-.]' 'BEGIN {OFS="."} {print $1,$2,$3}').0"; shift 2;;
--build) test -z "$2" || BUILD=true; shift 1;;
--layer) test -z "$2" || LAYER=true; shift 1;;
-h|--help) test -z "$2" || "${LL_PICA_FLATPAK_PATH}/ll-pica-flatpak-utils" help; shift 1; exit 0;;
--) shift; break;;
*) echo echo "Programming error $1 , $2"; exit 1;;
esac
Expand Down Expand Up @@ -75,14 +75,14 @@ function main() {
export REF="flathub:app/$APPID/$ARCH/stable"

echo "init flathub cache"
ostree init --repo=$FLATHUB_CACHE --mode bare-user-only
ostree init --repo="$FLATHUB_CACHE" --mode bare-user-only

FLATHUB_URL=$(jq -r ".flathub.url" $LL_PICA_FLATPAK_CONFIG_FILE)
ostree --repo=$FLATHUB_CACHE remote add --if-not-exists --no-sign-verify flathub $FLATHUB_URL
FLATHUB_URL=$(jq -r ".flathub.url" "$LL_PICA_FLATPAK_CONFIG_FILE")
ostree --repo="$FLATHUB_CACHE" remote add --if-not-exists --no-sign-verify flathub "$FLATHUB_URL"

case "${COMMAND}" in
convert)
"${LL_PICA_FLATPAK_PATH}/ll-pica-flatpak-convert" $APPID $VERSION $BUILD $LAYER
"${LL_PICA_FLATPAK_PATH}/ll-pica-flatpak-convert" "$APPID" "$VERSION" "$BUILD" "$LAYER"
;;
help | --help | -h)
exit 0
Expand All @@ -93,4 +93,4 @@ function main() {
esac
}

main $@
main "$@"
30 changes: 14 additions & 16 deletions cmd/ll-pica-flatpak/ll-pica-flatpak-convert
Original file line number Diff line number Diff line change
Expand Up @@ -8,33 +8,33 @@ BUILD=$3
LAYER=$4
WORKDIR=$APPID

SEARCH_REF=$(grep "$REF" $LL_PICA_FLATPAK_REFS_FILE)
SEARCH_REF=$(grep "$REF" "$LL_PICA_FLATPAK_REFS_FILE")

if [[ -z $SEARCH_REF ]];
then
"${LL_PICA_FLATPAK_PATH}/ll-pica-flatpak-utils" generate_ref_cache
fi

ostree --repo=$FLATHUB_CACHE pull "$REF"
rm -rf $WORKDIR && mkdir -p $WORKDIR
ostree --repo=$FLATHUB_CACHE checkout "$REF" "$WORKDIR/flatpak"
ostree --repo="$FLATHUB_CACHE" pull "$REF"
rm -rf "$WORKDIR" && mkdir -p "$WORKDIR"
ostree --repo="$FLATHUB_CACHE" checkout "$REF" "$WORKDIR/flatpak"

FLATPAK_RUNTIME=$(grep '^runtime=' $WORKDIR/flatpak/metadata | awk -F'=' '{print $2}' | awk -F'/' '{print $1}')
FLATPAK_RUNTIME_VERSION=$(grep '^runtime=' $WORKDIR/flatpak/metadata | awk -F'=' '{print $2}' | awk -F'/' '{print $3}')
FLATPAK_RUNTIME=$(grep '^runtime=' "$WORKDIR"/flatpak/metadata | awk -F'=' '{print $2}' | awk -F'/' '{print $1}')
FLATPAK_RUNTIME_VERSION=$(grep '^runtime=' "$WORKDIR"/flatpak/metadata | awk -F'=' '{print $2}' | awk -F'/' '{print $3}')

LINGLONG_BASE_NAME="org.deepin.base.flatpak.$(echo "$FLATPAK_RUNTIME"|awk -F'.' '{print $2}')"
LINGLONG_BASE_VERSION="$(echo "$FLATPAK_RUNTIME_VERSION.0.0.0" | awk -F'[-.]' 'BEGIN {OFS="."} {print $1,$2,$3}')"

# 尝试获取 base 的信息
LINGLONG_INSTALL_INFO=$(ll-cli install $LINGLONG_BASE_NAME)
LINGLONG_INSTALL_INFO=$(ll-cli install "$LINGLONG_BASE_NAME")
if [[ "$LINGLONG_INSTALL_INFO" != *installed* && "$LINGLONG_INSTALL_INFO" != *success* ]];
then
echo "$LINGLONG_BASE_NAME not found"
exit 1
fi

# 如果没有存在这个 base 选择一个默认的
ll-cli info $LINGLONG_BASE_NAME
ll-cli info "$LINGLONG_BASE_NAME"
if [[ $? != 0 ]];
then
LINGLONG_BASE_NAME=org.deepin.base.flatpak.kde
Expand All @@ -56,12 +56,12 @@ fi
for desktop in `ls -1 $WORKDIR/flatpak/files/share/applications/*desktop`
do
# DESKTOP_PATH=$WORKDIR/flatpak/files/share/applications/$desktop
EXEC_OLD=$(grep -e '^Exec=.*' $desktop | head -n 1 | cut -d "=" -f 2- | sed -e 's|%.||g')
EXEC_OLD=$(grep -e '^Exec=.*' "$desktop" | head -n 1 | cut -d "=" -f 2- | sed -e 's|%.||g')
if echo "$EXEC_OLD" | grep -q "/app";
then
# replace flatpak /app to linglong /opt/apps/$APPID/files
EXEC=$(echo $EXEC_OLD | sed "s|/app|/opt/apps/$APPID/files|g")
sed -i "/Exec*/c\\Exec=$EXEC" $desktop
sed -i "/Exec*/c\\Exec=$EXEC" "$desktop"
else
EXEC=$EXEC_OLD
fi
Expand All @@ -70,15 +70,13 @@ done
BIN_FILE=${EXEC_OLD%% *}
if [[ $BIN_FILE == /* ]];
then
BIN_FILE_PATH=$(echo $BIN_FILE | sed "s|/app|$APPID/flatpak/files|g")
BIN_FILE_PATH=$(echo "$BIN_FILE" | sed "s|/app|$APPID/flatpak/files|g")
else
BIN_FILE_PATH=$APPID/flatpak/files/bin/$BIN_FILE
fi
sed -i "s|/app|/opt/apps/$APPID/files|g" $BIN_FILE_PATH
sed -i "s|/app|/opt/apps/$APPID/files|g" "$BIN_FILE_PATH"

COMMAND="/opt/apps/$APPID/files/bin/start.sh"

tee $WORKDIR/linglong.yaml <<EOF
tee "$WORKDIR"/linglong.yaml <<EOF
version: "1"
package:
id: $APPID
Expand All @@ -97,7 +95,7 @@ EOF

if $BUILD;
then
cd $WORKDIR
cd "$WORKDIR"
ll-builder build

if $LAYER;
Expand Down

0 comments on commit 20864c9

Please sign in to comment.