(command.CommandList
  children: [
    (C {<.>} {(${ Id.VSub_Name BACKEND) <'/functions.sh'>})
    (C {<.>} {(${ Id.VSub_Name BACKEND) <'/functions-parse.sh'>})
    (command.Sentence
      child: 
        (command.ShFunction
          name: determine_package_dependencies
          body: 
            (BraceGroup
              children: [
                (C {<local>} {<Id.Lit_VarLike 'PKGNAME='> (DQ (${ Id.VSub_Number 1))})
                (C {<local>} {<Id.Lit_VarLike 'DEPFILE='> (DQ (${ Id.VSub_Number 2))})
                (C {<grep>} {<-q>} {(DQ (${ Id.VSub_Name PKGNAME))} {(DQ (${ Id.VSub_Name DEPFILE))})
                (command.If
                  arms: [
                    (if_arm
                      cond: 
                        (condition.Shell
                          commands: [
                            (C {<Id.Lit_LBracket '['>} {($ Id.VSub_QMark '$?')} {<-ne>} {<0>} 
                              {<Id.Lit_RBracket ']'>}
                            )
                          ]
                        )
                      action: [
                        (command.Simple
                          words: [{<echo>} {(DQ (${ Id.VSub_Name PKGNAME))}]
                          redirects: [
                            (redir
                              op: <Id.Redir_DGreat '>>'>
                              loc: (redir_loc.Fd fd:1)
                              arg: {(DQ (${ Id.VSub_Name DEPFILE))}
                            )
                          ]
                          do_fork: T
                        )
                        (C {<get_package_dependencies>} {(DQ (${ Id.VSub_Name PKGNAME))} {(DQ <1>)})
                        (C {<local>} {<Id.Lit_VarLike 'DEPS='> (DQ (${ Id.VSub_Name VAL))})
                        (command.ForEach
                          iter_name: d
                          iter_words: [{(${ Id.VSub_Name DEPS)}]
                          do_arg_iter: F
                          body: 
                            (command.DoGroup
                              children: [
                                (C {<determine_package_dependencies>} {(DQ (${ Id.VSub_Name d))} 
                                  {(DQ (${ Id.VSub_Name DEPFILE))}
                                )
                              ]
                            )
                        )
                      ]
                      spids: [146 159]
                    )
                  ]
                )
              ]
            )
        )
      terminator: <Id.Op_Semi _>
    )
    (command.Sentence
      child: 
        (command.ShFunction
          name: fetch_package_dependencies
          body: 
            (BraceGroup
              children: [
                (C {<local>} {<DEPFILE>})
                (C {<local>} {<DEPS>})
                (C {<local>} {<SAVEDIR>})
                (command.ShAssignment
                  pairs: [
                    (assign_pair
                      lhs: (sh_lhs_expr.Name name:DEPFILE)
                      op: assign_op.Equal
                      rhs: {(DQ (${ Id.VSub_Number 1))}
                      spids: [267]
                    )
                  ]
                )
                (command.ShAssignment
                  pairs: [
                    (assign_pair
                      lhs: (sh_lhs_expr.Name name:DEPS)
                      op: assign_op.Equal
                      rhs: 
                        {
                          (command_sub
                            left_token: <Id.Left_Backtick '`'>
                            child: (C {<cat>} {(DQ (${ Id.VSub_Name DEPFILE))})
                          )
                        }
                      spids: [275]
                    )
                  ]
                )
                (command.ShAssignment
                  pairs: [
                    (assign_pair
                      lhs: (sh_lhs_expr.Name name:SAVEDIR)
                      op: assign_op.Equal
                      rhs: {(DQ (${ Id.VSub_Number 2))}
                      spids: [289]
                    )
                  ]
                )
                (command.ForEach
                  iter_name: d
                  iter_words: [{(${ Id.VSub_Name DEPS)}]
                  do_arg_iter: F
                  body: 
                    (command.DoGroup
                      children: [
                        (C {<get_package_short_name>} {(DQ (${ Id.VSub_Name d))})
                        (command.ShAssignment
                          pairs: [
                            (assign_pair
                              lhs: (sh_lhs_expr.Name name:SNAME)
                              op: assign_op.Equal
                              rhs: {(DQ (${ Id.VSub_Name VAL))}
                              spids: [321]
                            )
                          ]
                        )
                        (C {<get_package_category>} {(DQ (${ Id.VSub_Name SNAME))})
                        (command.ShAssignment
                          pairs: [
                            (assign_pair
                              lhs: (sh_lhs_expr.Name name:CATEGORY)
                              op: assign_op.Equal
                              rhs: {(DQ (${ Id.VSub_Name VAL))}
                              spids: [339]
                            )
                          ]
                        )
                        (C {<fetch_package>} {(DQ (${ Id.VSub_Name CATEGORY))} {(DQ (${ Id.VSub_Name d))} 
                          {(DQ (${ Id.VSub_Name SAVEDIR))}
                        )
                      ]
                    )
                )
              ]
            )
        )
      terminator: <Id.Op_Semi _>
    )
    (command.Sentence
      child: 
        (command.ShFunction
          name: install_packages
          body: 
            (BraceGroup
              children: [
                (C {<echo>} {(DQ <'Checking for packages to install...'>)})
                (C {<sleep>} {<2>})
                (C {<get_value_from_cfg>} {<installPackages>})
                (command.If
                  arms: [
                    (if_arm
                      cond: 
                        (condition.Shell
                          commands: [
                            (command.Sentence
                              child: 
                                (C {<Id.Lit_LBracket '['>} {<-z>} {(DQ (${ Id.VSub_Name VAL))} 
                                  {<Id.Lit_RBracket ']'>}
                                )
                              terminator: <Id.Op_Semi _>
                            )
                          ]
                        )
                      action: [
                        (command.Sentence
                          child: (command.ControlFlow token:<Id.ControlFlow_Return return>)
                          terminator: <Id.Op_Semi _>
                        )
                      ]
                      spids: [412 427]
                    )
                  ]
                )
                (C {<echo>} {(DQ <'Installing packages...'>)})
                (C {<sleep>} {<3>})
                (C {<local>} {<PKGPTH>})
                (command.ShAssignment
                  pairs: [
                    (assign_pair
                      lhs: (sh_lhs_expr.Name name:HERE)
                      op: assign_op.Equal
                      rhs: {(command_sub left_token:<Id.Left_Backtick '`'> child:(C {<pwd>}))}
                      spids: [455]
                    )
                  ]
                )
                (C {<rc_halt>} {(DQ <'mkdir -p '> (${ Id.VSub_Name FSMNT) (${ Id.VSub_Name PKGTMPDIR))})
                (C {<get_package_location>})
                (C {<rc_halt>} {(DQ <'cd '> (${ Id.VSub_Name PKGDLDIR))})
                (command.ShAssignment
                  pairs: [
                    (assign_pair
                      lhs: (sh_lhs_expr.Name name:INDEXFILE)
                      op: assign_op.Equal
                      rhs: {(DQ (${ Id.VSub_Name TMPDIR) <'/INDEX'>)}
                      spids: [499]
                    )
                  ]
                )
                (command.If
                  arms: [
                    (if_arm
                      cond: 
                        (condition.Shell
                          commands: [
                            (command.Sentence
                              child: 
                                (C {<Id.Lit_LBracket '['>} {<Id.KW_Bang '!'>} {<-f>} 
                                  {(DQ (${ Id.VSub_Name INDEXFILE))} {<Id.Lit_RBracket ']'>}
                                )
                              terminator: <Id.Op_Semi _>
                            )
                          ]
                        )
                      action: [(C {<get_package_index>})]
                      spids: [509 526]
                    )
                  ]
                )
                (command.If
                  arms: [
                    (if_arm
                      cond: 
                        (condition.Shell
                          commands: [
                            (command.Sentence
                              child: 
                                (C {<Id.Lit_LBracket '['>} {<Id.KW_Bang '!'>} {<-f>} 
                                  {(DQ (${ Id.VSub_Name TMPDIR) <'/INDEX.parsed'>)} {<-a>} {(DQ ($ Id.VSub_DollarName '$INSTALLMEDIUM'))} {<Id.Lit_Equals '='>} {(DQ <ftp>)} 
                                  {<Id.Lit_RBracket ']'>}
                                )
                              terminator: <Id.Op_Semi _>
                            )
                          ]
                        )
                      action: [(C {<parse_package_index>})]
                      spids: [536 566]
                    )
                  ]
                )
                (command.ShAssignment
                  pairs: [
                    (assign_pair
                      lhs: (sh_lhs_expr.Name name:PKGEXT)
                      op: assign_op.Equal
                      rhs: {(DQ <txz>)}
                      spids: [580]
                    )
                  ]
                )
                (C {<get_value_from_cfg>} {<pkgExt>})
                (command.If
                  arms: [
                    (if_arm
                      cond: 
                        (condition.Shell
                          commands: [
                            (command.Sentence
                              child: 
                                (C {<Id.Lit_LBracket '['>} {<-n>} {(DQ (${ Id.VSub_Name VAL))} 
                                  {<Id.Lit_RBracket ']'>}
                                )
                              terminator: <Id.Op_Semi _>
                            )
                          ]
                        )
                      action: [
                        (C {<strip_white_space>} {(${ Id.VSub_Name VAL)})
                        (command.ShAssignment
                          pairs: [
                            (assign_pair
                              lhs: (sh_lhs_expr.Name name:PKGEXT)
                              op: assign_op.Equal
                              rhs: {(DQ ($ Id.VSub_DollarName '$VAL'))}
                              spids: [617]
                            )
                          ]
                        )
                      ]
                      spids: [591 606]
                    )
                  ]
                )
                (C {<export>} {<PKGEXT>})
                (command.ShAssignment
                  pairs: [
                    (assign_pair
                      lhs: (sh_lhs_expr.Name name:PACKAGE_BUILDING)
                      op: assign_op.Equal
                      rhs: {<yes>}
                      spids: [637]
                    )
                  ]
                )
                (C {<export>} {<PACKAGE_BUILDING>})
                (C {<get_value_from_cfg_with_spaces>} {<installPackages>})
                (command.ShAssignment
                  pairs: [
                    (assign_pair
                      lhs: (sh_lhs_expr.Name name:PACKAGES)
                      op: assign_op.Equal
                      rhs: {(DQ (${ Id.VSub_Name VAL))}
                      spids: [656]
                    )
                  ]
                )
                (C {<echo_log>} 
                  {
                    (DQ <'Packages to install: '> 
                      (command_sub
                        left_token: <Id.Left_Backtick '`'>
                        child: 
                          (command.Pipeline
                            children: [
                              (C {<echo>} {($ Id.VSub_DollarName '$PACKAGES')})
                              (C {<wc>} {<-w>})
                              (C {<awk>} {(SQ <'{print $1}'>)})
                            ]
                            negated: F
                          )
                      )
                    )
                  }
                )
                (command.ForEach
                  iter_name: i
                  iter_words: [{($ Id.VSub_DollarName '$PACKAGES')}]
                  do_arg_iter: F
                  body: 
                    (command.DoGroup
                      children: [
                        (command.If
                          arms: [
                            (if_arm
                              cond: 
                                (condition.Shell
                                  commands: [
                                    (command.Pipeline
                                      children: [(C {<get_package_name>} {(DQ (${ Id.VSub_Name i))})]
                                      negated: T
                                    )
                                  ]
                                )
                              action: [
                                (C {<echo_log>} {(DQ <'Unable to locate package '> (${ Id.VSub_Name i))})
                                (command.ControlFlow
                                  token: <Id.ControlFlow_Continue continue>
                                )
                              ]
                              spids: [704 717]
                            )
                          ]
                        )
                        (command.ShAssignment
                          pairs: [
                            (assign_pair
                              lhs: (sh_lhs_expr.Name name:PKGNAME)
                              op: assign_op.Equal
                              rhs: {(DQ (${ Id.VSub_Name VAL))}
                              spids: [737]
                            )
                          ]
                        )
                        (command.If
                          arms: [
                            (if_arm
                              cond: 
                                (condition.Shell
                                  commands: [
                                    (command.Sentence
                                      child: 
                                        (C {<Id.Lit_LBracket '['>} 
                                          {(DQ (${ Id.VSub_Name INSTALLMEDIUM))} {<Id.Lit_Equals '='>} {(DQ <ftp>)} {<Id.Lit_RBracket ']'>}
                                        )
                                      terminator: <Id.Op_Semi _>
                                    )
                                  ]
                                )
                              action: [
                                (command.ShAssignment
                                  pairs: [
                                    (assign_pair
                                      lhs: (sh_lhs_expr.Name name:DEPFILE)
                                      op: assign_op.Equal
                                      rhs: 
                                        {
                                          (DQ (${ Id.VSub_Name FSMNT) <'/'> (${ Id.VSub_Name PKGTMPDIR) 
                                            <'/.'> (${ Id.VSub_Name PKGNAME) <.deps>
                                          )
                                        }
                                      spids: [773]
                                    )
                                  ]
                                )
                                (C {<rc_nohalt>} {(DQ <'touch '> (${ Id.VSub_Name DEPFILE))})
                                (C {<determine_package_dependencies>} {(DQ (${ Id.VSub_Name PKGNAME))} 
                                  {(DQ (${ Id.VSub_Name DEPFILE))}
                                )
                                (C {<fetch_package_dependencies>} {(DQ (${ Id.VSub_Name DEPFILE))} 
                                  {(DQ (${ Id.VSub_Name FSMNT) <'/'> (${ Id.VSub_Name PKGTMPDIR))}
                                )
                              ]
                              spids: [750 770]
                            )
                          ]
                        )
                        (command.Case
                          to_match: {(DQ (${ Id.VSub_Name INSTALLMEDIUM))}
                          arms: [
                            (case_arm
                              pat_list: [{<usb>} {<dvd>} {<local>}]
                              action: [
                                (command.ShAssignment
                                  pairs: [
                                    (assign_pair
                                      lhs: (sh_lhs_expr.Name name:PKGPTH)
                                      op: assign_op.Equal
                                      rhs: 
                                        {
                                          (DQ (${ Id.VSub_Name PKGTMPDIR) <'/All/'> 
                                            (${ Id.VSub_Name PKGNAME)
                                          )
                                        }
                                      spids: [860]
                                    )
                                  ]
                                )
                              ]
                              spids: [853 858 871 -1]
                            )
                            (case_arm
                              pat_list: [{<Id.Lit_Star '*'>}]
                              action: [
                                (command.ShAssignment
                                  pairs: [
                                    (assign_pair
                                      lhs: (sh_lhs_expr.Name name:PKGPTH)
                                      op: assign_op.Equal
                                      rhs: 
                                        {
                                          (DQ (${ Id.VSub_Name PKGTMPDIR) <'/'> 
                                            (${ Id.VSub_Name PKGNAME)
                                          )
                                        }
                                      spids: [877]
                                    )
                                  ]
                                )
                              ]
                              spids: [874 875 888 -1]
                            )
                          ]
                        )
                        (command.If
                          arms: [
                            (if_arm
                              cond: 
                                (condition.Shell
                                  commands: [
                                    (command.Sentence
                                      child: 
                                        (C {<Id.Lit_LBracket '['>} {<-z>} 
                                          {(DQ (${ Id.VSub_Name PKGINFO))} {<Id.Lit_RBracket ']'>}
                                        )
                                      terminator: <Id.Op_Semi _>
                                    )
                                  ]
                                )
                              action: [
                                (command.Simple
                                  words: [
                                    {<tar>}
                                    {<tqf>}
                                    {(DQ (${ Id.VSub_Name FSMNT) (${ Id.VSub_Name PKGPTH))}
                                    {(SQ <'+MANIFEST'>)}
                                  ]
                                  redirects: [
                                    (redir
                                      op: <Id.Redir_Great '>'>
                                      loc: (redir_loc.Fd fd:1)
                                      arg: {<'/dev/null'>}
                                    )
                                    (redir
                                      op: <Id.Redir_Great '2>'>
                                      loc: (redir_loc.Fd fd:2)
                                      arg: {<'/dev/null'>}
                                    )
                                  ]
                                  do_fork: T
                                )
                                (command.If
                                  arms: [
                                    (if_arm
                                      cond: 
                                        (condition.Shell
                                          commands: [
                                            (command.Sentence
                                              child: 
                                                (C {<Id.Lit_LBracket '['>} {($ Id.VSub_QMark '$?')} 
                                                  {<-ne>} {<0>} {<Id.Lit_RBracket ']'>}
                                                )
                                              terminator: <Id.Op_Semi _>
                                            )
                                          ]
                                        )
                                      action: [
                                        (command.ShAssignment
                                          pairs: [
                                            (assign_pair
                                              lhs: (sh_lhs_expr.Name name:PKGADD)
                                              op: assign_op.Equal
                                              rhs: {(DQ <'pkg_add -C '> (${ Id.VSub_Name FSMNT))}
                                              spids: [960]
                                            )
                                          ]
                                        )
                                        (command.ShAssignment
                                          pairs: [
                                            (assign_pair
                                              lhs: (sh_lhs_expr.Name name:PKGINFO)
                                              op: assign_op.Equal
                                              rhs: {(DQ <pkg_info>)}
                                              spids: [970]
                                            )
                                          ]
                                        )
                                      ]
                                      spids: [943 957]
                                    )
                                  ]
                                  else_action: [
                                    (command.ShAssignment
                                      pairs: [
                                        (assign_pair
                                          lhs: (sh_lhs_expr.Name name:PKGADD)
                                          op: assign_op.Equal
                                          rhs: {(DQ <'pkg -c '> (${ Id.VSub_Name FSMNT) <' add'>)}
                                          spids: [980]
                                        )
                                      ]
                                    )
                                    (command.ShAssignment
                                      pairs: [
                                        (assign_pair
                                          lhs: (sh_lhs_expr.Name name:PKGINFO)
                                          op: assign_op.Equal
                                          rhs: {(DQ <'pkg info'>)}
                                          spids: [990]
                                        )
                                      ]
                                    )
                                    (C {<bootstrap_pkgng>})
                                  ]
                                )
                              ]
                              spids: [899 915]
                            )
                          ]
                        )
                        (command.If
                          arms: [
                            (if_arm
                              cond: 
                                (condition.Shell
                                  commands: [
                                    (command.Pipeline
                                      children: [
                                        (command.Simple
                                          words: [
                                            {<run_chroot_cmd>}
                                            {
                                              (DQ (${ Id.VSub_Name PKGINFO) <' -e '> 
                                                (${ Id.VSub_Name PKGNAME)
                                              )
                                            }
                                          ]
                                          redirects: [
                                            (redir
                                              op: <Id.Redir_Great '>'>
                                              loc: (redir_loc.Fd fd:1)
                                              arg: {<'/dev/null'>}
                                            )
                                            (redir
                                              op: <Id.Redir_Great '2>'>
                                              loc: (redir_loc.Fd fd:2)
                                              arg: {<'/dev/null'>}
                                            )
                                          ]
                                          do_fork: T
                                        )
                                      ]
                                      negated: T
                                    )
                                  ]
                                )
                              action: [
                                (C {<echo_log>} 
                                  {(DQ <'Installing package: '> (${ Id.VSub_Name PKGNAME))}
                                )
                                (C {<rc_nohalt>} 
                                  {(DQ (${ Id.VSub_Name PKGADD) <' '> (${ Id.VSub_Name PKGPTH))}
                                )
                              ]
                              spids: [1010 1033]
                            )
                          ]
                        )
                        (command.If
                          arms: [
                            (if_arm
                              cond: 
                                (condition.Shell
                                  commands: [
                                    (command.Sentence
                                      child: 
                                        (C {<Id.Lit_LBracket '['>} 
                                          {(DQ (${ Id.VSub_Name INSTALLMEDIUM))} {<Id.Lit_Equals '='>} {(DQ <ftp>)} {<Id.Lit_RBracket ']'>}
                                        )
                                      terminator: <Id.Op_Semi _>
                                    )
                                  ]
                                )
                              action: [(C {<rc_nohalt>} {(DQ <'rm '> (${ Id.VSub_Name DEPFILE))})]
                              spids: [1063 1083]
                            )
                          ]
                        )
                      ]
                    )
                )
                (C {<echo_log>} {(DQ <'Package installation complete!'>)})
                (C {<rc_halt>} {(DQ <'cd '> (${ Id.VSub_Name HERE))})
                (command.If
                  arms: [
                    (if_arm
                      cond: 
                        (condition.Shell
                          commands: [
                            (command.Sentence
                              child: 
                                (C {<Id.Lit_LBracket '['>} {(DQ (${ Id.VSub_Name INSTALLMEDIUM))} 
                                  {<Id.Lit_Equals '='>} {(DQ <ftp>)} {<Id.Lit_RBracket ']'>}
                                )
                              terminator: <Id.Op_Semi _>
                            )
                          ]
                        )
                      action: [
                        (command.Simple
                          words: [
                            {<rc_halt>}
                            {(DQ <'rm -rf '> (${ Id.VSub_Name FSMNT) (${ Id.VSub_Name PKGTMPDIR))}
                          ]
                          redirects: [
                            (redir
                              op: <Id.Redir_Great '>'>
                              loc: (redir_loc.Fd fd:1)
                              arg: {<'/dev/null'>}
                            )
                            (redir
                              op: <Id.Redir_Great '2>'>
                              loc: (redir_loc.Fd fd:2)
                              arg: {<'/dev/null'>}
                            )
                          ]
                          do_fork: T
                        )
                      ]
                      spids: [1126 1146]
                    )
                  ]
                  else_action: [
                    (command.Simple
                      words: [
                        {<rc_halt>}
                        {(DQ <'umount '> (${ Id.VSub_Name FSMNT) (${ Id.VSub_Name PKGTMPDIR))}
                      ]
                      redirects: [
                        (redir
                          op: <Id.Redir_Great '>'>
                          loc: (redir_loc.Fd fd:1)
                          arg: {<'/dev/null'>}
                        )
                        (redir
                          op: <Id.Redir_Great '2>'>
                          loc: (redir_loc.Fd fd:2)
                          arg: {<'/dev/null'>}
                        )
                      ]
                      do_fork: T
                    )
                    (command.Simple
                      words: [
                        {<rc_halt>}
                        {(DQ <'rmdir '> (${ Id.VSub_Name FSMNT) (${ Id.VSub_Name PKGTMPDIR))}
                      ]
                      redirects: [
                        (redir
                          op: <Id.Redir_Great '>'>
                          loc: (redir_loc.Fd fd:1)
                          arg: {<'/dev/null'>}
                        )
                        (redir
                          op: <Id.Redir_Great '2>'>
                          loc: (redir_loc.Fd fd:2)
                          arg: {<'/dev/null'>}
                        )
                      ]
                      do_fork: T
                    )
                  ]
                )
              ]
            )
        )
      terminator: <Id.Op_Semi _>
    )
  ]
)