-
Notifications
You must be signed in to change notification settings - Fork 0
/
pgAdmin_installer_automation_Yum.sh
885 lines (776 loc) · 24.7 KB
/
pgAdmin_installer_automation_Yum.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
#! /bin/bash
WAIT_TO_LAUNCH_APP=15
WAIT_TO_LAUNCH_FF=10
WAIT_TO_LAUNCH_PGAMIN_IN_NWJS=15
WAIT_TO_LAUNCH_PGAMIN_IN_FF=8
ABOUT_BOX_SHOW_TIME=3
BUILD_DATE=''
export PGADMIN_SETUP_EMAIL='[email protected]'
export PGADMIN_SETUP_PASSWORD='adminedb'
# Exit on error
set -e
# Set up parser
# help function
help()
{
echo "Usage: bash pgAdmin_installer_automation_Apt.sh
[ -o | --operation ](required):
install :Install latest released version
install_snapshot :Install snapshot of specified date
install_cb :Install candidate build of specified date
install_old :Install older pgadmin version
verify :Verify pgadmin installtion
upgrade_cb :Upgrade to candidate build
upgrade_test : Installs released version and then upgrades with candidate build and verify instalttion
fresh_test : Installs candidate build and verify instalttion
uninstall : Uninstall the pgadmin from system
[ -m | --mode ] (optional):
desktop
server
[ -h | --help ]"
exit 2
}
# Args
SHORT=o:,m:,h
LONG=operation:,mode:,help
OPTS=$(getopt -a -n pgAdmin_installer --options $SHORT --longoptions $LONG -- "$@")
# Check Args
VALID_ARGUMENTS=$# # Returns the count of arguments that are in short or long options
if [ "$VALID_ARGUMENTS" -eq 0 ]; then
help
fi
# Check args
eval set -- "$OPTS"
while :
do
case "$1" in
-o | --operation )
operation="$2"
shift 2
;;
-m | --mode )
mode="$2"
shift 2
;;
-h | --help)
help
;;
--)
shift;
break
;;
*)
echo "Unexpected option: $1"
help
;;
esac
done
# Validate args
operations=("install" "install_cb" "install_snapshot" "install_old" "verify" "upgrade_cb" "upgrade_test" "fresh_test" "uninstall")
modes=("desktop" "server" "")
if ! [[ " ${operations[@]} " =~ " ${operation} " ]]; then
echo 'Invalid operation'
exit 1
fi
if [[ ! -z " ${mode} " ]] && ! [[ " ${modes[@]} " =~ " ${mode} " ]]; then
echo 'Invalid mode'
exit 1
fi
# Actual Script Execution
# Setup display
echo '******Setting up display.********'
CURRENT_DISPLAY=`xrandr | awk '/ connected/ && /[[:digit:]]x[[:digit:]].*+/{print $1}'`
xrandr --output $CURRENT_DISPLAY --mode 1440x900 --size 16:10
#xrandr --output Virtual1 --mode 1440x900 --size 16:10
sleep 1.5
# Move terminal window to bottom
wid=`xdotool getactivewindow`
xdotool windowsize $wid 1300 500
sleep 1
xdotool windowmove $wid 60 700
# Get Plafrom
IS_REDHAT=0
IS_FEDORA=0
os_name=$(grep "^NAME=" /etc/os-release | awk -F "=" '{ print $2 }' | sed 's/"//g' | awk -F "." '{ print $1 }')
if [[ "$os_name" = "Red Hat Enterprise Linux" || "$os_name" = "Rocky Linux" || "$os_name" = "AlmaLinux" ]]; then
IS_REDHAT=1
elif [ "$os_name" = "Fedora Linux" ]; then
IS_FEDORA=1
else
echo 'Unable to find out platform'
exit 1
fi
# Check existing repo. Do not pasuse execution if repo is empty hence added set +e
REPO_EXISTS=0
set +e
repo=$(rpm -qa | grep pgadmin4)
if [[ ! -z "$repo" ]]; then
REPO_EXISTS=1
fi
set -e
_install_released_pgadmin(){
# Take pgAdmin mode as argument
mode=$1
mode=$([ "$mode" == "" ] && echo "Server & Desktop" || echo "$mode")
# Info
echo ''
echo '***********************************************************'
echo 'Installing Released pgAdmin version. Mode: - '$mode
echo '***********************************************************'
echo ''
echo '******Downloading existing pgAdmin.*******'
# Remove old repo if exists and add repo
set +e
if [ ${IS_REDHAT} == 1 ]; then
if [ ${REPO_EXISTS} == 1 ]; then
echo '----Removing old repo'
sudo rpm -e pgadmin4-redhat-repo
fi
echo '----Adding repo'
sudo rpm -i https://ftp.postgresql.org/pub/pgadmin/pgadmin4/yum/pgadmin4-redhat-repo-2-1.noarch.rpm
elif [ ${IS_FEDORA} == 1 ]; then
if [ ${REPO_EXISTS} == 1 ]; then
echo '----Removing old repo'
sudo rpm -e pgadmin4-fedora-repo
fi
echo '----Adding repo'
sudo rpm -i https://ftp.postgresql.org/pub/pgadmin/pgadmin4/yum/pgadmin4-fedora-repo-2-1.noarch.rpm
fi
set -e
# Check mode and run install commands
suffix=""
if [ "$mode" = "desktop" ]; then
echo '----Installing pgAdmin4-desktop'
sudo yum install pgadmin4-desktop -y
suffix="-desktop"
elif [ "$mode" = "server" ]; then
echo '----Installing pgAdmin4-web'
sudo yum install pgadmin4-web -y
suffix="-web"
# Configure the webserver, if you installed pgadmin4-web:
sudo -E /usr/pgadmin4/bin/setup-web.sh --yes
else
echo '----Installing pgAdmin4 in both modes'
sudo yum install pgadmin4 -y
# Configure the webserver, if you installed pgadmin4-web:
sudo -E /usr/pgadmin4/bin/setup-web.sh --yes
fi
# Check version
pgadmin_version=$(sudo rpm -qa | grep -i pgAdmin4"${suffix}")
echo ''
echo '***********************************************************'
echo 'Relased pgAdmin installed successfully - '"${pgadmin_version}"
echo '***********************************************************'
echo ''
}
_wait_for_window(){
set +e
win_name=$1
wait_time=$2
counter=$wait_time
while [[ $counter -gt 0 ]]
do
wid=`xdotool search --onlyvisible --desktop --name "${win_name}"`
if [[ -z "$wid" ]]; then
sleep 2
counter=$(( counter - 1 ))
if [[ "$counter" -eq 0 ]]; then
echo '---- '$win_name' not found after '$wait_time
exit 1
fi
else
echo '--- '$win_name' found.'
counter=0
sleep 2
fi
done
}
_wait_method(){
set +e
wait_time=$1
counter=$wait_time
echo -ne '----Waiting for '$counter' seconds'
while [ $counter -gt 0 ]
do
read -t 1 -n 1
if [ $? = 0 ] ; then
counter=0
sleep 1
else
echo -ne "."
fi
counter=$(( $counter -1))
done
if [ $counter = 0 ]; then
echo
fi
set -e
}
_verify_installed_pgadmin_server_mode(){
# platform name
os_name=$(grep "^NAME=" /etc/os-release | awk -F "=" '{ print $2 }' | sed 's/"//g' | awk -F "." '{ print $1 }')
# Take pgAdmin mode as argument
mode=$1
# Info
echo ''
echo '***********************************************************'
echo 'Verifying pgAdmin Launch in Server mode.'
echo '***********************************************************'
echo ''
# App launch - Move to applications option an click
xdotool mousemove --sync --screen 0 45 12
sleep 0.5
xdotool mousemove_relative 1 1
sleep 0.5
xdotool click 1
sleep 1
# Type in search box and heat enter
xdotool type "firefox"
sleep 0.5
xdotool key Return
# Wait for FF to open
echo '----Waiting to open firefox.'
app_name="Mozilla Firefox"
time=$WAIT_TO_LAUNCH_APP
_wait_for_window "$app_name" "$time"
_wait_method $WAIT_TO_LAUNCH_FF
set -e
# Search to FF window
wid=`xdotool search --onlyvisible --desktop --name "${app_name}"`
xdotool windowactivate $wid key --delay 250 ctrl+t
# Check if window is maximized
# Try to unmaximize
eval $(xdotool getwindowgeometry --shell ${wid})
if [ ${WIDTH} == 1440 ];then
echo "----Need to reduce size as launched in full screen."
xdotool mousemove --sync 875 45 click --repeat 2 1
echo "----Unmaximized."
fi
# Move window to Left top
if [ ${IS_REDHAT} == 1 ]; then
xdotool windowsize --sync $wid 1375 700
sleep 0.5
xdotool windowmove $wid 90 0
sleep 0.5
elif [ ${IS_FEDORA} == 1 ]; then
xdotool windowsize --sync $wid 1375 700
sleep 0.5
xdotool windowmove $wid 90 0
sleep 0.5
else
echo 'Unable to find platform'
exit 1
fi
echo '----Mozilla Firefox window in correct position.'
# Launch pgAdmin
echo '----Opening pgAdmin in FF'
xdotool type "http://127.0.0.1/pgadmin4"
xdotool key Return
_wait_method $WAIT_TO_LAUNCH_PGAMIN_IN_FF
# Move to login email and password & Enter email
echo '----Entering login details'
xdotool type "[email protected]"
xdotool key "Tab"
xdotool type "adminedb"
xdotool key "Return"
_wait_method 6
# Handle password save
xdotool mousemove 240 530 click 1
sleep 0.5
# Verify version
echo '----Verifying version from About'
# adding X+50, & Y+30
# Open Help
xdotool mousemove 500 160 click 1
sleep 0.5
# About option
xdotool mousemove 500 300 click 1
sleep 3
# Close About box
xdotool mousemove 1125 245 click 1
sleep 0.5
echo '----Closed About box'
# Move to logout
xdotool mousemove 1350 155 click 1
sleep 0.5
xdotool mousemove 1260 280 click 1
sleep 0.5
xdotool key "Return"
sleep $ABOUT_BOX_SHOW_TIME
echo '----Logged out'
# Move to close ff at top and click
xdotool mousemove 1410 45 click 1
sleep 0.5
xdotool key "Return"
echo '----FF is closed.'
# Final Msg
echo ''
echo '***********************************************************'
echo 'pgAdmin server version verified successfully.'
echo '***********************************************************'
echo ''
}
_verify_installed_pgadmin_dektop_mode(){
os_name=$(grep "^NAME=" /etc/os-release | awk -F "=" '{ print $2 }' | sed 's/"//g' | awk -F "." '{ print $1 }')
# Info
echo ''
echo '***********************************************************'
echo 'Verifying pgAdmin launch in Desktop mode'
echo '***********************************************************'
echo ''
# App launch - Move to applications option an click
xdotool mousemove --sync --screen 0 45 12
sleep 0.5
xdotool mousemove_relative 1 1
sleep 0.5
xdotool click 1
sleep 1
# Type in search box and heat enter
xdotool type "pgAdmin 4"
sleep 0.5
xdotool key Return
# Wait for pgAdmin to open
echo '----Waiting to open pgAdmin.'
app_name="pgAdmin 4"
time=$WAIT_TO_LAUNCH_APP
_wait_for_window "$app_name" "$time"
_wait_method $WAIT_TO_LAUNCH_PGAMIN_IN_NWJS
set -e
# Search to pgAdmin window
# Use only name else it will fail giving multiple windows.
wid=`xdotool search --onlyvisible --desktop --name "${app_name}"`
xdotool windowactivate $wid
# Check if window is maximized
# Try to unmaximize
eval $(xdotool getwindowgeometry --shell ${wid})
if [ ${WIDTH} == 1440 ];then
echo '----Need to reduce size as launched in full screen.'
xdotool mousemove --sync 375 45 click --repeat 2 1
echo '----Unmaximized.'
fi
# Move window to Left top
if [ ${IS_REDHAT} == 1 ]; then
xdotool windowsize --sync $wid 1360 700
sleep 0.5
xdotool windowmove $wid 90 0
sleep 0.5
elif [ ${IS_FEDORA} == 1 ]; then
xdotool windowsize --sync $wid 1360 700
sleep 0.5
xdotool windowmove $wid 90 0
sleep 0.5
else
echo 'Unable to find platform'
exit 1
fi
echo '----pgAdmin window in correct position.'
echo '----Wait till I show About box to check version.'
# Move to Help Menu and click
xdotool mousemove 240 75 click 1
sleep 0.5
# Move to About menu
xdotool mousemove 285 205 click 1
sleep $ABOUT_BOX_SHOW_TIME
echo '----About menu shown. Now will quit pgAdmin.'
# Move to pgAdmin4 close at top and click
xdotool mousemove 1415 45 click 1
sleep 1
xdotool key "Return"
echo '----pgAdmin is closed.'
# Final Msg
echo ''
echo '***********************************************************'
echo 'pgAdmin desktop version verified successfully.'
echo '***********************************************************'
echo ''
}
_verify_installed_pgadmin(){
# Take pgAdmin mode as argument
mode=$1
if [ "$mode" = "desktop" ]; then
_verify_installed_pgadmin_dektop_mode
elif [ "$mode" = "server" ]; then
_verify_installed_pgadmin_server_mode
else
echo '*********Verifying both modes*********'
_verify_installed_pgadmin_dektop_mode
_verify_installed_pgadmin_server_mode
fi
}
_get_build_date(){
# Take build date
set +e
build_type=$1
if [ "$build_type" = "cb" ]; then
default_date=$(date +'%Y-%m-%d')-1
read -r -p "----Enter the caididate build date. Press enter to select default.[default:$(date +'%Y-%m-%d')-1]." date
date="${date:=$default_date}"
echo '----Selected candidate build date is - '$date
BUILD_DATE=$date
else
default_date=$(date +'%Y-%m-%d')
read -r -p "----Enter the snapshot build date. Press enter to select default.[default:$(date +'%Y-%m-%d')]." date
date="${date:=$default_date}"
echo '----Selected snapshot build date is - '$date
BUILD_DATE=$date
fi
set -e
}
_update_repo(){
set +e
repo=$(rpm -qa | grep pgadmin4)
if [[ ! -z "$repo" ]]; then
REPO_EXISTS=1
fi
build_type=$1
set +e
if [ "$build_type" = "cb" ]; then
if [ ${IS_REDHAT} == 1 ]; then
# Remove old repo if exists
if [ ${REPO_EXISTS} == 1 ]; then
echo '----Removing old repo'
sudo rpm -e pgadmin4-redhat-repo
fi
# From url
url='https://developer.pgadmin.org/builds/'$BUILD_DATE'/yum/pgadmin4-redhat-repo-2-1.noarch.rpm'
elif [ ${IS_FEDORA} == 1 ]; then
# Remove old repo if exists
if [ ${REPO_EXISTS} == 1 ]; then
echo '----Removing old repo'
sudo rpm -e pgadmin4-fedora-repo
fi
# From url
url='https://developer.pgadmin.org/builds/'$BUILD_DATE'/yum/pgadmin4-fedora-repo-2-1.noarch.rpm'
fi
else
if [ ${IS_REDHAT} == 1 ]; then
# Remove old repo if exists
if [ ${REPO_EXISTS} == 1 ]; then
echo '----Removing old repo'
sudo rpm -e pgadmin4-redhat-repo
fi
# From url
url='https://ftp.postgresql.org/pub/pgadmin/pgadmin4/snapshots/'$BUILD_DATE'/yum/pgadmin4-redhat-repo-2-1.noarch.rpm'
elif [ ${IS_FEDORA} == 1 ]; then
# Remove old repo if exists
if [ ${REPO_EXISTS} == 1 ]; then
echo '----Removing old repo'
sudo rpm -e pgadmin4-fedora-repo
fi
# From url
url='https://ftp.postgresql.org/pub/pgadmin/pgadmin4/snapshots/'$BUILD_DATE'/yum/pgadmin4-fedora-repo-2-1.noarch.rpm'
fi
fi
set -e
# Add repo config
echo '----Creating repo config'
echo '----Using url - '$url
echo ''
sudo rpm -i $url
}
_upgrade_pgadmin_to_candidate_build(){
# Get args
mode=$1
mode=$([ "$mode" == "" ] && echo "Server & Desktop" || echo "$mode")
echo ''
echo '***********************************************************'
echo 'Upgrading pgAdmin to candidate build : - '$mode
echo '***********************************************************'
echo ''
echo '******Configuring repo .*******'
# Take candidate build date
_get_build_date cb
# Update repo data
_update_repo cb
# Upgrade
echo '******Starting upgrade .*******'
suffix=""
if [ "$mode" = "desktop" ]; then
echo '----Will start upgrading pgadmin desktop'
sudo yum upgrade pgadmin4-desktop -y
suffix="desktop"
elif [ "$mode" = "server" ]; then
echo '----Upgrading pgAdmin4-web'
sudo yum upgrade pgadmin4-web -y
suffix="web"
else
echo '----Upgrading pgAdmin4 both modes'
sudo yum upgrade pgadmin4 -y
sudo -E /usr/pgadmin4/bin/setup-web.sh --yes
fi
# Check version
pgadmin_version=$(sudo rpm -qa | grep -i pgAdmin4"${suffix}")
# Final msg
echo ''
echo '***********************************************************'
echo 'pgAdmin upgraded to canidate build successfully - '"${pgadmin_version}"
echo '***********************************************************'
echo ''
}
_install_candidate_build_pgadmin(){
# Take pgAdmin mode as argument
mode=$1
mode=$([ "$mode" == "" ] && echo "Server & Desktop" || echo "$mode")
# Info
echo ''
echo '***********************************************************'
echo 'Installing Candidate build pgAdmin mode: - '$mode
echo '***********************************************************'
echo ''
echo '******Configuring repo .*******'
# Take candidate build date
_get_build_date cb
# Update repo data
_update_repo cb
# Check mode
echo '******Starting installtion .*******'
suffix=""
if [ "$mode" = "desktop" ]; then
echo '----Installing pgAdmin4-desktop'
sudo yum install pgadmin4-desktop -y
suffix="-desktop"
elif [ "$mode" = "server" ]; then
echo '----Installing pgAdmin4-web'
sudo yum install pgadmin4-web -y
suffix="-web"
# Configure the webserver, if you installed pgadmin4-web:
sudo -E /usr/pgadmin4/bin/setup-web.sh --yes
else
echo '----Installing pgAdmin4 both modes'
sudo yum install pgadmin4 -y
sudo -E /usr/pgadmin4/bin/setup-web.sh --yes
fi
# Check version
pgadmin_version=$(sudo rpm -qa | grep -i pgAdmin4"${suffix}")
echo ''
echo '***********************************************************'
echo 'pgAdmin Candidate build installed successfully - '"${pgadmin_version}"
echo '***********************************************************'
echo ''
}
_install_snapshot_build_pgadmin(){
# Take pgAdmin mode as argument
mode=$1
mode=$([ "$mode" == "" ] && echo "Server & Desktop" || echo "$mode")
# Info
echo ''
echo '***********************************************************'
echo 'Installing Snapshot build pgAdmin mode: - '$mode
echo '***********************************************************'
echo ''
echo '******Configuring repo .*******'
# Take snapshot build date
_get_build_date
# Update repo data
_update_repo
# Check mode
echo '******Starting installtion .*******'
suffix=""
if [ "$mode" = "desktop" ]; then
echo '----Installing pgAdmin4-desktop'
sudo yum install pgadmin4-desktop -y
suffix="-desktop"
elif [ "$mode" = "server" ]; then
echo '----Installing pgAdmin4-web'
sudo yum install pgadmin4-web -y
suffix="-web"
# Configure the webserver, if you installed pgadmin4-web:
sudo -E /usr/pgadmin4/bin/setup-web.sh --yes
else
echo '----Installing pgAdmin4 both modes'
sudo yum install pgadmin4 -y
sudo -E /usr/pgadmin4/bin/setup-web.sh --yes
fi
# Check version
pgadmin_version=$(sudo rpm -qa | grep -i pgAdmin4"${suffix}")
echo ''
echo '***********************************************************'
echo 'pgAdmin Snapshot build installed successfully - '"${pgadmin_version}"
echo '***********************************************************'
echo ''
}
_install_older_version(){
# Take pgAdmin mode, version as argument
mode=$1
mode=$([ "$mode" == "" ] && echo "Server & Desktop" || echo "$mode")
# Take version
set +e
default_version=""
read -r -p "----Enter the pgadmin version." version
version="${version:=$default_version}"
echo '----Entered version is - '$version
set -e
if [ "$version" = "" ]; then
echo 'Version is not specified.'
else
# Info
echo ''
echo '***********************************************************'
echo 'Installing pgadmin version: - '$version
echo '***********************************************************'
echo ''
echo '******Downloading package.*******'
if [ ${IS_REDHAT} == 1 ]; then
# From url
os_name=$(grep -oP '(?<=^ID=).+' /etc/os-release | tr -d '"')
os_version_minor=$(grep -oP '(?<=^VERSION_ID=).+' /etc/os-release | tr -d '"')
os_version=${os_version_minor%.*}
os_variant=$(grep -oP '(?<=^VARIANT_ID=).+' /etc/os-release | tr -d '"')
os_flavour="$os_name"-"$os_version""${os_variant^}"-"$(arch)"
url=https://pgadmin-archive.postgresql.org/pgadmin4/yum/redhat/$os_flavour/
desktop_url="$url"pgadmin4-desktop-"$version"-1.el"$os_version"."$(arch)".rpm
server_url="$url"pgadmin4-server-"$version"-1.el"$os_version"."$(arch)".rpm
web_url="$url"pgadmin4-web-"$version"-1.el"$os_version"."$(arch)".rpm
desktop_rpm=pgadmin4-desktop-"$version"-1.el"$os_version"."$(arch)".rpm
server_rpm=pgadmin4-server-"$version"-1.el"$os_version"."$(arch)".rpm
web_rpm=pgadmin4-web-"$version"-1.el"$os_version"."$(arch)".rpm
elif [ ${IS_FEDORA} == 1 ]; then
# form the url
os_name=$(grep -oP '(?<=^ID=).+' /etc/os-release | tr -d '"')
os_version=$(grep -oP '(?<=^VERSION_ID=).+' /etc/os-release | tr -d '"')
os_variant=$(grep -oP '(?<=^VARIANT_ID=).+' /etc/os-release | tr -d '"')
os_flavour="$os_name"-"$os_version""${os_variant^}"-"$(arch)"
url=https://pgadmin-archive.postgresql.org/pgadmin4/yum/fedora/$os_flavour/
desktop_url="$url"pgadmin4-desktop-"$version"-1.fc"$os_version"."$(arch)".rpm
server_url="$url"pgadmin4-server-"$version"-1.fc"$os_version"."$(arch)".rpm
web_url="$url"pgadmin4-web-"$version"-1.fc"$os_version"."$(arch)".rpm
desktop_rpm=pgadmin4-desktop-"$version"-1.fc"$os_version"."$(arch)".rpm
server_rpm=pgadmin4-server-"$version"-1.fc"$os_version"."$(arch)".rpm
web_rpm=pgadmin4-web-"$version"-1.fc"$os_version"."$(arch)".rpm
fi
if curl --output /dev/null --silent --head --fail "$server_url"; then
echo '----Package found.'
curl -O $server_url
curl -O $desktop_url
curl -O $web_url
echo '******Starting installtion .*******'
echo '*****Need to install released verison first and then will downgrade .*******'
_install_released_pgadmin
echo '******Now will downgrade .*******'
sudo dnf install ./$server_rpm --allowerasing -y
# Check version
pgadmin_version=$(sudo rpm -qa | grep -i pgAdmin4)
echo ''
echo '***********************************************************'
echo 'pgAdmin Older version installed - '$pgadmin_version
echo '***********************************************************'
echo ''
else
echo '################ Package for version specified does NOT exist -'$version
fi
fi
}
_uninstall(){
# Take pgAdmin mode as argument
mode=$1
mode=$([ "$mode" == "" ] && echo "Server & Desktop" || echo "$mode")
# Info
echo ''
echo '***********************************************************'
echo 'Uninstalling pgAdmin mode: - '$mode
echo '***********************************************************'
echo ''
# Check mode
if [ "$mode" = "desktop" ]; then
echo '----Uninstalling pgAdmin4-desktop'
sudo yum remove pgadmin4-desktop -y
elif [ "$mode" = "server" ]; then
echo '----Uninstalling pgAdmin4-web'
sudo yum remove pgadmin4-web -y
else
echo '----Uninstalling pgAdmin4 both modes'
sudo yum remove pgadmin4* -y
fi
echo '----Earsing pgAdmin4 both modes'
sudo yum erase pgadmin4*
echo '----Clean cache'
sudo yum clean all
# Info
echo ''
echo '***********************************************************'
echo 'pgAdmin uninstalled successfully - mode: - '$mode
echo '***********************************************************'
echo ''
read -r -p 'Do you want to delete DATA DIR(y/N)' response
case ${response} in
y|Y )
set +e
echo '----Deleting DATA DIR'
if [ "$mode" = "desktop" ]; then
echo '----Deleting /home/'$SUDO_USER'/.pgadmin/'
rm -rf /home/$SUDO_USER/.pgadmin/*
rmdir /home/$SUDO_USER/.pgadmin
elif [ "$mode" = "server" ]; then
echo '----Deleting /var/lib/pgadmin/'
sudo -E rm -rf /var/lib/pgadmin/*
sudo -E rmdir /var/lib/pgadmin/
else
echo '----Deleting /home/'$SUDO_USER'/.pgadmin/'
rm -rf /home/$SUDO_USER/.pgadmin/*
rmdir /home/$SUDO_USER/.pgadmin/
echo '----Deleting /var/lib/pgadmin/'
sudo -E rm -rf /var/lib/pgadmin/*
sudo -E rmdir /var/lib/pgadmin/
fi
set -e
echo '----DATA DIR is Deleted.'
;;
* )
echo '----DATA DIR is NOT Deleted.'
echo ''
esac
}
# Trigger actual operations
if [ "$operation" = "install" ]; then
# Install released pgAdmin
_install_released_pgadmin $mode
elif [ "$operation" = "uninstall" ]; then
# Uninstall candidate build pgAdmin
_uninstall $mode
elif [ "$operation" = "install_old" ]; then
# Install candidate build pgAdmin
_install_older_version $mode
elif [ "$operation" = "install_cb" ]; then
# Install candidate build pgAdmin
_install_candidate_build_pgadmin $mode
elif [ "$operation" = "install_snapshot" ];then
# Insall snapshot
_install_snapshot_build_pgadmin $mode
elif [ "$operation" = "verify" ]; then
# Verify pgAdmin
_verify_installed_pgadmin $mode
elif [ "$operation" = "upgrade_cb" ]; then
# Upgrade pgAdmin
_upgrade_pgadmin_to_candidate_build $mode
elif [ "$operation" = "upgrade_test" ]; then
# Install released pgAdmin
_install_released_pgadmin $mode
echo 'Press any key to continue... '
read var
# Verify released pgAdmin
_verify_installed_pgadmin $mode
echo 'Press any key to continue... '
read var
# Upgrade pgAdmin
_upgrade_pgadmin_to_candidate_build $mode
echo 'Press any key to continue... '
read var
# Verify upgraded pgAdmin
_verify_installed_pgadmin $mode
echo 'Press any key to continue... '
read var
elif [ "$operation" = "fresh_test" ]; then
# Install candidate build pgAdmin
_install_candidate_build_pgadmin $mode
echo 'Press any key to continue... '
read var
# Verify upgraded pgAdmin
_verify_installed_pgadmin $mode
echo 'Press any key to continue... '
read var
else
echo 'Specify correct operation:install, verify, upgrade, all, uninstall'
fi
echo ''
echo '!!!!!!! THANK YOU !!!!!!!'
echo ''