1. #!/bin/bash
    2. echo -n "please enter the password:"
    3. read password
    4. echo "new password is: $password"
    5. echo -n "please enter the mount device:"
    6. read mountDev
    7. echo "input mount device is: $mountDev"
    8. current="`pwd`"
    9. mountPath=$current/mountDir
    10. volTemp="volTemp"
    11. ret=255
    12. function return_assert(){
    13. if [ $1 -ne 0 ];then
    14. echo "return_assert: line $2 error, return $1, cmd: $3"
    15. exit 1
    16. fi
    17. }
    18. function write_rc_file(){
    19. rc_rc=${mountPath}/etc/rc.d/rc
    20. rc_local=${mountPath}/etc/rc.d/rc.local
    21. init_rc=${mountPath}/etc/init.d/rc
    22. boot_local=${mountPath}/etc/init.d/boot.local
    23. addline="/bin/bash /etc/init.d/setpasswd.sh"
    24. if [ -f $rc_rc ];then
    25. grep -n "^exit 0" $rc_rc
    26. if [ $? -eq 0 ];then
    27. line_num=`grep -n "^exit 0" ${rc_rc} | awk -F'[:]' '{print $1}'`
    28. sed -i "${line_num} i${addline}" ${rc_rc} #add line before "exit 0"
    29. else
    30. echo $addline >> $rc_rc
    31. fi
    32. chmod +x $rc_rc
    33. fi
    34. if [ -f $rc_local ];then
    35. grep -n "^exit 0" $rc_local
    36. if [ $? -eq 0 ];then
    37. line_num=`grep -n "^exit 0" ${rc_local} | awk -F'[:]' '{print $1}'`
    38. sed -i "${line_num} i${addline}" ${rc_local} #add line before "exit 0"
    39. else
    40. echo $addline >> $rc_local
    41. fi
    42. chmod +x $rc_local
    43. fi
    44. if [ -f $init_rc ];then
    45. grep -n "^exit 0" $init_rc
    46. if [ $? -eq 0 ];then
    47. line_num=`grep -n "^exit 0" ${init_rc} | awk -F'[:]' '{print $1}'`
    48. sed -i "${line_num} i${addline}" ${init_rc} #add line before "exit 0"
    49. else
    50. echo $addline >> $init_rc
    51. fi
    52. chmod +x $init_rc
    53. fi
    54. if [ -f $boot_local ];then
    55. grep -n "^exit 0" $boot_local
    56. if [ $? -eq 0 ];then
    57. line_num=`grep -n "^exit 0" ${boot_local} | awk -F'[:]' '{print $1}'`
    58. sed -i "${line_num} i${addline}" ${boot_local} #add line before "exit 0"
    59. else
    60. echo $addline >> $boot_local
    61. fi
    62. chmod +x $boot_local
    63. fi
    64. echo "write to rc success."
    65. }
    66. function write_windows_scripts(){
    67. script=${mountPath}/Windows/System32/GroupPolicy/Machine/Scripts/scripts.ini
    68. script_dir=${mountPath}/Windows/System32/GroupPolicy/Machine/Scripts
    69. if [ -f $script ];then
    70. sed -i '/^$/d' $script #strip space lines
    71. cat $script | grep -iq '\[Startup\]'
    72. if [ $? -eq 0 ];then
    73. startup_num=`grep -n "\[Startup\]" $script | cut -d ":" -f 1`
    74. cat $script | grep -iq '\[Shutdown\]'
    75. if [ $? -eq 0 ];then
    76. shutdown_num=`grep -n "\[Shutdown\]" $script | cut -d ":" -f 1`
    77. if [ "$startup_num" -gt "$shutdown_num" ];then
    78. lastline="`tail -n1 $script`"
    79. cmdline_num=`echo $lastline | grep -oE "^[0-9]+"`
    80. new_cmdline_num="`expr $cmdline_num + 1`"
    81. echo -ne "${new_cmdline_num}CmdLine=setpasswd.vbs\\r\\n" >> $script
    82. echo -ne "${new_cmdline_num}Parameters=\\r\\n" >> $script
    83. else
    84. startup_lastline_num="`expr $shutdown_num - 1`"
    85. startup_lastline=`sed -n ${startup_lastline_num}p $script`
    86. cmdline_num=`echo $startup_lastline | grep -oE "^[0-9]+"`
    87. new_cmdline_num="`expr $cmdline_num + 1`"
    88. parameters="${new_cmdline_num}Parameters=\\r\\n"
    89. cmdline="${new_cmdline_num}CmdLine=setpasswd.vbs\\r\\n"
    90. sed -i "/\[Shutdown\]/i${cmdline}" $script #insert cmdline before [Shutdown] group
    91. sed -i "/\[Shutdown\]/i${parameters}" $script
    92. fi
    93. else
    94. lastline="`tail -n1 $script`"
    95. cmdline_num=`echo $lastline | grep -oE "^[0-9]+"`
    96. new_cmdline_num="`expr $cmdline_num + 1`"
    97. echo -ne "${new_cmdline_num}CmdLine=setpasswd.vbs\\r\\n" >> $script
    98. echo -ne "${new_cmdline_num}Parameters=\\r\\n" >> $script
    99. fi
    100. else
    101. echo -ne "[Startup]\\r\\n" >> $script
    102. echo -ne "0CmdLine=setpasswd.vbs\\r\\n" >> $script
    103. echo -ne "0Parameters=\\r\\n" >> $script
    104. fi
    105. else
    106. mkdir -p $script_dir
    107. echo -ne "[Startup]\\r\\n" >> $script
    108. echo -ne "0CmdLine=setpasswd.vbs\\r\\n" >> $script
    109. echo -ne "0Parameters=\\r\\n" >> $script
    110. fi
    111. echo "write to scripts.ini success."
    112. }
    113. function create_setpasswd_sh(){
    114. filename=${mountPath}/etc/init.d/setpasswd.sh
    115. if [ -f $filename ];then
    116. rm $filename
    117. fi
    118. echo "#!/bin/bash" >> $filename
    119. echo "echo \"root:${password}\" | chpasswd" >> $filename
    120. echo "rm -f /etc/init.d/setpasswd.sh" >> $filename
    121. chmod +x $filename
    122. echo "create setpasswd.sh success."
    123. }
    124. function create_setpasswd_vbs(){
    125. filename=${mountPath}/Windows/System32/GroupPolicy/Machine/Scripts/Startup/setpasswd.vbs
    126. file_dir=${mountPath}/Windows/System32/GroupPolicy/Machine/Scripts/Startup
    127. if [ -f $filename ];then
    128. rm $filename
    129. fi
    130. mkdir -p $file_dir
    131. echo -ne "Set objUser = GetObject(\"WinNT://./Administrator,user\")\\r\\n" >> $filename
    132. echo -ne "objUser.SetPassword \"${password}\"\\r\\n" >> $filename
    133. echo -ne "objUser.SetInfo\\r\\n" >> $filename
    134. echo -ne "strPath = Wscript.ScriptFullName\\r\\n" >> $filename
    135. echo -ne "Set objFSO = CreateObject(\"Scripting.FileSystemObject\")\\r\\n" >> $filename
    136. echo -ne "Set objFile = objFSO.GetFile(strPath)\\r\\n" >> $filename
    137. echo -ne "f = objFSO.DeleteFile(objFile)\\r\\n" >> $filename
    138. echo "create setpasswd.vbs success."
    139. }
    140. function mount_dev(){
    141. if [ -d "${mountPath}/Windows/System32" ];then
    142. write_windows_scripts
    143. create_setpasswd_vbs
    144. return 0
    145. elif [ -d "${mountPath}/etc/init.d" ];then
    146. write_rc_file
    147. create_setpasswd_sh
    148. return 0
    149. fi
    150. return 1
    151. }
    152. echo "begin setpassword ..."
    153. if [ ! -d "$mountPath" ];then
    154. mkdir -p $mountPath
    155. fi
    156. devs=`fdisk -l | grep "^$mountDev" | awk '{print $1}'`
    157. for dev in $devs;do
    158. echo "trying device : ${dev} ..."
    159. dev_type=`fdisk -l | grep "^$dev" | grep -i "lvm"`
    160. if [ $? -eq 0 ];then
    161. lvmFlag="lvmType"
    162. else
    163. lvmFlag="normal"
    164. fi
    165. if [ "$lvmFlag" == "normal" ];then
    166. mount $dev $mountPath
    167. mount_dev
    168. ret=$?
    169. umount $mountPath
    170. if [ $ret -eq 0 ];then
    171. rmdir $mountPath
    172. echo "set password success."
    173. exit 0
    174. fi
    175. elif [ "$lvmFlag" == "lvmType" ];then
    176. vgchange -ay
    177. sleep 1
    178. vg="`pvs $dev | grep $dev | awk '{print $2}'`"
    179. lvs="`lvs $vg | grep -v 'LSize' | awk '{print $1}'`"
    180. for lv in $lvs;do
    181. tableValues="`dmsetup table ${vg}-${lv}`"
    182. if [ $? -ne 0 ];then #ubuntu's VG name is different
    183. vg_alias="`echo $vg | sed 's/-/--/g'`"
    184. tableValues="`dmsetup table ${vg_alias}-${lv}`"
    185. fi
    186. sectors="`echo ${tableValues} | awk '{print $2}'`"
    187. startSector="`echo ${tableValues} | awk '{print $5}'`"
    188. targetDev_first="`ls -l $dev | awk -F'[,]' '{print $1}' | awk '{print $5}'`"
    189. targetDev_second="`ls -l $dev | awk -F'[,]' '{print $2}' | awk '{print $1}'`"
    190. echo -e "0 $sectors linear ${targetDev_first}:${targetDev_second} $startSector" | dmsetup create $volTemp
    191. mount /dev/mapper/$volTemp $mountPath
    192. mount_dev
    193. ret=$?
    194. umount $mountPath
    195. dmsetup remove $volTemp
    196. if [ $ret -eq 0 ];then
    197. rmdir $mountPath
    198. echo "set password success."
    199. exit 0
    200. fi
    201. done
    202. fi
    203. done
    204. echo "set password failed."
    205. exit 1
    1. #!/bin/bash
    2. getCurrentPath()
    3. {
    4. if [ "` dirname "$0" `" = "" ] || [ "` dirname "$0" `" = "." ] ; then
    5. CURRENT_DIR="`pwd`"
    6. else
    7. cd ` dirname "$0" `
    8. CURRENT_DIR="`pwd`"
    9. cd - > /dev/null 2>&1
    10. fi
    11. }
    12. getCurrentPath
    13. CPU_CORE=`uname -m`
    14. echo "Current machine hardware name is : $CPU_CORE"
    15. Endpoint='oc.cloud.boccfc.com'
    16. MonitorServiceIp='10.200.148.2'
    17. if [ $CPU_CORE = "aarch64" ]
    18. then
    19. sed -i "s#oc.demo.com#${Endpoint}#g" ${CURRENT_DIR}"/telescope_linux_arm64/bin/conf_ces.json"
    20. else
    21. sed -i "s#oc.demo.com#${Endpoint}#g" ${CURRENT_DIR}"/telescope_linux_amd64/bin/conf_ces.json"
    22. fi
    23. if [ -z "$MonitorServiceIp" ];
    24. then
    25. echo "Monitor Service Ip is empty"
    26. else
    27. echo "$MonitorServiceIp $Endpoint" >> /etc/hosts
    28. fi
    29. if [ $CPU_CORE = "aarch64" ];
    30. then
    31. chmod 755 ${CURRENT_DIR}"/telescope_linux_arm64/install.sh"
    32. bash ${CURRENT_DIR}"/telescope_linux_arm64/install.sh"
    33. else
    34. chmod 755 ${CURRENT_DIR}"/telescope_linux_amd64/install.sh"
    35. bash ${CURRENT_DIR}"/telescope_linux_amd64/install.sh"
    36. fi