setup-spot 9.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251
  1. #!/bin/sh
  2. #call from 3builddistro, current dir is inside 'sandbox3'.
  3. #also want to call from LoginManager (/usr/sbin/loginmanager) from running puppy
  4. # (3buildistro will copy this script to sandbox3/rootfs-complete/usr/sbin).
  5. #pass in space-delimited names of apps to run as spot, each with false or true.
  6. #ex: 'seamonkey=true' 'sylpheed=false'
  7. #...=true means turn on spot, =false turn off. no parameter then do nothing.
  8. #130601 first version, seamonkey only.
  9. #130604 use code from /usr/sbin/run-as-spot, created by jamesbond (James Budiono).
  10. #130604 passed-in params to have actual names of executables.
  11. #130720 add support for QtWeb. 130721 fix. 130722 fix.
  12. #130723 add opera option to run as spot. see also 3builddistro, loginmanager.
  13. SPOTAPPS="$@"
  14. RUNNINGPUP=0
  15. echo "$0" | grep -q 'support' && RUNNINGPUP=1 #running in woof.
  16. PREFIXDIR=''
  17. [ $RUNNINGPUP -eq 1 ] && PREFIXDIR='rootfs-complete'
  18. touch ${PREFIXDIR}/root/.spot-status
  19. #130604 jamesbond, mods by BK...
  20. RUNASSPOT='#script to run $APP as spot...
  21. ARGS=""
  22. [ "$1" ] && while [ "$1" ]; do ARGS="$ARGS \"$1\""; shift; done
  23. if [ $(id -u) -eq 0 ]; then
  24. [ $XAUTHORITY ] && cp $XAUTHORITY /root/spot/.Xauthority 2>/dev/null
  25. touch /root/spot/.Xauthority
  26. #following line is mostly there to catch any root:root files that may have got copied in...
  27. find /root/spot \( -not -user spot -or -not -group spot \) -exec chown -h spot:spot {} \; &
  28. export XAUTHORITY=/root/spot/.Xauthority
  29. export XDG_CONFIG_HOME=/root/spot/.config
  30. export XDG_CACHE_HOME=/root/spot/.cache
  31. export XDG_DATA_HOME=/root/spot/.local/share
  32. exec su spot -s /bin/sh -c "\"$APP\" $ARGS"
  33. else #precaution
  34. exec "$APP" "$ARGS"
  35. fi'
  36. seamonkey_true() {
  37. #function to run seamonkey as spot.
  38. [ ! -e ${ONEAPPpath}/${ONEAPPname}.bin ] && cp -a -f ${ONEAPPpath}/${ONEAPPname} ${ONEAPPpath}/${ONEAPPname}.bin
  39. rm -f ${ONEAPPpath}/${ONEAPPname} #in case it is a symlink.
  40. echo "#!/bin/sh
  41. APP='${ONEAPPpath}/${ONEAPPname}.bin'" > ${ONEAPPpath}/${ONEAPPname}
  42. echo "$RUNASSPOT" >> ${ONEAPPpath}/${ONEAPPname}
  43. chmod 755 ${ONEAPPpath}/${ONEAPPname}
  44. if [ -e ${PREFIXDIR}/root/.mozilla ];then
  45. if [ ! -e ${PREFIXDIR}/root/spot/.mozilla/seamonkey/a2bvafqx.default ];then #check not already setup.
  46. if [ "$PREFIXDIR" ];then #woof. my SM PETs have skeleton .mozilla.
  47. cp -a ${PREFIXDIR}/root/.mozilla ${PREFIXDIR}/root/spot/
  48. DEFAULTDIR="`find ${PREFIXDIR}/root/spot/.mozilla/seamonkey -mindepth 1 -maxdepth 1 -name '*.default'`"
  49. else #running puppy...
  50. xDEFAULTDIR="`find /root/.mozilla/seamonkey -mindepth 1 -maxdepth 1 -name '*.default' | head -n 1`"
  51. if [ "$xDEFAULTDIR" ];then
  52. BASENAME="`basename $xDEFAULTDIR`" #ex: 3o1ptd5r.default
  53. mkdir -p /root/spot/.mozilla/seamonkey/${BASENAME}
  54. rm -rf /root/spot/.mozilla/seamonkey/${BASENAME}/* 2>/dev/null #precaution.
  55. echo "[General]
  56. StartWithLastProfile=1
  57. [Profile0]
  58. Name=default
  59. IsRelative=1
  60. Path=${BASENAME}" > /root/spot/.mozilla/seamonkey/profiles.ini
  61. cp -a -f /root/.mozilla/seamonkey/${BASENAME}/chrome /root/spot/.mozilla/seamonkey/${BASENAME}/
  62. cp -a -f /root/.mozilla/seamonkey/${BASENAME}/localstore.rdf /root/spot/.mozilla/seamonkey/${BASENAME}/
  63. cp -a -f /root/.mozilla/seamonkey/${BASENAME}/mimeTypes.rdf /root/spot/.mozilla/seamonkey/${BASENAME}/
  64. cp -a -f /root/.mozilla/seamonkey/${BASENAME}/prefs.js /root/spot/.mozilla/seamonkey/${BASENAME}/
  65. DEFAULTDIR="/root/spot/.mozilla/seamonkey/${BASENAME}"
  66. fi
  67. fi
  68. if [ "$DEFAULTDIR" ];then #precaution.
  69. DIRNAME="`dirname $DEFAULTDIR`"
  70. #needs to have a different name for .default dir from main one...
  71. mv -f $DEFAULTDIR $DIRNAME/a2bvafqx.default
  72. sed -i -e 's%^Path=.*defaul.*%Path=a2bvafqx.default%' $DIRNAME/profiles.ini
  73. #setup Downloads dir... 130722 no need for this anymore, already exists...
  74. mkdir -p ${PREFIXDIR}/root/spot/Downloads
  75. sed -i -e 's%/root/my-documents%/root/spot/Downloads%' $DIRNAME/a2bvafqx.default/prefs.js
  76. sed -i -e 's%"/usr/share/doc"%"/root/spot/Downloads"%' $DIRNAME/a2bvafqx.default/prefs.js
  77. fi
  78. fi
  79. fi
  80. return 0
  81. }
  82. seamonkey_false() {
  83. #function to run seamonkey as root.
  84. if [ -e ${ONEAPPpath}/${ONEAPPname}.bin ];then
  85. cp -a -f --remove-destination ${ONEAPPpath}/${ONEAPPname}.bin ${ONEAPPpath}/${ONEAPPname} #restore original.
  86. rm -f ${ONEAPPpath}/${ONEAPPname}.bin
  87. else #precaution. error.
  88. ln -snf /usr/lib/seamonkey/seamonkey ${PREFIXDIR}/usr/bin/seamonkey
  89. fi
  90. #a paranoid precaution...
  91. xDEFAULTDIR="`find ${PREFIXDIR}/root/.mozilla/seamonkey -mindepth 1 -maxdepth 1 -name '*.default' | head -n 1`"
  92. if [ "$xDEFAULTDIR" ];then
  93. BASENAME="`basename $xDEFAULTDIR`" #ex: 3o1ptd5r.default
  94. rm -rf ${PREFIXDIR}/root/spot/.mozilla/seamonkey/${BASENAME} 2>/dev/null
  95. fi
  96. return 0
  97. }
  98. generic_func() {
  99. #setup the app to run as spot or root...
  100. case $ONEAPPvalue in
  101. true)
  102. [ ! -e ${ONEAPPpath}/${ONEAPPname}.bin ] && cp -a -f ${ONEAPPpath}/${ONEAPPname} ${ONEAPPpath}/${ONEAPPname}.bin
  103. rm -f ${ONEAPPpath}/${ONEAPPname} #in case it is a symlink.
  104. case $RUNNINGPUP in
  105. 0)APPpath=${ONEAPPpath};;
  106. 1)APPpath=`echo ${ONEAPPpath}|sed "s%$PREFIXDIR%%"`;;
  107. esac
  108. echo "#!/bin/sh
  109. APP='${APPpath}/${ONEAPPname}.bin'" > ${ONEAPPpath}/${ONEAPPname}
  110. echo "$RUNASSPOT" >> ${ONEAPPpath}/${ONEAPPname}
  111. chmod 755 ${ONEAPPpath}/${ONEAPPname}
  112. ;;
  113. false)
  114. if [ -e ${ONEAPPpath}/${ONEAPPname}.bin ];then
  115. cp -a -f --remove-destination ${ONEAPPpath}/${ONEAPPname}.bin ${ONEAPPpath}/${ONEAPPname} #restore original.
  116. rm -f ${ONEAPPpath}/${ONEAPPname}.bin
  117. fi
  118. ;;
  119. esac
  120. return 0
  121. }
  122. #130720
  123. QtWeb_true() {
  124. #function to run QtWeb as spot.
  125. [ ! -e ${ONEAPPpath}/${ONEAPPname}.bin ] && cp -a -f ${ONEAPPpath}/${ONEAPPname} ${ONEAPPpath}/${ONEAPPname}.bin
  126. rm -f ${ONEAPPpath}/${ONEAPPname} #in case it is a symlink.
  127. echo "#!/bin/sh
  128. APP='${ONEAPPpath}/${ONEAPPname}.bin'" > ${ONEAPPpath}/${ONEAPPname}
  129. #QtWeb saves config settings in /tmp when running as spot...
  130. #jamesbond: fixed: http://bkhome.org/blog2/?viewDetailed=00319
  131. # echo 'rm -rf /tmp/QtWeb.NET' >> ${ONEAPPpath}/${ONEAPPname}
  132. # echo 'cp -a -f /root/spot/QtWeb.NET /tmp/' >> ${ONEAPPpath}/${ONEAPPname}
  133. echo "$RUNASSPOT" >> ${ONEAPPpath}/${ONEAPPname}
  134. # echo 'rm -rf /root/spot/QtWeb.NET' >> ${ONEAPPpath}/${ONEAPPname}
  135. # echo 'cp -a -f /tmp/QtWeb.NET /root/spot/' >> ${ONEAPPpath}/${ONEAPPname}
  136. # #take out "exec" as want to return to the script...
  137. # sed -i -e 's% exec % %' ${ONEAPPpath}/${ONEAPPname}
  138. chmod 755 ${ONEAPPpath}/${ONEAPPname}
  139. if [ -d ${PREFIXDIR}/root/.config/QtWeb.NET ];then #this is in the PET or created when run QtWeb as root.
  140. if [ ! -d ${PREFIXDIR}/root/spot/.config/QtWeb.NET ];then
  141. mkdir -p ${PREFIXDIR}/root/spot/.config/QtWeb.NET
  142. cp -a -f ${PREFIXDIR}/root/.config/QtWeb.NET/"QtWeb Internet Browser.conf" ${PREFIXDIR}/root/spot/.config/QtWeb.NET/
  143. sed -i -e 's%/root/Downloads%/root/spot/Downloads%' ${PREFIXDIR}/root/spot/.config/QtWeb.NET/"QtWeb Internet Browser.conf"
  144. fi
  145. else
  146. mkdir -p ${PREFIXDIR}/root/spot/.config/QtWeb.NET
  147. fi
  148. chown -R spot:spot ${PREFIXDIR}/root/spot/.config
  149. chmod 775 ${PREFIXDIR}/root/spot/Downloads #should already be.
  150. return 0
  151. }
  152. #130720
  153. QtWeb_false() {
  154. if [ -e ${ONEAPPpath}/${ONEAPPname}.bin ];then
  155. cp -a -f --remove-destination ${ONEAPPpath}/${ONEAPPname}.bin ${ONEAPPpath}/${ONEAPPname} #restore original.
  156. rm -f ${ONEAPPpath}/${ONEAPPname}.bin
  157. fi
  158. return 0
  159. }
  160. #130723 opera...
  161. opera_true() {
  162. #function to run Opera as spot.
  163. [ ! -e ${ONEAPPpath}/${ONEAPPname}.bin ] && cp -a -f ${ONEAPPpath}/${ONEAPPname} ${ONEAPPpath}/${ONEAPPname}.bin
  164. rm -f ${ONEAPPpath}/${ONEAPPname} #in case it is a symlink.
  165. echo "#!/bin/sh
  166. APP='${ONEAPPpath}/${ONEAPPname}.bin'" > ${ONEAPPpath}/${ONEAPPname}
  167. echo "$RUNASSPOT" >> ${ONEAPPpath}/${ONEAPPname}
  168. chmod 755 ${ONEAPPpath}/${ONEAPPname}
  169. if [ ! -d ${PREFIXDIR}/root/spot/.opera ];then
  170. if [ -d ${PREFIXDIR}/root/.opera ];then #this is in the PET or created when run Opera as root.
  171. cp -a -f ${PREFIXDIR}/root/.opera ${PREFIXDIR}/root/spot/
  172. else
  173. mkdir -p ${PREFIXDIR}/root/spot/.opera
  174. echo '
  175. [State]
  176. Accept License=0
  177. [User Prefs]
  178. Home URL=file://localhost/usr/share/doc/home.htm
  179. Startup Type=2
  180. Download Directory={Home}Downloads
  181. [Fonts]
  182. Normal=14,4,0,0,0,0,DejaVu Sans
  183. PRE=14,4,0,0,0,0,Nimbus Mono L
  184. ' > ${PREFIXDIR}/root/spot/.opera/operaprefs.ini
  185. fi
  186. fi
  187. chown -R spot:spot ${PREFIXDIR}/root/spot/.opera
  188. chmod 775 ${PREFIXDIR}/root/spot/Downloads #should already be.
  189. return 0
  190. }
  191. opera_false() {
  192. if [ -e ${ONEAPPpath}/${ONEAPPname}.bin ];then
  193. cp -a -f --remove-destination ${ONEAPPpath}/${ONEAPPname}.bin ${ONEAPPpath}/${ONEAPPname} #restore original.
  194. rm -f ${ONEAPPpath}/${ONEAPPname}.bin
  195. fi
  196. return 0
  197. }
  198. for ONEAPP in $SPOTAPPS
  199. do
  200. ONEAPPname="`echo -n "$ONEAPP" | cut -f 1 -d '='`" #ex: seamonkey
  201. ONEAPPvalue="`echo -n "$ONEAPP" | cut -f 2 -d '='`" #ex: true
  202. ONEAPPspec="`find ${PREFIXDIR}/bin ${PREFIXDIR}/sbin ${PREFIXDIR}/usr/bin ${PREFIXDIR}/usr/sbin ${PREFIXDIR}/usr/local/bin -mindepth 1 -maxdepth 1 -name ${ONEAPPname} | head -n 1`"
  203. if [ ! "$ONEAPPspec" ];then
  204. #executable does not exist, so remove from list, if there...
  205. sed -i -e "/^${ONEAPPname}=/d" ${PREFIXDIR}/root/.spot-status
  206. continue
  207. fi
  208. ONEAPPpath="$(dirname "$ONEAPPspec")"
  209. case $ONEAPPname in
  210. seamonkey) ${ONEAPPname}_${ONEAPPvalue} ;;
  211. QtWeb) ${ONEAPPname}_${ONEAPPvalue} ;; #130720
  212. opera) ${ONEAPPname}_${ONEAPPvalue} ;; #130723
  213. *) generic_func ;;
  214. esac
  215. if [ $? -ne 0 ];then
  216. sed -i -e "/^${ONEAPPname}=/d" ${PREFIXDIR}/root/.spot-status #remove.
  217. continue
  218. fi
  219. #record choice, for future runs of Login&Security Manager...
  220. if [ "$(grep "^${ONEAPPname}=" ${PREFIXDIR}/root/.spot-status)" != "" ];then
  221. rsPTN="s%^${ONEAPPname}=.*%${ONEAPPname}=${ONEAPPvalue}%"
  222. sed -i -e "$rsPTN" ${PREFIXDIR}/root/.spot-status
  223. else
  224. echo "${ONEAPPname}=${ONEAPPvalue}" >> ${PREFIXDIR}/root/.spot-status
  225. fi
  226. done
  227. find ${PREFIXDIR}/root/spot \( -not -user spot -or -not -group spot \) -exec chown -h spot:spot {} \;
  228. ###END###