post-install.sh 4.94 KB
Newer Older
1 2 3 4
#! /bin/bash
#
# When cygwin is installed, then call this script by Administrator:
#
5
#    /bin/bash/ --login -i post-install.sh PREFIX
6
#
7 8
# It will do:
#
9
#    * Set uid of Adminstrator to 0, and create root account
10
#
11
#    * Create .minttyrc and cygtty.bat, which used to start comand console
12
#
13
#    * Create autorebase.bat, it used to fix cygwin dll problem
14
#
15
#    * Change readme.txt to dos format
16
#
17 18
#    * Set prefix for this slapos node
#
19 20
function show_error_exit()
{
21
    echo Error: ${1:-"Run post-install script failed."}
22 23 24
    read -n 1 -p "Press any key to exit..."
    exit 1
}
25
readonly -f show_error_exit
26

27
declare -r slapos_prefix=$1
28
declare -r _cygroot=$(cygpath -w /)
29

30 31 32 33 34
_filename=/etc/passwd
echo "Checking ${_filename} ..."
if [[ ! -f ${_filename} ]] ; then
    mkpasswd -l > ${_filename} || show_error_exit "Error: mkpasswd failed"
    echo "${_filename} has been generated."
35
else
36
    echo OK.
37 38
fi

39 40 41 42 43
_filename=/etc/group
echo "Checking ${_filename} ..."
if [[ ! -f ${_filename} ]] ; then
    mkgroup -l > ${_filename} || show_error_exit "Error: mkgroup failed"
    echo "${_filename} has been generated."
44
else
45
    echo OK.
46 47
fi

48
# grep -q "^root:" ${password_filename}
49
# if (( $? != 0 )) ; then
50
#     myaccount=$(grep "^Administrator:" ${password_filename} | \
51 52
#               sed -e "s/Administrator:unused:500:/root:unused:0:/g")
#     if [[ "${myaccount:0:4}" == root ]] ; then
53
#         echo $myaccount >> ${password_filename}
54 55 56 57
#     else
#         exit 1
#     fi
# fi
58

59
_charset=$(ipwin codepage) || _charset=""
60
echo "Windows OEM Codepage is ${_charset}"
61

62
_filename=".minttyrc"
63 64 65
echo Checking  ${_filename} ...
if [[ ! -f ${_filename} ]] ; then
    cat <<EOF > ${_filename}
66 67 68 69
BoldAsFont=no
Font=Courier New
FontHeight=16
Scrollbar=none
70
Locale=C
71
Charset=${_charset}
72
EOF
73
    echo "${_filename} has been generated."
74 75
else
    echo OK.
76 77
fi

78 79 80 81
_filename="/cygtty.bat"
echo Checking  ${_filename} ...
if [[ ! -x ${_filename} ]] ; then
    cat <<EOF > ${_filename}
82 83
@echo off

84 85
${_cygroot:0:2}
chdir ${_cygroot}\\bin
86 87 88

start mintty.exe -i /Cygwin-Terminal.ico -
EOF
89
    chmod +x ${_filename}
90
    echo "${_filename} has been generated."
91 92
else
    echo OK.
93 94
fi

95 96 97
_filename="/autorebase.bat"
echo Checking  ${_filename} ...
if [[ ! -f ${_filename} ]] ; then
98
    cat <<EOF > ${_filename}
99
@echo off
100 101 102 103 104 105 106 107 108 109 110 111
${_cygroot:0:2}
CHDIR ${_cygroot}
${_cygroot}\bin\find /opt/slapos -name "*.dll" > ${_cygroot}\myfile.list
IF EXIST ${_cygroot}\opt\slapgrid. ${_cygroot}\bin\find /opt/slapgrid -name "*.dll" >> ${_cygroot}\myfile.list
bin\bash --login -c "for pid in \$(ps | grep '/usr/bin/openvpn' | gawk '{print $4}') ; do TASKKILL /F /T /PID \$pid ; done"
NET STOP ${slapos_prefix}re6stnet
NET STOP ${slapos_prefix}cygserver
NET STOP ${slapos_prefix}syslog-ng
NET STOP ${slapos_prefix}cron
NET STOP ${slapos_prefix}sshd
bin\bash --login -c "for pid in \$(ps | grep '/usr/bin/python2.7' | gawk '{print \$4}') ; do TASKKILL /F /T /PID \$pid ; done"
PATH .\bin;%PATH%
112
dash /bin/rebaseall -T /myfile.list -v
113
EXIT 0
114
EOF
115
    chmod +x ${_filename}
116
    echo "${_filename} has been generated."
117 118
else
    echo OK.
119 120
fi

121
# Change format of readme.txt
122 123
_filename=$(cygpath -u $(cygpath -m /)/../readme.txt)
if [[ -f ${_filename} ]] ; then
124
    echo "Changing $(cygpath -w ${_filename}) as dos format ..."
125
    unix2dos ${_filename} && echo OK.
126 127
fi

128
# Backup slap-runner.html
129 130
_filename=/etc/slapos/scripts/slap-runner.html
if [[ -r ${_filename} ]] ; then
131
    echo "Backuping ${_filename} as ${_filename}.orig"
132 133
    cp ${_filename}{,.orig} && echo OK.
else
134
    echo "Warning: missing ${_filename}"
135
fi
136

137
# Unzip slapos.tar.gz
138 139
_filename=/opt/downloads/slapos.tar.gz
if [[ -r ${_filename} ]] ; then
140
    echo "Extracting ${_filename} ..."
141 142 143
    (cd /opt ; tar xzf ${_filename} --no-same-owner) || show_error_exit
    echo OK.
elif [[ ! -d /opt/slapos ]] ; then
144
    echo "Warning: missing ${_filename}"
145 146
fi

147 148 149
# Patch cygport, so that we can specify package prefix by ourself.
_filename=/usr/bin/cygport
if [[ -f ${_filename} ]] ; then
150
    echo "Patching ${_filename} ..."
151 152 153
    sed -i -e 's/D="${workdir}\/inst"/D="${CYGCONF_PREFIX-${workdir}\/inst}"/g' ${_filename} &&
    echo OK.
fi
154 155
_filename=/usr/share/cygport/cygclass/autotools.cygclass
if [[ -f ${_filename} ]] ; then
156
    echo "Patching ${_filename} ..."
157 158 159 160 161
    sed -i -e 's/prefix=$(__host_prefix)/prefix=${CYGCONF_PREFIX-$(__host_prefix)}/g' ${_filename} &&
    echo OK.
fi
_filename=/usr/share/cygport/cygclass/cmake.cygclass
if [[ -f ${_filename} ]] ; then
162
    echo "Patching ${_filename} ..."
163 164 165 166
    sed -i -e 's/-DCMAKE_INSTALL_PREFIX=$(__host_prefix)/-DCMAKE_INSTALL_PREFIX=${CYGCONF_PREFIX-$(__host_prefix)}/g' ${_filename} &&
    echo OK.
fi

167 168 169
# Set prefix for slapos
if [[ -n ${slapos_prefix} ]] ; then
    echo "Set slapos prefix as ${slapos_prefix}"
170
    sed -i -e "s%slapos_prefix=.*\$%slapos_prefix=${slapos_prefix}%" \
171
        /etc/slapos/scripts/pre-uninstall.sh /etc/slapos/scripts/slapos-include.sh
172 173
else
    echo "Set slapos prefix to empty"
174 175
fi

176
echo
177
echo "Run post-install.sh script successfully."
178
echo
179
read -n 1 -t 60 -p "Press any key to exit..."
180
exit 0