Skip to content

Commit ea9fa49

Browse files
author
sydneyowl
committed
Add dialog
1 parent ea655be commit ea9fa49

File tree

1 file changed

+109
-17
lines changed

1 file changed

+109
-17
lines changed

build.sh

Lines changed: 109 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ ARMBIAN_REPO=armbian/build
2626
ARMBIAN_REF=main
2727
DESKTOP_ENVIRONMENT=xfce
2828
DESKTOP_ENVIRONMENT_CONFIG_NAME=config_base
29-
DESKTOP_APPGROUPS_SELECTED=""
29+
DESKTOP_APPGROUPS_SELECTED=
3030
PATCHES=(4077 5076 5082)
3131
AMLIMG_VERSION="v0.3.1"
3232

@@ -36,6 +36,7 @@ RELEASE=(jammy,bullseye,sid)
3636
TYPE=(minimal,cli,desktop)
3737

3838
# Default choices...
39+
INTERACTIVE=false
3940
CHOOSED_BRANCH=current
4041
CHOOSED_RELEASE=jammy
4142
CHOOSED_TYPE=minimal
@@ -48,7 +49,7 @@ OUTPUT_DIR=$(pwd)/build_onecloud/dist
4849
# Show usages...
4950
usage(){
5051
cat << EOF
51-
Usage: $0
52+
Usage: $0 [OPTION]
5253
-h,--help: Show help infomation
5354
-b,--branch: Branch to be built, choose from ${BRANCH[*]}. Default is $CHOOSED_BRANCH.
5455
-n,--no-burnable-images: Don't Create burnable images. Default is $NOT_CREATE_BURNABLE.
@@ -60,17 +61,96 @@ If you use this option, the script will no longer clone the source code from $AR
6061
for example, config/kernel/xxx.config. Default is $LOCAL_REPO_ADDR.
6162
-s,--skip-patch: Skip apply patch to source code. Default is $SKIP_PATCH.
6263
-o,--output-dir: specify a directory to storage artifacts. Default is $OUTPUT_DIR.
64+
-i,--interactive: use dialog to ask user for build args.
6365
example: ./build.sh -b current -r jammy -t minimal
6466
EOF
6567
}
68+
interactive(){
69+
echo "Installing Dialog...."
70+
# sudo sudo apt-get -qqqqq update && apt-get -qqqqq install dialog -y
71+
dialog --title "Onecloud Build" --msgbox "Now this script will guide you to build your armbian image for onecloud." 20 50
72+
if dialog --title "Build from local" --defaultno --yesno "Do you want to build from local repo?" 10 30; then
73+
SKIP_CLONE=true
74+
dialog --title "Select or input yout repo position" --fselect / 7 60 2> /tmp/dialog_onecloud.txt
75+
_LOCAL_REPO_ADDR=$(cat /tmp/dialog_onecloud.txt)
76+
if [ -n $_LOCAL_REPO_ADDR ];then
77+
LOCAL_REPO_ADDR=$_LOCAL_REPO_ADDR
78+
fi
79+
if dialog --title "Apply Patch" --defaultno --yesno "Do you want to Apply patches automatically?" 10 30; then
80+
SKIP_PATCH=true
81+
fi
82+
fi
83+
84+
if dialog --title "Build Burnable Images" --yesno "Do you want to build Burnable images?" 10 30; then
85+
NOT_CREATE_BURNABLE=false
86+
else
87+
NOT_CREATE_BURNABLE=true
88+
fi
89+
90+
if dialog --title "Select output directory" --defaultno --yesno "Do you want to select a output directory, default is $OUTPUT_DIR?" 10 60; then
91+
dialog --title "Select output directory" --fselect / 7 60 2> /tmp/dialog_onecloud.txt
92+
_OUTPUT_DIR=$(cat /tmp/dialog_onecloud.txt)
93+
if [ -n $_OUTPUT_DIR ];then
94+
OUTPUT_DIR=$_OUTPUT_DIR
95+
fi
96+
fi
97+
98+
dialog --title "Select build branch" --clear --menu \
99+
"Please choose branch to be built, default is $CHOOSED_BRANCH: " 16 51 3 \
100+
current "Build branch current" \
101+
edge "Build branch edge" 2>/tmp/dialog_onecloud.txt
102+
_CHOOSED_BRANCH=$(cat /tmp/dialog_onecloud.txt)
103+
if [ -n $_CHOOSED_BRANCH ];then
104+
CHOOSED_BRANCH=$_CHOOSED_BRANCH
105+
fi
66106

107+
dialog --title "Select build release" --clear --menu \
108+
"Please choose release to be built, default is $CHOOSED_RELEASE: " 16 51 3 \
109+
jammy "Build release jammy" \
110+
bullseye "Build release bullseye" \
111+
sid "Build release sid" 2>/tmp/dialog_onecloud.txt
112+
_CHOOSED_RELEASE=$(cat /tmp/dialog_onecloud.txt)
113+
if [ -n $_CHOOSED_RELEASE ];then
114+
CHOOSED_RELEASE=$_CHOOSED_RELEASE
115+
fi
116+
117+
dialog --title "Select build type" --clear --menu \
118+
"Please choose type to be built, default is $CHOOSED_TYPE: " 16 51 3 \
119+
minimal "Build type minimal" \
120+
cli "Build type cli" \
121+
desktop "Build type desktop" 2>/tmp/dialog_onecloud.txt
122+
_CHOOSED_TYPE=$(cat /tmp/dialog_onecloud.txt)
123+
if [ -n $_CHOOSED_TYPE ];then
124+
CHOOSED_TYPE=$_CHOOSED_TYPE
125+
fi
126+
if [[ $CHOOSED_TYPE == "desktop" ]];then
127+
if dialog --title "ADVANCED" --defaultno --yesno "Do you want to specify other configs, including DESKTOP_ENVIRONMENT,DESKTOP_ENVIRONMENT_CONFIG_NAME,DESKTOP_APPGROUPS_SELECTED?" 10 60; then
128+
USER_INPUT=$(dialog --title "Advanced option" \
129+
--output-fd 1 \
130+
--output-separator "," \
131+
--form "Input configs:" 12 80 4 \
132+
"DESKTOP_ENVIRONMENT:" 1 1 "$DESKTOP_ENVIRONMENT" 1 40 25 0 \
133+
"Full DESKTOP_ENVIRONMENT_CONFIG_NAME:" 2 1 "$DESKTOP_ENVIRONMENT_CONFIG_NAME" 2 40 25 0 \
134+
"DESKTOP_APPGROUPS_SELECTED:" 3 1 "$DESKTOP_APPGROUPS_SELECTED" 3 40 25 0)
135+
RET_ARRAY=($USER_INPUT)
136+
if [ -n $RET_ARRAY[0] ];then
137+
DESKTOP_ENVIRONMENT=$RET_ARRAY[0]
138+
fi
139+
if [ -n $RET_ARRAY[1] ];then
140+
DESKTOP_ENVIRONMENT_CONFIG_NAME=$RET_ARRAY[1]
141+
fi
142+
if [ -n $RET_ARRAY[2] ];then
143+
DESKTOP_APPGROUPS_SELECTED=$RET_ARRAY[2]
144+
fi
145+
fi
146+
fi
147+
dialog --title "Onecloud Build" --msgbox "Configs collected. Press Enter to start building!" 20 50
148+
# echo "ddd"
149+
dialog --clear
150+
rm -rf /tmp/dialog_onecloud.txt
151+
}
67152
# Run build
68153
run_build(){
69-
# Check if running with root...
70-
if [ `id -u` -ne 0 ];then
71-
echo "Plz Use sudo to run this script"
72-
exit 0
73-
fi
74154

75155
mkdir -p $LOCAL_REPO_ADDR
76156
mkdir -p $OUTPUT_DIR/debs
@@ -214,7 +294,7 @@ exit 0
214294

215295

216296
# Fetch user options
217-
OPTIONS=`getopt -o hso:b:r:t:l: --long help,skip-patch,branch:,release:,type:,local-repo-addr:,output-dir: -n $0 -- "$@"`
297+
OPTIONS=`getopt -o hsio:b:r:t:l: --long help,skip-patch,interactive,branch:,release:,type:,local-repo-addr:,output-dir: -n $0 -- "$@"`
218298
if [ $? != 0 ];then
219299
usage
220300
exit 1
@@ -223,9 +303,6 @@ eval set -- "${OPTIONS}"
223303
while true
224304
do
225305
case $1 in
226-
-h|--help)
227-
usage
228-
;;
229306
-b|--branch)
230307
CHOOSED_BRANCH=$2
231308
[[ ${BRANCH[@]/${CHOOSED_BRANCH}/} != ${BRANCH[@]} ]] && echo "Branch $CHOOSED_BRANCH is choosed." || (echo "You should choose from ${BRANCH[*]}." && exit 1)
@@ -249,16 +326,22 @@ do
249326
exit 1
250327
fi
251328
shift
252-
;;
253-
-s|--skip-patch)
254-
SKIP_PATCH=true
255329
;;
256330
-o|--output-dir)
257331
OUTPUT_DIR=$2
332+
shift
333+
;;
334+
-h|--help)
335+
usage
336+
;;
337+
-s|--skip-patch)
338+
SKIP_PATCH=true
258339
;;
259340
-n|--no-burnable-images)
260-
$NOT_CREATE_BURNABLE=true
261-
shift
341+
NOT_CREATE_BURNABLE=true
342+
;;
343+
-i|--interactive)
344+
INTERACTIVE=true
262345
;;
263346
--)
264347
shift
@@ -272,4 +355,13 @@ do
272355
shift
273356
done
274357
# usage
275-
run_build
358+
359+
# Check if running with root...
360+
if [ `id -u` -ne 0 ];then
361+
echo "Plz Use sudo to run this script"
362+
exit 0
363+
fi
364+
if [ "$INTERACTIVE" = true ];then
365+
interactive
366+
fi
367+
run_build

0 commit comments

Comments
 (0)