@@ -55,112 +55,135 @@ function uses_systemd(plat) {
5555}
5656
5757function get_platform_text ( p ) {
58- var a = p . split ( '-' ) ;
58+ const a = p . split ( '-' ) ;
5959 return get_platform_name ( a [ 0 ] , a [ 1 ] ) + ' version ' + a [ 1 ] ;
6060}
6161
6262window . onload = function ( ) {
63- for ( var p in supported_versions ) {
64- var opt = document . createElement ( 'option' ) ;
65- opt . text = supported_versions [ p ] ;
66- document . getElementById ( 'version' ) . add ( opt ) ;
67- }
68-
69- loadPlatforms ( ) ;
70- archChanged ( ) ;
71- }
72-
73- function verChanged ( ) {
74- /* Just update like the architecture changed */
75- archChanged ( ) ;
76- }
77-
78- function loadPlatforms ( ) {
79- var platbox = document . getElementById ( 'platform' ) ;
80-
81- while ( platbox . options . length > 0 ) {
82- platbox . options . remove ( 0 ) ;
83- }
84- var opt = document . createElement ( 'option' ) ;
85- opt . text = '* Select your platform' ;
86- opt . value = - 1 ;
87- platbox . add ( opt ) ;
88-
89- platkeys = Object . keys ( repodata [ 'platforms' ] ) . sort ( ) ;
90- for ( var pp in platkeys ) {
91- var opt = document . createElement ( 'option' ) ;
92- opt . text = get_platform_text ( platkeys [ pp ] ) ;
93- opt . value = platkeys [ pp ] ;
94- platbox . add ( opt ) ;
95- }
96-
97- platChanged ( ) ;
63+ const platbox = document . getElementById ( 'platform' ) ;
64+ const platkeys = Object . keys ( repodata [ 'platforms' ] ) . sort ( ) ;
65+
66+ let opt = document . createElement ( 'option' ) ;
67+ opt . text = '* Select your platform' ;
68+ opt . value = "-1" ;
69+ platbox . add ( opt ) ;
70+
71+ for ( const pp in platkeys ) {
72+ opt = document . createElement ( 'option' ) ;
73+ opt . text = get_platform_text ( platkeys [ pp ] ) ;
74+ opt . value = platkeys [ pp ] ;
75+ platbox . add ( opt ) ;
76+ }
77+
78+ platChanged ( )
9879}
9980
10081function platChanged ( ) {
101- var plat = document . getElementById ( 'platform' ) . value ;
102- var archbox = document . getElementById ( 'arch' ) ;
82+ const plat = document . getElementById ( 'platform' ) . value ;
83+ const archbox = document . getElementById ( 'arch' ) ;
10384
104- while ( archbox . options . length > 0 ) {
105- archbox . options . remove ( 0 ) ;
106- }
85+ while ( archbox . options . length > 0 ) {
86+ archbox . options . remove ( 0 ) ;
87+ }
10788
108- if ( plat == - 1 ) {
109- archChanged ( ) ;
110- return ;
111- }
89+ if ( ! plat || plat === "-1" ) {
90+ archChanged ( ) ;
91+ return ;
92+ }
11293
113- for ( a in repodata [ 'platforms' ] [ plat ] . sort ( ) . reverse ( ) ) {
114- var opt = document . createElement ( 'option' ) ;
115- opt . text = opt . value = repodata [ 'platforms' ] [ plat ] [ a ] ;
116- archbox . add ( opt ) ;
117- }
94+ let opt = document . createElement ( 'option' ) ;
95+ opt . text = '* Select your architecture' ;
96+ opt . value = "-1" ;
97+ archbox . add ( opt ) ;
11898
119- archChanged ( ) ;
99+ for ( const a in repodata [ 'platforms' ] [ plat ] . sort ( ( a , b ) => a [ 'arch' ] . localeCompare ( b [ 'arch' ] ) ) ) {
100+ opt = document . createElement ( 'option' ) ;
101+ opt . text = opt . value = repodata [ 'platforms' ] [ plat ] [ a ] [ 'arch' ] ;
102+ archbox . add ( opt ) ;
103+ }
104+
105+ archChanged ( ) ;
120106}
121107
122108function archChanged ( ) {
123- var ver = document . getElementById ( 'version' ) . value ;
124- var plat = document . getElementById ( 'platform' ) . value ;
125- var arch = document . getElementById ( 'arch' ) . value ;
126- var scriptBox = document . getElementById ( 'script-box' )
127-
128- if ( ! plat || plat == - 1 ) {
129- document . getElementById ( 'copy-btn' ) . style . display = 'none' ;
130- scriptBox . innerHTML = 'Select version and platform above' ;
131- return ;
109+ const plat = document . getElementById ( 'platform' ) . value ;
110+ const arch = document . getElementById ( 'arch' ) . value ;
111+ const verbox = document . getElementById ( 'version' ) ;
112+
113+ while ( verbox . options . length > 0 ) {
114+ verbox . options . remove ( 0 ) ;
115+ }
116+
117+ if ( ! arch || arch === "-1" ) {
118+ verChanged ( ) ;
119+ return ;
120+ }
121+
122+ let opt = document . createElement ( 'option' ) ;
123+ opt . text = '* Select your required PostgreSQL version' ;
124+ opt . value = "-1" ;
125+ verbox . add ( opt ) ;
126+
127+ let versions = [ ]
128+ for ( const a in repodata [ 'platforms' ] [ plat ] ) {
129+ if ( repodata [ 'platforms' ] [ plat ] [ a ] [ 'arch' ] === arch ) {
130+ versions = repodata [ 'platforms' ] [ plat ] [ a ] [ 'versions' ]
131+ break
132132 }
133+ }
133134
134- var pinfo = repodata [ 'platforms' ] [ plat ] ;
135- var shortver = ver . replace ( '.' , '' ) ;
136-
137- var url = 'https://download.postgresql.org/pub/repos/yum/reporpms/' + plat + '-' + arch + '/pgdg-' + get_rpm_prefix ( plat ) + '-repo-latest.noarch.rpm' ;
138-
139- var installer = get_installer ( plat ) ;
140- scriptBox . innerHTML = '# Install the repository RPM:\n' ;
141- scriptBox . innerHTML += 'sudo ' + installer + ' install -y ' + url + '\n\n' ;
142-
143- if ( disable_module_on ( plat ) ) {
144- scriptBox . innerHTML += '# Disable the built-in PostgreSQL module:\n' ;
145- scriptBox . innerHTML += 'sudo dnf -qy module disable postgresql\n\n' ;
146- }
135+ for ( const a in versions . sort ( ) ) {
136+ if ( supported_versions . includes ( parseInt ( versions [ a ] ) ) ) {
137+ opt = document . createElement ( 'option' ) ;
138+ opt . text = opt . value = versions [ a ] ;
139+ verbox . add ( opt ) ;
140+ }
141+ }
147142
148- scriptBox . innerHTML += '# Install PostgreSQL:\n' ;
149- scriptBox . innerHTML += 'sudo ' + installer + ' install -y postgresql' + shortver + '-server\n\n' ;
143+ verChanged ( ) ;
144+ }
150145
151- scriptBox . innerHTML += '# Optionally initialize the database and enable automatic start:\n' ;
152- if ( uses_systemd ( plat ) ) {
153- var setupcmd = 'postgresql-' + shortver + '-setup' ;
154- if ( ver < 10 ) {
155- setupcmd = 'postgresql' + shortver + '-setup' ;
156- }
157- scriptBox . innerHTML += 'sudo /usr/pgsql-' + ver + '/bin/' + setupcmd + ' initdb\nsudo systemctl enable postgresql-' + ver + '\nsudo systemctl start postgresql-' + ver ;
158- }
159- else {
160- scriptBox . innerHTML += 'sudo service postgresql-' + ver + ' initdb\nsudo chkconfig postgresql-' + ver + ' on\nsudo service postgresql-' + ver + ' start' ;
161- }
146+ function verChanged ( ) {
147+ var ver = document . getElementById ( 'version' ) . value ;
148+ var plat = document . getElementById ( 'platform' ) . value ;
149+ var arch = document . getElementById ( 'arch' ) . value ;
150+ var scriptBox = document . getElementById ( 'script-box' )
151+
152+ if ( ! ver || ver === "-1" ) {
153+ document . getElementById ( 'copy-btn' ) . style . display = 'none' ;
154+ scriptBox . innerHTML = 'Select platform, architecture, and version above' ;
155+ return ;
156+ }
157+
158+ var shortver = ver . replace ( '.' , '' ) ;
159+
160+ var url = 'https://download.postgresql.org/pub/repos/yum/reporpms/' + plat + '-' + arch + '/pgdg-' + get_rpm_prefix ( plat ) + '-repo-latest.noarch.rpm' ;
161+
162+ var installer = get_installer ( plat ) ;
163+ scriptBox . innerHTML = '# Install the repository RPM:\n' ;
164+ scriptBox . innerHTML += 'sudo ' + installer + ' install -y ' + url + '\n\n' ;
165+
166+ if ( disable_module_on ( plat ) ) {
167+ scriptBox . innerHTML += '# Disable the built-in PostgreSQL module:\n' ;
168+ scriptBox . innerHTML += 'sudo dnf -qy module disable postgresql\n\n' ;
169+ }
170+
171+ scriptBox . innerHTML += '# Install PostgreSQL:\n' ;
172+ scriptBox . innerHTML += 'sudo ' + installer + ' install -y postgresql' + shortver + '-server\n\n' ;
173+
174+ scriptBox . innerHTML += '# Optionally initialize the database and enable automatic start:\n' ;
175+ if ( uses_systemd ( plat ) ) {
176+ var setupcmd = 'postgresql-' + shortver + '-setup' ;
177+ if ( ver < 10 ) {
178+ setupcmd = 'postgresql' + shortver + '-setup' ;
179+ }
180+ scriptBox . innerHTML += 'sudo /usr/pgsql-' + ver + '/bin/' + setupcmd + ' initdb\nsudo systemctl enable postgresql-' + ver + '\nsudo systemctl start postgresql-' + ver ;
181+ }
182+ else {
183+ scriptBox . innerHTML += 'sudo service postgresql-' + ver + ' initdb\nsudo chkconfig postgresql-' + ver + ' on\nsudo service postgresql-' + ver + ' start' ;
184+ }
162185
163- document . getElementById ( 'copy-btn' ) . style . display = 'block' ;
186+ document . getElementById ( 'copy-btn' ) . style . display = 'block' ;
164187}
165188
166189/* Event handlers */
0 commit comments