summaryrefslogtreecommitdiffstats
path: root/abs/core-testing/mythinstall/install_proxy.sh
blob: a1a722ec8a92b45eee1dc96605232d0afb8bfccd (plain)
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
#!/bin/bash
disk=$2
rootfs=$3
rootsize=$4
datafs=$5
datasize=$6
swapsize=$7
mountpoint="/new_boot"
run=/root/install_functions.sh
. /etc/systemconfig 2>/dev/null
 

progress () {
mypercent=`echo "$1" | cut -d. -f1`
if [  x$mypercent = x ]
then
echo "" > /tmp/.install_percent
else
echo "${mypercent}% complete" > /tmp/.install_percent
fi


}

full_install () {
    if [ -f /tmp/.this_is_upgrade ]
    then
        rm /tmp/.this_is_upgrade
    fi
    echo "Partitioning $disk" > /tmp/.install_state
    progress 1
    sleep 1
    $run partition_it $disk $rootsize $datasize $swapsize

    echo "Formating $disk" > /tmp/.install_state
        progress 2
    sleep 1
    $run format_it $disk $rootfs $datafs

    echo "Preparing $disk" > /tmp/.install_state
    progress 3
    sleep 1
    $run mount_it $disk

    startsize=`statgrab -M disk.|grep $disk.write_bytes|cut -d= -f 2|tr -d " "`

    echo "STARTSIZE=$startsize">/tmp/.startsize.io
    echo "Installing data" > /tmp/.install_state

    sleep 1
        $run copy_it $disk ALL
        $run fstab_fix_it $disk $rootfs $datafs

    progress 99
    sleep 1
    $run grub_it $disk

    echo "Configuring system" > /tmp/.install_state
        progress 100
        sleep 1
        cp -f /etc/systemconfig "$mountpoint"/etc
    #run save syssettings to save settings, then copy to new mountpoint
        /root/restore_default_settings.sh  -c save -t syssettings -h myhost -d 127.0.0.1
        SE=/usr/share/templates/settings/syssettings
        mkdir -p ${mountpoint}$SE
        cp -rp $SE/*  ${mountpoint}$SE/
        chown root:mythtv "$mountpoint"/etc/systemconfig
        chown -R mythtv:mythtv ${mountpoint}$SE

        chmod -R 775   ${mountpoint}$SE
        chmod 775 "$mountpoint"/etc/systemconfig
        #copy over any updates that might have occured
        cp -f /root/*.sh "$mountpoint"/root/
        chmod -R 755 ${mountpoint}/root
        cp /etc/mtab "$mountpoint"/etc/mtab
        chroot "$mountpoint" /root/systemconfig.sh misc,hostype,network

    if  [ $SystemType = "Master_backend" -o $SystemType = "Standalone"  ]
    then
            #installing DB to local machine

            chroot "$mountpoint"   /root/install_db_chroot.sh
    else
            #update remotedb with this host settings
            chroot "$mountpoint" /root/restore_default_settings.sh -c restore -t Default
            chroot "$mountpoint" /root/restore_default_settings.sh -c restore -t syssettings
            #Run second time
            chroot "$mountpoint" /root/systemconfig.sh misc,hostype,network
    fi
    echo "Done" > /tmp/.install_state
    $run unmount_it $disk
}




function upgrade () {
    touch /tmp/.this_is_upgrade

    if [ ! x$rootfs = "xDo_not_format" ]
    then
        echo "Formating $disk" > /tmp/.install_state
            progress 2
            sleep 1
            $run format_it $disk $rootfs NO
    fi


    echo "Preparing $disk" > /tmp/.install_state
        progress 3
        sleep 1
        $run mount_it $disk
        startsize=`statgrab -M disk.|grep $disk.write_bytes|cut -d= -f 2|tr -d " "`
        echo "STARTSIZE=$startsize">/tmp/.startsize.io
        echo "Installing data" > /tmp/.install_state
        sleep 1
        cp -rf /tmp/etc /new_boot/etc.old
        cp -rf  /tmp/oss /new_boot/var/lib/oss.old
        $run copy_it $disk bin.lzm,boot.lzm,etc.lzm,home.lzm,lib.lzm,opt.lzm,root.lzm,sbin.lzm,usr.lzm,var.lzm

        if [  x$rootfs = "xDo_not_format" ]
        then
            rootfs=`grep ${disk}1 /tmp/etc/fstab |awk ' { print $3 } '`
        fi
            datafs=`grep ${disk}3 /tmp/etc/fstab |awk ' { print $3 } '`
        $run fstab_fix_it $disk $rootfs $datafs

    echo "Writing boot sector" > /tmp/.install_state
        progress 99
        sleep 1
        $run grub_it $disk


    echo "Configuring system" > /tmp/.install_state
        progress
        sleep 1
        cp /etc/mtab "$mountpoint"/etc/mtab
        cp -f /etc/systemconfig "$mountpoint"/etc
        cp -f /root/*.sh "$mountpoint"/root/
        chmod -R 755 ${mountpoint}/root
        chown root:mythtv "$mountpoint"/etc/systemconfig
        chmod 775 "$mountpoint"/etc/systemconfig
        chroot "$mountpoint" /root/systemconfig.sh misc,hostype,network
    #  chroot "$mountpoint" /root/restore_default_settings.sh restore Default
        chroot "$mountpoint" /root/restore_default_settings.sh -c restore -t syssettings
    #Run second time
        chroot "$mountpoint" /root/systemconfig.sh misc,hostype,network
    #  fi

    echo "Done" > /tmp/.install_state

    $run unmount_it $disk
}



function killdhcp () {
if [ -f /etc/dhcpc/dhcpcd-eth0.pid ]
        then
            pid=`cat /etc/dhcpc/dhcpcd-eth0.pid`
            kill -9 $pid
            rm -f /etc/dhcpc/dhcpcd-eth0.pid
            rm -f /var/run/dhcpcd*
        fi
if [ -f /var/run/dhcpcd-eth0.pid ]
        then
            pid=`cat /var/rundhcpcd-eth0.pid`
            kill -9 $pid
            rm -f /var/run/dhcpcd-eth0.pid*
        fi
ip address flush dev eth0
}

function network_setup () {
DEVICE=eth0
    if [ ! -f /etc/systemconfig ]
    then
        exit 1
    fi
killdhcp

if [ $UseDHCP = 0 ]
then
        /sbin/dhcpcd $DEVICE
        if [ ! $? = 0 ]
        then
            exit 2
        fi
fi

if [ $UseDHCP = 1 ]
then

        /sbin/ifconfig $DEVICE $ip
        /sbin/route add default gw $route
        echo "nameserver $nameserver" > /etc/resolv.conf
fi


}

function SANE_SYSETTINGS () {
sed -e '/HOSTrootfstype/d' \
        -e '/HOSTrootfstype/d' \
        -e '/HOSTdatafstype/d' \
        -e '/HOSTOSsize/d'  \
        -e '/HostUseALLdata/d'  \
        -e '/HOSTDATAsize/d'    \
        -e '/HOSTuprootfstype/d'    \
        -e '/HostUseSWAP/d' \
        -e '/HOSTSWAPsize/d  ' /tmp/usr/share/templates/settings/syssettings/settings.txt  >  /tmp/settings.new
    mv  /tmp/settings.new /tmp/usr/share/templates/settings/syssettings/settings.txt
}

case $1 in
        full_install_it )

            full_install
        ;;
        find_update)
            #TRY TO mount first partition of drive
            #copy /etc/systemconfig to live,  import settings into db
            #umount drive
            $run mount_it $disk
                if [ -f /new_boot/etc/systemconfig ]
                then
                ###########ADD templates
                mkdir -p /tmp/usr/share/templates
                cp -pr /new_boot/usr/share/templates  /tmp/usr/share
                SANE_SYSETTINGS
                cp -rp /tmp/usr/share/templates/settings /usr/share/templates


                cp /new_boot/etc/systemconfig /etc/systemconfig
                cp -rf  /new_boot/etc /tmp/etc
                cp -rf /new_boot/var/lib/oss  /tmp/oss

                /root/restore_default_settings.sh -c restore -t syssettings -h myhost  -d 127.0.0.1
                fi
            $run umount_it $disk
            ;;

        upgrade_it)
                #"/root/install_proxy.sh upgrade_it " + install_drive + " " + rootfs +  "&"
                upgrade

            ;;
        disk_model_it)
                        model="unknown"
                            size="xxx"
                        case $2 in

                            h* )
                                    model=`cat /proc/ide/$2/model`
                                    ;;
                            s*)     model=`sginfo /dev/$2|grep Product|awk ' { print $2 } '`
                                    ;;
                        esac
                                size=`parted /dev/$2  print |grep Disk|awk  ' { print $3 } '  `


                                echo ""$model" $size " >/tmp/model

            ;;
        network_check_it)
                        #Should never return from check_network
                        case $2 in
                                setup_network)  network_setup
                                ;;

                                check_self)
                                            myipeth0=`ifconfig  | grep 'inet addr:'| grep -v '127.0.0.1' | cut -d: -f2 | awk '{ print $1}'|head -n1`
                                            ping -c 1 $myipeth0
                                                    if [ ! $? = 0 ]
                                                    then
                                                        exit 3
                                                        #can't ping yourself
                                                    fi
                                ;;
                                check_gw)
                                            #check gateway
                                            mygweth0=`/sbin/route |grep eth0|grep UG|awk '{ print $2}'`
                                            ping -c 1 $mygweth0
                                            if [ ! $? = 0 ]
                                            then
                                                exit 4
                                                #can't ping the gw
                                            fi
                                ;;
                                check_ns)
                                            #check nameserver
                                                    mydns=`cat /etc/resolv.conf|grep nameserver|head -1|awk '{ print $2}'`
                                                    ping -c 1 $mydns
                                                    if [ ! $? = 0 ]
                                                    then
                                                        exit 5
                                                        #can't ping the gw
                                                    fi
                                ;;
                                check_names)
                                            host google.com
                                            if [ ! $? = 0 ]
                                            then
                                                exit 6
                                                #can't ping the gw
                                            fi
                                ;;
                            esac
                        exit 0
            ;;


        * )
            state=`cat /tmp/.install_state`
            if  [  x"${state}" =  "xConfiguring system" ]
            then
                progress ""
            else
        #finding the drive
                ddrive=`df |  grep $mountpoint | head -n1 | awk -F/ ' { print $3 } ' | cut -d" " -f 1|cut -b1,2,3 `
                used=`statgrab -M disk.|grep ${ddrive}.write_bytes|cut -d= -f 2|tr -d " "`
        . /tmp/.startsize.io
        used=`echo $used-$STARTSIZE|bc`
        echo $used

        if [ ! x$used = x ]
            then
                . /root/.install_size
                #somehow find if it's an install or update
                if [ -f /tmp/.this_is_upgrade ]
                then
                    total=$UPGRADESIZE
                else
                    total=$TOTALSIZE
                fi
            percent=`echo "scale=2 ;  ($used/$total) * 100 " |bc `
            cond2=$(echo "$percent > 100" |bc  )
            if [ $cond2 -eq 1  ]
            then
            percent=100
            fi
            cond3=$(echo "$percent < 3" |bc )
            if [ $cond3 -eq 0   ]
                then
                    progress $percent
                fi
            fi
        fi
        ;;
esac