Advertisement
j0h

edatec2002-101c

j0h
Dec 22nd, 2024
41
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 9.84 KB | None | 0 0
  1. #!/bin/bash
  2.  
  3. #DEVICES=" aic_200w aic_230w aic_hq gwl2010_470 gwl2010_868 gwl2010_915 gwl2110_470 gwl2110_868 gwl2110_915 hmi2002_070c hmi2002_101c hmi2020_070c hmi2020_101c hmi2120_070c hmi2120_101c hmi2220-070c hmi2220-101c hmi232x_backlight_f hmi232x_backlight_r hmi2610_101c hmi2620_101c hmi2630_101c hmi3010_070c hmi3010_101c hmi3020_070c hmi3020_101c hmi3120_070c hmi3120_101c hmi332x_backlight_f hmi332x_backlight_r hmi3610_101c hmi3620_101c hmi3630_101c ind ipc2010 ipc2110 ipc2200 ipc2410 ipc2420 ipc2430 ipc2610 ipc2620 ipc2630 ipc3020 ipc3110 ipc3610 ipc3620 ipc3630 plc2010 sbc231x sbc331x sen"
  4. DEVICES="hmi2002_101c"
  5. #TIMEOUT=30
  6. #BASE_URL=https://apt.edatec.cn/bsp
  7. TMP_PATH="$HOME/eda-common"
  8.  
  9. # if [ $# -ne 1 ];then
  10. #     echo "Please specify the target."
  11. #     exit 1
  12. # fi
  13. #TARGET=$1
  14. TARGET=$DEVICES
  15.  
  16.  
  17.  
  18. function log_error(){
  19. echo "log_error Function reached"
  20. read
  21.     local msg=$1
  22.     echo -e "\033[31m ${msg} \033[0m"
  23. }
  24.  
  25. function log_info(){
  26.     echo "log_info Function reached"
  27. read
  28.     local msg=$1
  29.     echo -e "\033[32m ${msg} \033[0m"
  30. }
  31.  
  32. function load_json(){
  33.     echo "load_json Function reached"
  34. read
  35.     case $# in
  36.         2)
  37.             echo $1 |  python3 -c "import sys, json; data=json.load(sys.stdin); print(data['"$2"'])"
  38.             ;;
  39.         3)
  40.             echo $1 |  python3 -c "import sys, json; data=json.load(sys.stdin); print(data['"$2"']['"$3"'])"
  41.             ;;
  42.         4)
  43.             echo $1 |  python3 -c "import sys, json; data=json.load(sys.stdin); print(data['"$2"']['"$3"']['"$4"'])"
  44.             ;;  
  45.         5)
  46.             echo $1 |  python3 -c "import sys, json; data=json.load(sys.stdin); print(data['"$2"']['"$3"']['"$4"']['"$5"'])"
  47.             ;;  
  48.         6)
  49.             echo $1 |  python3 -c "import sys, json; data=json.load(sys.stdin); print(data['"$2"']['"$3"']['"$4"']['"$5"']['"$6"'])"
  50.             ;;  
  51.         7)
  52.             echo $1 |  python3 -c "import sys, json; data=json.load(sys.stdin); print(data['"$2"']['"$3"']['"$4"']['"$5"']['"$6"']['"$7"'])"
  53.             ;;  
  54.         8)
  55.             echo $1 |  python3 -c "import sys, json; data=json.load(sys.stdin); print(data['"$2"']['"$3"']['"$4"']['"$5"']['"$6"']['"$7"']['"$8"'])"
  56.             ;;  
  57.     esac
  58.     # python3 -c "import sys, json; data=json.load(sys.stdin); print(data['test']['target'])
  59. }
  60.  
  61. function is_in_json(){
  62.     echo "is_in_json Function reached"
  63. read
  64.     local t_data=$1
  65.     local t_key=$2
  66.     echo $t_data | python3 -c "import sys, json; data=json.load(sys.stdin); print('"${t_key}"' in data)"
  67. }
  68.  
  69. function load_json_len(){
  70.     echo "load_json Function reached"
  71. read
  72.     local t_data=$1
  73.     local t_key=$2
  74.     echo $t_data | python3 -c "import sys, json; data=json.load(sys.stdin); print(len(data['"${t_key}"']))"
  75. }
  76.  
  77. function load_json_array(){
  78.     echo "load_json Function reached"
  79. read
  80.     local t_data=$1
  81.     local t_key=$2
  82.     local t_index=$3
  83.     echo $t_data | python3 -c "import sys, json; data=json.load(sys.stdin); print(data['"${t_key}"']["${t_index}"])"
  84. }
  85.  
  86.  
  87. function run_cmd(){
  88.     echo "run_cmd Function reached arg1== " $1
  89. read
  90.     local cmd=$1
  91.     log_info "[DEBUG] ${cmd}"
  92.     eval "$cmd"
  93. }
  94.  
  95. function install_eda(){
  96.     echo "install_eda Function reached"
  97. read
  98.     local tmp_dir="${TMP_PATH}/eda/"
  99.     #mkdir -p $tmp_dir
  100.     #wget "${BASE_URL}/splash.png" -O "${tmp_dir}splash.png"
  101.     #install -m 644 "${tmp_dir}splash.png" "/usr/share/plymouth/themes/pix/"
  102.  
  103.  
  104.     local code_name=$(cat /etc/os-release | grep VERSION_CODENAME=)
  105.     local cmd_file="/boot/firmware/cmdline.txt"
  106.     code_name=${code_name#VERSION_CODENAME=}
  107.     if [ "${code_name}" = "bookworm" ];then
  108.         cmd_file="/boot/firmware/cmdline.txt"
  109.     else
  110.         cmd_file="/boot/cmdline.txt"
  111.     fi
  112.  
  113.     grep -q "net.ifnames=0" ${cmd_file} || sed -i "1{s/$/ net.ifnames=0/}" ${cmd_file}
  114. echo  $cmd_file " cmd_file "
  115. read
  116. #NOPE
  117.     #wget "https://apt.edatec.cn/pubkey.gpg" -O "${tmp_dir}edatec.gpg"
  118.     #cat ${tmp_dir}edatec.gpg | gpg --dearmor > "/etc/apt/trusted.gpg.d/edatec-archive-stable.gpg"
  119.     #echo "deb https://apt.edatec.cn/raspbian stable main" | sudo tee /etc/apt/sources.list.d/edatec.list
  120.     #sudo apt update
  121. }
  122.  
  123.  
  124. function start(){
  125.         echo "start Function reached  arg?: " $?
  126. read
  127.  
  128.     #local data=$(curl ${BASE_URL}/devices/${TARGET}.json --connect-timeout ${TIMEOUT})
  129.     #if [ $? -ne 0 ];then
  130.        # echo "Load device info failed."
  131.        # exit 2
  132.     #fi
  133.         echo "calling Function install-eda"
  134. read
  135.  
  136.     install_eda
  137.  
  138.     local b_state=$(is_in_json "${data}" "debs")
  139.         echo " b_state " $b_state " Data:  " $data
  140. read
  141.  
  142.     if [ "${b_state}" == "True" ];then
  143.         local debs=$(load_json "${data}" "debs")
  144.          
  145.          echo $debs=$(load_json "${data}" "debs")
  146.         read
  147.         log_info "[DEBUG] apt install -y ${debs}"
  148.         echo $log_info "[DEBUG] apt install -y ${debs}"
  149.         read
  150.         #sudo apt install -y ${debs}
  151.         if [ $? -ne 0 ];then
  152.             log_error "Failed to install package"
  153.             #exit 1
  154.         fi
  155.     fi
  156.    
  157.     b_state=$(is_in_json "${data}" "cmd")
  158.     if [ "${b_state}" == "True" ];then
  159.         local t_len=$(load_json_len "${data}" "cmd")
  160.         index=0
  161.         for i in $(seq 0 $((${t_len} -1)));do
  162.             t_cmd=$(load_json_array "${data}" "cmd" $i)
  163.             run_cmd "${t_cmd}"
  164.          done
  165.     fi
  166.    echo " reboot? lol no"
  167.    read
  168.    # reboot
  169. }
  170.  
  171. function useage(){
  172.     #log_info "curl -s ${BASE_URL}/ed-install.sh | sudo bash -s <device name>"
  173.     #log_info "Suport device:"
  174.     #for d in ${DEVICES[@]}
  175.     #do
  176.     #    log_info "    ${d}"
  177.     #done
  178. echo " potential missuse lol "
  179. read
  180. }
  181.  
  182. if [ -z "${TARGET}" ]; then
  183.     log_error "Please specify the target."
  184.     useage
  185. else
  186.     if [ -n "${DEVICES}" ];then
  187.         echo "${DEVICES}" | grep -q "${TARGET}"
  188.         if [ $? -eq 0 ];then
  189.             start $TARGET
  190.         else
  191.             log_error "Unknown target."
  192.             useage
  193.         fi
  194.     else
  195.         start $TARGET
  196.     fi
  197.    
  198.     # start $TARGET
  199. fi
  200. #POSINST
  201.  
  202. echo " postinstal reached"
  203. read
  204. CODENAME=$(cat /etc/os-release | grep VERSION_CODENAME=)
  205. CODENAME=${CODENAME#VERSION_CODENAME=}
  206. CONFIG_FILE="/boot/firmware/config.txt"
  207.  
  208. if [ "${CODENAME}" = "bookworm" ];then
  209.     CONFIG_FILE="/boot/firmware/config.txt"
  210.     if [ ! -f "$CONFIG_FILE" ];then
  211.         exit 0
  212.     fi
  213. else
  214.     CONFIG_FILE="/boot/config.txt"
  215.     if [ ! -f "$CONFIG_FILE" ];then
  216.         exit 0
  217.     fi
  218. fi
  219.  
  220. auto_add(){
  221.     local value=$1
  222.     grep -q "^${value}" $CONFIG_FILE
  223.     if [ $? -ne 0 ];then
  224.         sed -i '$a '"${value}" $CONFIG_FILE
  225.     fi
  226. }
  227.  
  228. write_ini(){
  229.     local t_user=$1
  230.     mkdir -p /home/${t_user}/.config
  231. cat > /home/${t_user}/.config/wayfire.ini << EOF
  232. [command]
  233. repeatable_binding_volume_up = KEY_VOLUMEUP
  234. command_volume_up = wfpanelctl volumepulse volu
  235. repeatable_binding_volume_down = KEY_VOLUMEDOWN
  236. command_volume_down = wfpanelctl volumepulse vold
  237. binding_mute = KEY_MUTE
  238. command_mute = wfpanelctl volumepulse mute
  239. binding_menu = <super>
  240. command_menu = wfpanelctl smenu menu
  241. binding_terminal = <ctrl> <alt> KEY_T
  242. command_terminal = lxterminal
  243. binding_bluetooth = <ctrl> <alt> KEY_B
  244. command_bluetooth = wfpanelctl bluetooth menu
  245. binding_netman = <ctrl> <alt> KEY_W
  246. command_netman = wfpanelctl netman menu
  247. binding_grim = KEY_SYSRQ
  248. command_grim = grim
  249. binding_orca = <ctrl> <alt> KEY_SPACE
  250. command_orca = gui-pkinst orca reboot
  251. binding_quit = <ctrl> <alt> KEY_DELETE
  252. command_quit = lxde-pi-shutdown-helper
  253. binding_power = KEY_POWER
  254. command_power = pwrkey
  255.  
  256. [input-device:generic ft5x06 (79)]
  257. output = DSI-1
  258.  
  259. [input-device:generic ft5x06 (80)]
  260. output = DSI-1
  261.  
  262. [input-device:FT5406 memory based driver]
  263. output = DSI-1
  264.  
  265. [input]
  266. xkb_model = pc105
  267. xkb_layout = gb
  268. xkb_variant =
  269.  
  270. [output:DSI-1]
  271. mode = 800x1280@40000
  272. position = 0,0
  273. transform = 90
  274.  
  275. [input-device:Goodix Capacitive TouchScreen]
  276. output = DSI-1
  277.  
  278. [input-device:10-0014 Goodix Capacitive TouchScreen]
  279. output = DSI-1
  280.  
  281. [window-rules]
  282. rule-1 = on created if title is "LXTerminal" then maximize
  283. EOF
  284.     chown -R ${t_user}:${t_user} /home/${t_user}/.config
  285. }
  286.  
  287. do_labwc(){
  288.     local t_user=$1
  289.     mkdir -p /home/${t_user}/.config/
  290.     mkdir -p /home/${t_user}/.config/labwc
  291.     mkdir -p /home/${t_user}/.config/kanshi
  292.  
  293. cat > /home/${t_user}/.config/kanshi/config << EOF
  294. profile {
  295.         output DSI-1 mode 800x1280 position 0,0 transform 90
  296. }
  297.  
  298. EOF
  299. cat > /home/${t_user}/.config/labwc/rc.xml << EOF
  300. <?xml version='1.0' encoding='UTF-8'?>
  301. <openbox_config xmlns="http://openbox.org/3.4/rc">
  302.   <touch deviceName="10-0014 Goodix Capacitive TouchScreen" mapToOutput="DSI-1" />
  303. </openbox_config>
  304. EOF
  305. chown -R ${t_user}:${t_user} /home/${t_user}/.config
  306. }
  307.  
  308. write_ini_auto(){
  309.     if [ -f "/usr/bin/labwc" ];then
  310.         raspi-config nonint do_wayland W3
  311.     fi
  312.  
  313.     for t_user in `ls /home/`
  314.     do
  315.         if [ -d "/home/${t_user}" ];then
  316.             if [ -f "/usr/bin/labwc" ];then
  317.                 do_labwc ${t_user}
  318.             fi
  319.             write_ini "${t_user}"
  320.         fi
  321.     done
  322. }
  323.  
  324. start(){
  325.     auto_add "dtoverlay=vc4-kms-dsi-rzw-t101p136cq-rpi4-2lane,interrupt=2"
  326.     auto_add "dtoverlay=imx219"
  327.     echo "" >> $CONFIG_FILE
  328.  
  329.     if [ "${CODENAME}" = "bookworm" ];then
  330.         write_ini_auto
  331.     fi
  332. }
  333.  
  334. start
  335. ############## fix post install #################
  336. :'
  337. #validate users with getent
  338.  
  339. for t_user in $(getent passwd | awk -F: '$6 ~ /^\/home\// {print $1}'); do
  340.    if [ -d "/home/${t_user}" ]; then
  341.        if [ -f "/usr/bin/labwc" ]; then
  342.            do_labwc "${t_user}"
  343.        fi
  344.        write_ini "${t_user}"
  345.    fi
  346. done
  347.  
  348. '
  349. :'
  350. # this is only really compable with bookworm though its not clearly stated
  351.  
  352. if ! grep -q 'VERSION_CODENAME=bookworm' /etc/os-release; then
  353.    echo "Unsupported OS version. Exiting." >&2
  354.    exit 1
  355. fi
  356. '
  357.  
  358.  
  359.  
  360.  
  361.  
  362.  
  363.  
  364.  
  365.  
  366.  
  367.  
  368.  
  369.  
  370.  
  371.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement